Skip to content

Commit

Permalink
195-Integration-tests-invariants (#225)
Browse files Browse the repository at this point in the history
test: smoke tests
chore: correct smoke test logic
test: run smoke tests on release branches
  • Loading branch information
filo87 authored Jul 11, 2024
1 parent fb7c486 commit 31e1f1a
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 14 deletions.
50 changes: 39 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
env:
SUBQL_INDEXER_VERSION: v3.4.10
SUBQL_QUERY_VERSION: v2.8.0
CHAIN_ID: demo
CHAIN_ID: centrifuge
steps:
- name: Check out repo's default branch
uses: actions/checkout@v3
Expand Down Expand Up @@ -44,11 +44,14 @@ jobs:
- name: 'Setup Node'
uses: actions/setup-node@v3
with:
node-version: '18'
- name: 'Install Dependencies'
run: yarn install
- name: 'Generate Entities'
run: yarn codegen
node-version: 18
cache: npm
- name: Setup Yarn
run: yarn install --frozen-lockfile
- name: Codegen
run: |
CHAIN_ID=centrifuge yarn projectgen
yarn codegen
- name: 'Run Linter'
run: yarn lint
test:
Expand All @@ -62,10 +65,35 @@ jobs:
- name: 'Setup Node'
uses: actions/setup-node@v3
with:
node-version: '18'
- name: 'Install Dependencies'
run: yarn install
- name: 'Generate Entities'
run: yarn codegen
node-version: 18
cache: npm
- name: Setup Yarn
run: yarn install --frozen-lockfile
- name: Codegen
run: |
CHAIN_ID=centrifuge yarn projectgen
yarn codegen
- name: 'Run Tests'
run: yarn test
smoke-tests:
if: ${{ startsWith(github.head_ref, 'release-please') }}
name: 'Run Smoke Tests'
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: Initialise project.yaml
run: cp chains-cfg/_root.yaml project.yaml
- name: 'Setup Node'
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- name: Setup Yarn
run: yarn install --frozen-lockfile
- name: Codegen
run: |
CHAIN_ID=centrifuge yarn projectgen
yarn codegen
- name: 'Run Tests'
run: yarn test:smoke
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const config: Config = {
testEnvironment: 'node',
setupFiles: ['./jest/globals.js'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
testPathIgnorePatterns: [ '/node_modules/', '/smoke-tests/' ],
transform: {
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
Expand Down
23 changes: 23 additions & 0 deletions jest.smoke.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Config } from 'jest'

const config: Config = {
verbose: true,
workerThreads: true,
preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ['./jest/smoke.js'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
testMatch: [ '**/smoke-tests/**/*.test.ts' ],
transform: {
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: './tsconfig.json',
},
],
},
}

export default config
10 changes: 10 additions & 0 deletions jest/smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const axios = require('axios')
const STAGING_URL = 'https://api.subquery.network/sq/centrifuge/pools-multichain__Y2Vud'

async function subql(query) {
const response = await axios.post('/', { query }, { baseURL: STAGING_URL }).catch((err) => err.response.data)
return response.data
}

global.subql = subql
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dev": "docker compose down -v --remove-orphans && docker compose pull && docker compose up -d",
"prepack": "rm -rf dist && subql build",
"test": "jest",
"test:smoke": "jest -c jest.smoke.config.ts",
"codegen": "subql codegen",
"projectgen": "./project-generator.sh",
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package centrifuge-subql/src/api-interfaces --endpoint 'wss://fullnode.development.cntrfg.com' --input ./src/api-interfaces",
Expand Down
5 changes: 5 additions & 0 deletions smoke-tests/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare global {
function subql<T>(query: string): Promise<T>
}

export {}
15 changes: 15 additions & 0 deletions smoke-tests/snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as Models from '../src/types/models'

const snapshotModels = Object.keys(Models)
.filter((modelName) => modelName.endsWith('Snapshot'))
.map((modelName) => `${modelName.charAt(0).toLowerCase() + modelName.slice(1)}s`)

describe('Entities snapshots', () => {
test.each(snapshotModels)('%s should have some snapshots', async (snapshotModel) => {
const queryModelName = `${snapshotModel}`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const subqlResponse = await subql<any>(`{ ${queryModelName} { totalCount } }`)
const { totalCount } = subqlResponse.data[queryModelName]
expect(totalCount).toBeGreaterThan(0)
})
})
23 changes: 23 additions & 0 deletions smoke-tests/timekeeper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const lastMidnight = new Date().setHours(0, 0, 0, 0)

const chainIds = {
CFG: '0xb3db41421702df9a7fcac62b53ffeac85f7853cc4e689e0b93aeb3db18c09d82',
ETH: '1',
}

const chains = Object.keys(chainIds)

describe('SubQl Nodes', () => {
test.each(chains)('%s node is fully synced', async (chain) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const response = await subql<any>(`
{
timekeeper(id: "${chainIds[chain]}") {
lastPeriodStart
}
}
`)
const lastPeriodStart = Date.parse(response.data.timekeeper.lastPeriodStart)
expect(lastPeriodStart).toBe(lastMidnight)
})
})
17 changes: 17 additions & 0 deletions smoke-tests/tvl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const knownTVL = {
'2024-01-01': '253434909261717851940121572',
'2024-07-01': '12008948422649000000000000',
}

const sampleDates = Object.keys(knownTVL)

describe('TVL at known intervals', () => {
test.each(sampleDates)('TVL at %s', async (sampleDate) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const response = await subql<any>(`
{ poolSnapshots(filter: { periodStart: { equalTo: "${sampleDate}" } }) { aggregates { sum { normalizedNAV } } } }
`)
const { normalizedNAV } = response.data.poolSnapshots.aggregates.sum
expect(normalizedNAV).toBe(knownTVL[sampleDate])
})
})
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
"declaration": true,
"importHelpers": true,
"resolveJsonModule": true,
"module": "commonjs",
"module": "CommonJS",
"outDir": "dist",
"rootDir": "src",
//"rootDir": "src",
"target": "es2017",
//"strict": true
},
"include": [
"src/**/*",
"smoke-tests/*.ts",
"smoke-tests/*.d.ts",
"node_modules/@subql/types-core/dist/global.d.ts",
"node_modules/@subql/types/dist/global.d.ts"
],
, "smoke-tests/.test.ts" ],
"exclude": ["src/api-interfaces/**"],
"exports": {
"chaintypes": "./src/chaintypes.ts"
Expand Down

0 comments on commit 31e1f1a

Please sign in to comment.