diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 10c52b246f5..4b01bdd5758 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -590,7 +590,55 @@ jobs: # true # fi - dev-test: + vitest-test: + runs-on: + labels: bare-metal + permissions: + contents: read + needs: ["set-tags", "build"] + timeout-minutes: 20 + env: + DEBUG_COLORS: 1 + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + ref: ${{ needs.set-tags.outputs.git_ref }} + - name: Create local folders + run: | + mkdir -p target/release/wbuild/${{ matrix.chain }}-runtime/ + - name: "Download branch built runtime" + uses: actions/download-artifact@v5 + with: + name: runtimes + path: target/release/wbuild/${{ matrix.chain }}-runtime/ + - name: "Download branch built node" + uses: actions/download-artifact@v5 + with: + name: moonbeam + path: target/release + - uses: pnpm/action-setup@v4 + with: + version: 9 + - uses: actions/setup-node@v4 + with: + node-version-file: "test/.nvmrc" + cache: "pnpm" + cache-dependency-path: pnpm-lock.yaml + + - name: "Install and run dev test" + shell: bash + env: + DEBUG_COLOURS: "1" + NODE_OPTIONS: "--max-old-space-size=12288" + run: | + chmod uog+x target/release/moonbeam + cd test + pnpm install + pnpm compile-solidity + pnpm vitest + + moonwall-test: runs-on: labels: bare-metal permissions: diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5f41b37586d..50b9ff94167 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@acala-network/chopsticks': specifier: 1.2.2 version: 1.2.2(bufferutil@4.0.9)(debug@4.4.3)(ts-node@10.9.2(@types/node@24.7.0)(typescript@5.9.3))(utf-8-validate@5.0.10) + '@acala-network/chopsticks-testing': + specifier: 1.2.2 + version: 1.2.2(@polkadot/util-crypto@13.5.6(@polkadot/util@13.5.6))(bufferutil@4.0.9)(debug@4.4.3)(postcss@8.5.6)(rxjs@7.8.2)(ts-node@10.9.2(@types/node@24.7.0)(typescript@5.9.3))(tsx@4.20.6)(utf-8-validate@5.0.10)(yaml@2.8.1) '@biomejs/biome': specifier: ^2.2.5 version: 2.2.5 @@ -248,6 +251,14 @@ packages: '@acala-network/chopsticks-executor@1.2.2': resolution: {integrity: sha512-py+0rOYz+kAs6RGVRwu+mDX89x2CYv27oMy6/anh2wrfo88xPHjr1y8hOapDpRU5ynBW8Klx+z6rA3c2PrgB8g==} + '@acala-network/chopsticks-testing@1.2.2': + resolution: {integrity: sha512-X+1cYLxkPgFjahV/GRcNhOLuxkv7LVEbv+3rp9pm5UOQKQm1WmTCCUCfuldizivOI3l2sWJLiBxgqE/wWPjuSw==} + engines: {node: '>=v22'} + + '@acala-network/chopsticks-utils@1.2.2': + resolution: {integrity: sha512-IQCez/h2MtsitzQTLgPaMZiGDYy78fQFsgfHg8NXRMFL7N54sRqREkb/XdlGU/QefFlZy96IsJxd6XfIQg2FGA==} + engines: {node: '>=v22'} + '@acala-network/chopsticks@1.2.2': resolution: {integrity: sha512-LIzzyErMW+nf5oD64ST4rvK5DVLV99umy3Xr7pkU3KkdHjklF1bkuj3u6nqC7I4qna7/PukDcV02xcoqThjSPw==} engines: {node: '>=v22'} @@ -1420,6 +1431,12 @@ packages: '@polkadot-api/ws-provider@0.6.2': resolution: {integrity: sha512-YCllTdysvh30t4YWJubS1G8ULCZTOXGC+x8evbuFUNM1d70gpD98+zi4ba4lZGd1IlZ8v0zJuvC7G+/9Jcrm4w==} + '@polkadot-labs/hdkd-helpers@0.0.19': + resolution: {integrity: sha512-xo0by/TpjRbAQKZGTZbw1PQ/OnRlXz8iV+wWQIztShfTCvvtCP+R1QnfdJSCKk7u4CMtsRiaSp1EM0Oh9cJiSg==} + + '@polkadot-labs/hdkd@0.0.19': + resolution: {integrity: sha512-/MeAHXSpfsachcm1KXustsjzRFE8d6cgz0bmWWCa6tR6e0hkoGHMo82O+0dq8C2axumNz40eahznn8QYgQf7mg==} + '@polkadot/api-augment@10.13.1': resolution: {integrity: sha512-IAKaCp19QxgOG4HKk9RAgUgC/VNVqymZ2GXfMNOZWImZhxRIbrK+raH5vN2MbWwtVHpjxyXvGsd1RRhnohI33A==} engines: {node: '>=18'} @@ -2327,6 +2344,9 @@ packages: '@scure/bip39@1.6.0': resolution: {integrity: sha512-+lF0BbLiJNwVlev4eKelw1WWLaiKXw7sSl8T6FvBlWkdX+94aGJ4o8XjUdlyhTCjd8c+B3KT3JfS8P0bLRNU6A==} + '@scure/sr25519@0.2.0': + resolution: {integrity: sha512-uUuLP7Z126XdSizKtrCGqYyR3b3hYtJ6Fg/XFUXmc2//k2aXHDLqZwFeXxL97gg4XydPROPVnuaHGF2+xriSKg==} + '@sec-ant/readable-stream@0.4.1': resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==} @@ -4294,6 +4314,7 @@ packages: resolution: {integrity: sha512-Quz3MvAwHxVYNXsOByL7xI5EB2WYOeFswqaHIA3qOK3isRWTxiplBEocmmru6XmxDB2L7jDNYtYA4FyimoAFEw==} engines: {node: '>=8.17.0'} hasBin: true + bundledDependencies: [] jsonfile@4.0.0: resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==} @@ -6632,6 +6653,85 @@ snapshots: '@polkadot/util': 13.5.6 '@polkadot/wasm-util': 7.5.1(@polkadot/util@13.5.6) + '@acala-network/chopsticks-testing@1.2.2(@polkadot/util-crypto@13.5.6(@polkadot/util@13.5.6))(bufferutil@4.0.9)(debug@4.4.3)(postcss@8.5.6)(rxjs@7.8.2)(ts-node@10.9.2(@types/node@24.7.0)(typescript@5.9.3))(tsx@4.20.6)(utf-8-validate@5.0.10)(yaml@2.8.1)': + dependencies: + '@acala-network/chopsticks-utils': 1.2.2(@polkadot/util-crypto@13.5.6(@polkadot/util@13.5.6))(bufferutil@4.0.9)(debug@4.4.3)(postcss@8.5.6)(rxjs@7.8.2)(ts-node@10.9.2(@types/node@24.7.0)(typescript@5.9.3))(tsx@4.20.6)(utf-8-validate@5.0.10)(yaml@2.8.1) + '@polkadot/api': 16.4.8(bufferutil@4.0.9)(utf-8-validate@5.0.10) + '@polkadot/types': 16.4.8 + transitivePeerDependencies: + - '@google-cloud/spanner' + - '@microsoft/api-extractor' + - '@polkadot/util-crypto' + - '@sap/hana-client' + - '@swc/core' + - babel-plugin-macros + - better-sqlite3 + - bluebird + - bufferutil + - debug + - ioredis + - jiti + - mongodb + - mssql + - mysql2 + - oracledb + - pg + - pg-native + - pg-query-stream + - postcss + - redis + - rxjs + - sql.js + - supports-color + - ts-node + - tsx + - typeorm-aurora-data-api-driver + - utf-8-validate + - yaml + + '@acala-network/chopsticks-utils@1.2.2(@polkadot/util-crypto@13.5.6(@polkadot/util@13.5.6))(bufferutil@4.0.9)(debug@4.4.3)(postcss@8.5.6)(rxjs@7.8.2)(ts-node@10.9.2(@types/node@24.7.0)(typescript@5.9.3))(tsx@4.20.6)(utf-8-validate@5.0.10)(yaml@2.8.1)': + dependencies: + '@acala-network/chopsticks': 1.2.2(bufferutil@4.0.9)(debug@4.4.3)(ts-node@10.9.2(@types/node@24.7.0)(typescript@5.9.3))(utf-8-validate@5.0.10) + '@acala-network/chopsticks-core': 1.2.2(bufferutil@4.0.9)(utf-8-validate@5.0.10) + '@polkadot-labs/hdkd': 0.0.19 + '@polkadot-labs/hdkd-helpers': 0.0.19 + '@polkadot/api': 16.4.8(bufferutil@4.0.9)(utf-8-validate@5.0.10) + '@polkadot/api-base': 16.4.8(bufferutil@4.0.9)(utf-8-validate@5.0.10) + '@polkadot/keyring': 13.5.6(@polkadot/util-crypto@13.5.6(@polkadot/util@13.5.6))(@polkadot/util@13.5.6) + '@polkadot/types': 16.4.8 + '@polkadot/util': 13.5.6 + polkadot-api: 1.19.2(bufferutil@4.0.9)(postcss@8.5.6)(rxjs@7.8.2)(tsx@4.20.6)(utf-8-validate@5.0.10)(yaml@2.8.1) + transitivePeerDependencies: + - '@google-cloud/spanner' + - '@microsoft/api-extractor' + - '@polkadot/util-crypto' + - '@sap/hana-client' + - '@swc/core' + - babel-plugin-macros + - better-sqlite3 + - bluebird + - bufferutil + - debug + - ioredis + - jiti + - mongodb + - mssql + - mysql2 + - oracledb + - pg + - pg-native + - pg-query-stream + - postcss + - redis + - rxjs + - sql.js + - supports-color + - ts-node + - tsx + - typeorm-aurora-data-api-driver + - utf-8-validate + - yaml + '@acala-network/chopsticks@1.2.2(bufferutil@4.0.9)(debug@4.4.3)(ts-node@10.9.2(@types/node@24.7.0)(typescript@5.9.3))(utf-8-validate@5.0.10)': dependencies: '@acala-network/chopsticks-core': 1.2.2(bufferutil@4.0.9)(utf-8-validate@5.0.10) @@ -8195,6 +8295,18 @@ snapshots: - bufferutil - utf-8-validate + '@polkadot-labs/hdkd-helpers@0.0.19': + dependencies: + '@noble/curves': 1.9.7 + '@noble/hashes': 1.8.0 + '@scure/base': 1.2.6 + '@scure/sr25519': 0.2.0 + scale-ts: 1.6.1 + + '@polkadot-labs/hdkd@0.0.19': + dependencies: + '@polkadot-labs/hdkd-helpers': 0.0.19 + '@polkadot/api-augment@10.13.1(bufferutil@4.0.9)(utf-8-validate@5.0.10)': dependencies: '@polkadot/api-base': 10.13.1(bufferutil@4.0.9)(utf-8-validate@5.0.10) @@ -9963,6 +10075,11 @@ snapshots: '@noble/hashes': 1.8.0 '@scure/base': 1.2.6 + '@scure/sr25519@0.2.0': + dependencies: + '@noble/curves': 1.9.7 + '@noble/hashes': 1.8.0 + '@sec-ant/readable-stream@0.4.1': {} '@sindresorhus/is@4.6.0': {} diff --git a/test/package.json b/test/package.json index 2ea27a85f2d..8445a9fe6c3 100644 --- a/test/package.json +++ b/test/package.json @@ -16,13 +16,15 @@ "lint": "biome lint .", "compile-solidity": "tsx scripts/compile-contracts.ts compile", "typecheck": "pnpm tsc --noEmit", - "print-failed-tests": "tsx scripts/print-failed-tests.ts" + "print-failed-tests": "tsx scripts/print-failed-tests.ts", + "vitest": "vitest run --dir suites/simple" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@acala-network/chopsticks": "1.2.2", + "@acala-network/chopsticks-testing": "1.2.2", "@biomejs/biome": "^2.2.5", "@moonbeam-network/api-augment": "workspace:*", "@moonbeam-network/types-bundle": "workspace:*", diff --git a/test/suites/simple/test-chopsticks-fake-signature.test.ts b/test/suites/simple/test-chopsticks-fake-signature.test.ts new file mode 100644 index 00000000000..b0c12cb75ab --- /dev/null +++ b/test/suites/simple/test-chopsticks-fake-signature.test.ts @@ -0,0 +1,86 @@ +import { afterAll, describe, expect, it } from "vitest"; +import { + setupContext, + signFake, + signFakeWithApi, + testingPairs, +} from "@acala-network/chopsticks-testing"; + +describe( + "Chopsticks Fake Signature", + async () => { + const { api, dev, teardown } = await setupContext({ + endpoint: ["wss://wss.api.moonbase.moonbeam.network"], + timeout: 400_000, + }); + + afterAll(async () => await teardown()); + + it("accept valid signature", async () => { + const { alith, baltathar } = testingPairs(); + await dev.setStorage({ + System: { + Account: [[[alith.address], { providers: 1, data: { free: 1000 * 1e12 } }]], + }, + }); + + const tx = api.tx.balances.transferAllowDeath(baltathar.address, 100); + + await tx.signAsync(alith); + + await expect(tx.send()).resolves.toBeTruthy(); + }); + + it("reject invalid signature", async () => { + const { alith, baltathar } = testingPairs(); + const { nonce } = await api.query.system.account(alith.address); + const tx = api.tx.balances.transferAllowDeath(baltathar.address, 100); + + tx.signFake(alith.address, { + nonce, + genesisHash: api.genesisHash, + runtimeVersion: api.runtimeVersion, + blockHash: api.genesisHash, + }); + + await expect(tx.send()).rejects.toThrow('1010: {"invalid":{"badProof":null}}'); + }); + + it("accept mock signature (with api)", async () => { + const { alith, baltathar } = testingPairs(); + await dev.setStorage({ + System: { + Account: [[[alith.address], { providers: 1, data: { free: 1000 * 1e12 } }]], + }, + }); + + const tx = api.tx.balances.transferAllowDeath(baltathar.address, 100); + + await signFakeWithApi(api, tx, alith.address); + + await expect(tx.send()).resolves.toBeTruthy(); + }); + + it("accept mock signature (manually input options)", async () => { + const { alith, baltathar } = testingPairs(); + await dev.setStorage({ + System: { + Account: [[[alith.address], { providers: 1, data: { free: 1000 * 1e12 } }]], + }, + }); + + const { nonce } = await api.query.system.account(alith.address); + const tx = api.tx.balances.transferAllowDeath(baltathar.address, 100); + + signFake(tx, alith.address, { + nonce, + genesisHash: api.genesisHash, + runtimeVersion: api.runtimeVersion, + blockHash: api.genesisHash, + }); + + await expect(tx.send()).resolves.toBeTruthy(); + }); + }, + { timeout: 120_000 } +);