From 2c138edcd74b4b9c9c9309e462f802c12e4c3ef0 Mon Sep 17 00:00:00 2001 From: Tim B <79199034+timbrinded@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:47:30 +0000 Subject: [PATCH] zombienet doesnt require connected parachains (#438) * zombienet doesnt require connected parachains * prescript errors halt runs --- .changeset/olive-lions-enjoy.md | 10 ++++ .github/workflows/main.yml | 9 ++- packages/cli/src/cmds/runTests.ts | 2 +- .../src/internal/foundations/zombieHelpers.ts | 60 ++++++++++--------- packages/cli/src/internal/launcherCommon.ts | 3 +- .../cli/src/internal/providerFactories.ts | 39 +++++++----- packages/cli/src/lib/globalContext.ts | 5 +- test/configs/zombieNoPara.json | 32 ++++++++++ test/moonwall.config.json | 32 ++++++++++ test/scripts/failing-script.ts | 3 + test/suites/zombieNoPara/test_basic.ts | 31 ++++++++++ 11 files changed, 175 insertions(+), 51 deletions(-) create mode 100644 .changeset/olive-lions-enjoy.md create mode 100644 test/configs/zombieNoPara.json create mode 100644 test/scripts/failing-script.ts create mode 100644 test/suites/zombieNoPara/test_basic.ts diff --git a/.changeset/olive-lions-enjoy.md b/.changeset/olive-lions-enjoy.md new file mode 100644 index 00000000..d264f18e --- /dev/null +++ b/.changeset/olive-lions-enjoy.md @@ -0,0 +1,10 @@ +--- +"@moonwall/cli": minor +"@moonwall/tests": minor +"@moonwall/types": minor +"@moonwall/util": minor +--- + +November Update +- [[#435](https://github.com/Moonsong-Labs/moonwall/issues/435)] Zombienets dont require parachains anymore +- [[#408](https://github.com/Moonsong-Labs/moonwall/issues/408)] preScript failures halt test runs \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9206edc7..a24a6426 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -219,7 +219,7 @@ jobs: strategy: fail-fast: false matrix: - suite: ["zombie_test", "zombie_multi_para"] + suite: ["zombie_test", "zombie_multi_para", "zombie_noPara"] steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 @@ -241,10 +241,9 @@ jobs: cd test bun moonwall download moonbeam latest ./tmp - # Change these to latest once MB is compatible with 1.2.0 - bun moonwall download polkadot 1.8.0 ./tmp - bun moonwall download polkadot-execute-worker 1.8.0 ./tmp - bun moonwall download polkadot-prepare-worker 1.8.0 ./tmp + bun moonwall download polkadot stable2407 ./tmp + bun moonwall download polkadot-execute-worker stable2407 ./tmp + bun moonwall download polkadot-prepare-worker stable2407 ./tmp - name: Run ${{matrix.suite}} run: | cd test diff --git a/packages/cli/src/cmds/runTests.ts b/packages/cli/src/cmds/runTests.ts index 92709e2e..36f21044 100644 --- a/packages/cli/src/cmds/runTests.ts +++ b/packages/cli/src/cmds/runTests.ts @@ -1,7 +1,7 @@ import type { Environment } from "@moonwall/types"; import chalk from "chalk"; import path from "node:path"; -import type { UserConfig, Vitest } from "vitest"; +import type { UserConfig, Vitest } from "vitest/node"; import { startVitest } from "vitest/node"; import { clearNodeLogs } from "../internal/cmdFunctions/tempLogs"; import { commonChecks } from "../internal/launcherCommon"; diff --git a/packages/cli/src/internal/foundations/zombieHelpers.ts b/packages/cli/src/internal/foundations/zombieHelpers.ts index 0013f450..7d646fd5 100644 --- a/packages/cli/src/internal/foundations/zombieHelpers.ts +++ b/packages/cli/src/internal/foundations/zombieHelpers.ts @@ -15,39 +15,41 @@ export async function checkZombieBins(config: LaunchConfig) { await checkExists(relayBinPath); checkAccess(relayBinPath); - const promises = config.parachains.map((para) => { - if (para.collator) { - if (!para.collator.command) { - throw new Error( - "No command found for collator, please check your zombienet config file for collator command" - ); - } - checkExists(para.collator.command); - checkAccess(para.collator.command); - } - - if (para.collators) { - for (const coll of para.collators) { - if (!coll.command) { + if (config.parachains) { + const promises = config.parachains.map((para) => { + if (para.collator) { + if (!para.collator.command) { throw new Error( - "No command found for collators, please check your zombienet config file for collators command" + "No command found for collator, please check your zombienet config file for collator command" ); } - checkExists(coll.command); - checkAccess(coll.command); + checkExists(para.collator.command); + checkAccess(para.collator.command); } - // para.collators.forEach((coll) => { - // if (!coll.command) { - // throw new Error( - // "No command found for collators, please check your zombienet config file for para collators command" - // ); - // } - // checkExists(coll.command); - // checkAccess(coll.command); - // }); - } - }); - await Promise.all(promises); + + if (para.collators) { + for (const coll of para.collators) { + if (!coll.command) { + throw new Error( + "No command found for collators, please check your zombienet config file for collators command" + ); + } + checkExists(coll.command); + checkAccess(coll.command); + } + // para.collators.forEach((coll) => { + // if (!coll.command) { + // throw new Error( + // "No command found for collators, please check your zombienet config file for para collators command" + // ); + // } + // checkExists(coll.command); + // checkAccess(coll.command); + // }); + } + }); + await Promise.all(promises); + } } export function getZombieConfig(path: string) { diff --git a/packages/cli/src/internal/launcherCommon.ts b/packages/cli/src/internal/launcherCommon.ts index 1c35106d..8cc15213 100644 --- a/packages/cli/src/internal/launcherCommon.ts +++ b/packages/cli/src/internal/launcherCommon.ts @@ -84,7 +84,8 @@ export async function executeScript(scriptCommand: string, args?: string) { default: console.log(`${ext} not supported, skipping ${script}`); } - } catch (err) { + } catch (err: any) { console.error(`Error executing script: ${chalk.bgGrey.redBright(err)}`); + throw new Error(err); } } diff --git a/packages/cli/src/internal/providerFactories.ts b/packages/cli/src/internal/providerFactories.ts index a1a8de5c..3ff08755 100644 --- a/packages/cli/src/internal/providerFactories.ts +++ b/packages/cli/src/internal/providerFactories.ts @@ -149,7 +149,7 @@ export class ProviderFactory { public static prepareDefaultZombie(): MoonwallProvider[] { const MOON_PARA_WSS = process.env.MOON_PARA_WSS || "error"; const MOON_RELAY_WSS = process.env.MOON_RELAY_WSS || "error"; - return ProviderFactory.prepare([ + const providers = [ { name: "w3", type: "web3", @@ -165,34 +165,45 @@ export class ProviderFactory { type: "viem", endpoints: [MOON_PARA_WSS], }, - { - name: "parachain", - type: "polkadotJs", - endpoints: [MOON_PARA_WSS], - }, + { name: "relaychain", type: "polkadotJs", endpoints: [MOON_RELAY_WSS], }, - ]); + ] satisfies ProviderConfig[]; + + if (MOON_PARA_WSS !== "error") { + providers.push({ + name: "parachain", + type: "polkadotJs", + endpoints: [MOON_PARA_WSS], + }); + } + + return ProviderFactory.prepare(providers); } public static prepareNoEthDefaultZombie(): MoonwallProvider[] { const MOON_PARA_WSS = process.env.MOON_PARA_WSS || "error"; const MOON_RELAY_WSS = process.env.MOON_RELAY_WSS || "error"; - return ProviderFactory.prepare([ - { - name: "parachain", - type: "polkadotJs", - endpoints: [MOON_PARA_WSS], - }, + + const providers = [ { name: "relaychain", type: "polkadotJs", endpoints: [MOON_RELAY_WSS], }, - ]); + ] satisfies ProviderConfig[]; + + if (MOON_PARA_WSS !== "error") { + providers.push({ + name: "parachain", + type: "polkadotJs", + endpoints: [MOON_PARA_WSS], + }); + } + return ProviderFactory.prepare(providers); } } diff --git a/packages/cli/src/lib/globalContext.ts b/packages/cli/src/lib/globalContext.ts index 7fcf8b53..aeb3111b 100644 --- a/packages/cli/src/lib/globalContext.ts +++ b/packages/cli/src/lib/globalContext.ts @@ -208,7 +208,10 @@ export class MoonwallContext { }; process.env.MOON_RELAY_WSS = network.relay[0].wsUri; - process.env.MOON_PARA_WSS = Object.values(network.paras)[0].nodes[0].wsUri; + + if (Object.entries(network.paras).length > 0) { + process.env.MOON_PARA_WSS = Object.values(network.paras)[0].nodes[0].wsUri; + } const nodeNames = Object.keys(network.nodesByName); process.env.MOON_ZOMBIE_DIR = `${network.tmpDir}`; diff --git a/test/configs/zombieNoPara.json b/test/configs/zombieNoPara.json new file mode 100644 index 00000000..d5452122 --- /dev/null +++ b/test/configs/zombieNoPara.json @@ -0,0 +1,32 @@ +{ + "settings": { + "timeout": 1000, + "provider": "native" + }, + "relaychain": { + "chain": "rococo-local", + "default_command": "tmp/polkadot", + "default_args": [ + "--no-hardware-benchmarks", + "-lparachain=debug", + "--database=paritydb" + ], + "nodes": [ + { + "name": "alice", + "validator": true + }, + { + "name": "bob", + "validator": true + } + ] + }, + "types": { + "Header": { + "number": "u64", + "parent_hash": "Hash", + "post_state": "Hash" + } + } +} diff --git a/test/moonwall.config.json b/test/moonwall.config.json index 7b8b48c2..eff1245b 100644 --- a/test/moonwall.config.json +++ b/test/moonwall.config.json @@ -78,6 +78,19 @@ ] } }, + { + "name": "failing_prescript", + "testFileDir": ["suites/basic"], + "description": "Test that failing pre-scripts are caught", + "runScripts": ["failing-script.ts"], + "foundation": { + "type": "read_only", + "launchSpec": { + "disableRuntimeVersionCheck": true + } + }, + "connections": [] + }, { "name": "dev_tanssi", "testFileDir": ["suites/tanssi"], @@ -168,6 +181,25 @@ } } }, + { + "name": "zombie_noPara", + "testFileDir": ["suites/zombieNoPara"], + "timeout": 300000, + "envVars": ["DEBUG_COLORS=1"], + "reporters": ["default"], + "foundation": { + "type": "zombie", + "zombieSpec": { + "name": "zombienet", + "disableDefaultEthProviders": true, + "additionalZombieConfig": { + "silent": true + }, + "configPath": "./configs/zombieNoPara.json" + } + } + }, + { "name": "para_test", "testFileDir": ["suites/zombie"], diff --git a/test/scripts/failing-script.ts b/test/scripts/failing-script.ts new file mode 100644 index 00000000..ec9dae62 --- /dev/null +++ b/test/scripts/failing-script.ts @@ -0,0 +1,3 @@ +console.log("This script will fail on purpose.") + +process.exit(1) \ No newline at end of file diff --git a/test/suites/zombieNoPara/test_basic.ts b/test/suites/zombieNoPara/test_basic.ts new file mode 100644 index 00000000..eed20add --- /dev/null +++ b/test/suites/zombieNoPara/test_basic.ts @@ -0,0 +1,31 @@ +import "@moonbeam-network/api-augment"; +import { beforeAll, describeSuite, expect } from "@moonwall/cli"; +import type { ApiPromise } from "@polkadot/api"; + +describeSuite({ + id: "Z1", + title: "Zombie Test Suite", + foundationMethods: "zombie", + testCases: ({ it, context, log }) => { + let paraApi: ApiPromise; + let relayApi: ApiPromise; + + beforeAll(async () => { + relayApi = context.polkadotJs("relaychain"); + }, 10000); + + it({ + id: "T01", + title: "Check relaychain api correctly connected", + test: async () => { + const rt = relayApi.consts.system.version.specVersion.toNumber(); + expect(rt).to.be.greaterThan(0); + + const network = relayApi.consts.system.version.specName.toString(); + expect(network).to.contain("rococo"); + }, + }); + + + }, +});