Skip to content

Commit

Permalink
zombienet doesnt require connected parachains (#438)
Browse files Browse the repository at this point in the history
* zombienet doesnt require connected parachains

* prescript errors halt runs
  • Loading branch information
timbrinded authored Nov 14, 2024
1 parent cbb72a2 commit 2c138ed
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 51 deletions.
10 changes: 10 additions & 0 deletions .changeset/olive-lions-enjoy.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 4 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
60 changes: 31 additions & 29 deletions packages/cli/src/internal/foundations/zombieHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/internal/launcherCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
39 changes: 25 additions & 14 deletions packages/cli/src/internal/providerFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/lib/globalContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
32 changes: 32 additions & 0 deletions test/configs/zombieNoPara.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
32 changes: 32 additions & 0 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down
3 changes: 3 additions & 0 deletions test/scripts/failing-script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log("This script will fail on purpose.")

process.exit(1)
31 changes: 31 additions & 0 deletions test/suites/zombieNoPara/test_basic.ts
Original file line number Diff line number Diff line change
@@ -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");
},
});


},
});

0 comments on commit 2c138ed

Please sign in to comment.