diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f176645..28fe2367 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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: @@ -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 diff --git a/jest.config.ts b/jest.config.ts index 499ffca7..0adcf701 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -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` diff --git a/jest.smoke.config.ts b/jest.smoke.config.ts new file mode 100644 index 00000000..e50fd4a6 --- /dev/null +++ b/jest.smoke.config.ts @@ -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 diff --git a/jest/smoke.js b/jest/smoke.js new file mode 100644 index 00000000..0047e141 --- /dev/null +++ b/jest/smoke.js @@ -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 diff --git a/package.json b/package.json index bee7ed2f..4d2a5dd8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/smoke-tests/global.d.ts b/smoke-tests/global.d.ts new file mode 100644 index 00000000..e357fff2 --- /dev/null +++ b/smoke-tests/global.d.ts @@ -0,0 +1,5 @@ +declare global { + function subql(query: string): Promise +} + +export {} diff --git a/smoke-tests/snapshots.test.ts b/smoke-tests/snapshots.test.ts new file mode 100644 index 00000000..fe78136d --- /dev/null +++ b/smoke-tests/snapshots.test.ts @@ -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(`{ ${queryModelName} { totalCount } }`) + const { totalCount } = subqlResponse.data[queryModelName] + expect(totalCount).toBeGreaterThan(0) + }) +}) diff --git a/smoke-tests/timekeeper.test.ts b/smoke-tests/timekeeper.test.ts new file mode 100644 index 00000000..0712545e --- /dev/null +++ b/smoke-tests/timekeeper.test.ts @@ -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(` + { + timekeeper(id: "${chainIds[chain]}") { + lastPeriodStart + } + } + `) + const lastPeriodStart = Date.parse(response.data.timekeeper.lastPeriodStart) + expect(lastPeriodStart).toBe(lastMidnight) + }) +}) diff --git a/smoke-tests/tvl.test.ts b/smoke-tests/tvl.test.ts new file mode 100644 index 00000000..934d9a64 --- /dev/null +++ b/smoke-tests/tvl.test.ts @@ -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(` + { poolSnapshots(filter: { periodStart: { equalTo: "${sampleDate}" } }) { aggregates { sum { normalizedNAV } } } } + `) + const { normalizedNAV } = response.data.poolSnapshots.aggregates.sum + expect(normalizedNAV).toBe(knownTVL[sampleDate]) + }) +}) diff --git a/tsconfig.json b/tsconfig.json index 3e9500dd..1873543c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"