From ad8028f3fc8b5ffa47aa3b2d785e229d490aaf66 Mon Sep 17 00:00:00 2001 From: timbrinded <79199034+timbrinded@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:30:43 +0000 Subject: [PATCH] test: :white_check_mark: add fork test --- .github/workflows/main.yml | 2 +- test/configs/mbStateOverride.json | 7 +- test/moonwall.config.json | 5 +- test/scripts/compile-wasm.ts | 105 ----------------------------- test/suites/fork_test/test_fork.ts | 24 +++++-- 5 files changed, 26 insertions(+), 117 deletions(-) delete mode 100644 test/scripts/compile-wasm.ts diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a1448030..1ddedcc4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -114,7 +114,7 @@ jobs: strategy: fail-fast: false matrix: - suite: ["dev_test", "dev_multi", "dev_seq", "dev_smoke", "papi_dev"] + suite: ["dev_test", "dev_multi", "dev_seq", "dev_smoke", "papi_dev", "fork_test"] shard: [1, 2, 3, 4] steps: - uses: actions/checkout@v4 diff --git a/test/configs/mbStateOverride.json b/test/configs/mbStateOverride.json index fe51488c..a675a1cf 100644 --- a/test/configs/mbStateOverride.json +++ b/test/configs/mbStateOverride.json @@ -1 +1,6 @@ -[] +[ + { + "key": "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da90b65f88190770e2d4021d80a480ecf9c8300db2442725604b8f5eb172692bb15078205c2", + "value": "0x000000000000000001000000000000000000443945309a7a4800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080" + } +] diff --git a/test/moonwall.config.json b/test/moonwall.config.json index 6c0c3c29..c803b39d 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -953,9 +953,7 @@ { "name": "fork_test", "testFileDir": ["suites/fork_test"], - "runScripts": [ - "compile-wasm.ts compile -b tmp/moonbeam -o tmp/wasm -c moonbeam-dev" - ], + "foundation": { "type": "dev", "launchSpec": [ @@ -968,7 +966,6 @@ "--ethapi=txpool", "--no-hardware-benchmarks", "--no-telemetry", - "--wasmtime-precompiled=tmp/wasm", "--unsafe-force-node-key-generation", "--reserved-only", "--no-grandpa", diff --git a/test/scripts/compile-wasm.ts b/test/scripts/compile-wasm.ts deleted file mode 100644 index 5091123d..00000000 --- a/test/scripts/compile-wasm.ts +++ /dev/null @@ -1,105 +0,0 @@ -import fs from "fs/promises"; -import path from "path"; -import child_process from "child_process"; -import yargs from "yargs"; -import { hideBin } from "yargs/helpers"; - -yargs(hideBin(process.argv)) - .usage("Usage: $0") - .version("2.0.0") - .options({ - OutputDirectory: { - type: "string", - alias: "o", - description: "Output directory for compiled contracts", - default: "precompiled-wasm", - }, - Binary: { - type: "string", - alias: "b", - description: "Moonbeam binary path", - default: "contracts/src", - }, - Chain: { - type: "string", - alias: "c", - description: "runtime chain to use", - require: true, - }, - Verbose: { - type: "boolean", - alias: "v", - description: "Verbose mode for extra logging.", - default: false, - }, - }) - .command("compile", "Compile wasm", async (argv) => { - await main(argv as any); - }) - .parse(); - -async function spawn(cmd: string) { - return new Promise((resolve, reject) => { - var spawned = child_process.spawn(cmd, { shell: true }); - - let errData = ""; - let outData = ""; - spawned.stdout.on("data", (chunk) => { - outData += chunk.toString(); - }); - - spawned.stderr.on("data", (chunk) => { - errData += chunk.toString(); - }); - - spawned.on("close", function (code) { - if (code && code > 0) { - return reject(new Error(errData)); - } - - resolve(outData); - }); - - spawned.on("error", function (err) { - reject(err); - }); - }); -} - -async function main(args: any) { - const outputDirectory = path.join(process.cwd(), args.argv.OutputDirectory); - const binaryPath = args.argv.Binary; - - console.log(`🗃️ Binary: ${binaryPath}`); - console.log(`🗃️ Output directory: ${outputDirectory}`); - - child_process.execSync(`mkdir -p ${outputDirectory}`); - - await fs.mkdir("tmp", { recursive: true }); - const tmpDir = await fs.mkdtemp("tmp/base-path"); - try { - // Generate plain chain spec - const generateChainSpecCmd = - `${binaryPath} build-spec` + ` --chain ${args.argv.Chain} > tmp/${args.argv.Chain}.json`; - console.log(`🗃️ ${generateChainSpecCmd}`); - await spawn(generateChainSpecCmd); - - // Generate raw chain spec - const generateRawChainSpecCmd = - `${binaryPath} build-spec --chain tmp/${args.argv.Chain}.json ` + - `--raw > tmp/${args.argv.Chain}-raw.json`; - console.log(`🗃️ ${generateRawChainSpecCmd}`); - await spawn(generateRawChainSpecCmd); - - // Generate precompiled wasm - const command = - `${binaryPath} precompile-wasm --log=wasmtime-runtime --base-path=${tmpDir} ` + - `--chain tmp/${args.argv.Chain}-raw.json ${outputDirectory}`; - console.log(`🗃️ ${command}`); - await spawn(command); - } finally { - if ((await fs.stat(tmpDir)).isDirectory()) { - await fs.rm(tmpDir, { recursive: true, force: true }); - } - } -} diff --git a/test/suites/fork_test/test_fork.ts b/test/suites/fork_test/test_fork.ts index 67f5fffb..be7a4b0a 100644 --- a/test/suites/fork_test/test_fork.ts +++ b/test/suites/fork_test/test_fork.ts @@ -8,17 +8,15 @@ describeSuite({ foundationMethods: "dev", options: { forkConfig: { - url: "https://moonbeam.public.blastapi.io", - verbose: true + url: "https://moonbeam.unitedbloc.com", + verbose: true, }, }, - testCases: ({ it, context , log}) => { + testCases: ({ it, context, log }) => { let polkadotJs: ApiPromise; beforeAll(async () => { polkadotJs = context.polkadotJs(); - log("Waiting a minute for lazy loading to do its thing"); - await new Promise((resolve) => setTimeout(resolve, 60_000)); // wait for LL loading 1 minute }); it({ @@ -26,10 +24,24 @@ describeSuite({ title: "Checking that launched node can create blocks", test: async () => { const block = (await polkadotJs.rpc.chain.getBlock()).block.header.number.toNumber(); - await context.createBlock(); + await context.createBlock([], { finalize: false }); const block2 = (await polkadotJs.rpc.chain.getBlock()).block.header.number.toNumber(); expect(block2).to.be.greaterThan(block); }, }); + + it({ + id: "T02", + title: "Check that state overrides work", + test: async () => { + const testAccount = "0x8300db2442725604b8f5Eb172692Bb15078205c2"; + log(`Address: ${testAccount}`); + + const { + data: { free }, + } = await polkadotJs.query.system.account(testAccount); + expect(free.toBigInt(), "Free balance should be 1337000").toBe(1337000000000000000000n); + }, + }); }, });