Skip to content

Commit

Permalink
test: ✅ Added fork test to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Nov 27, 2024
1 parent 3b41c62 commit ce941a0
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 16 deletions.
11 changes: 11 additions & 0 deletions .changeset/lucky-boats-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@moonwall/types": major
"@moonwall/cli": major
"@moonwall/tests": major
"@moonwall/docs": major
"@moonwall/util": major
---

Added Fork config to dev foundations

- BETA: Added ability to use moonbeam's fork API both via moonwall.config and also in a test
7 changes: 1 addition & 6 deletions docs/guide/intro/foundations.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,4 @@ Use Read Only if Moonwall doesn't need to start any networks - you've already go

::: tip
Zombie is the ideal Foundation for testing cross chain interactions including XCM.
:::


### Fork:

- 🚧 Not yet implemented! Will be part of a new way of forking the network with a real client.
:::
1 change: 0 additions & 1 deletion docs/guide/intro/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ This isn't too important as you will always be able to create new environment sp
- `chopsticks` : Using Acala Foundation's Chopsticks to start a lazily-forked network.
- `read_only`: Not starting a network but instead connecting to one that already exists.
- `zombie`: Using ParityTech's ZombieNetwork framework to run a multi-node network
- `fork` : 🚧 Not yet implemented! Will be part of a new way of forking the network with a real client

::: tip
This is the very brief rundown of foundations. For their specific information please visit the relevant sections in [Config](/guide/intro/foundations).
Expand Down
2 changes: 1 addition & 1 deletion packages/types/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"type": "string"
},
"defaultForkConfig": {
"description": "Default Fork options for the node (overriden by per-test fork options)",
"description": "BETA: Default Fork options for the node (overriden by per-test fork options)",
"properties": {
"blockNumber": {
"description": "The block number to fork from (optional)",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export interface DevLaunchSpec extends GenericLaunchSpec {
newRpcBehaviour?: boolean;

/**
* Default Fork options for the node (overriden by per-test fork options)
* BETA: Default Fork options for the node (overriden by per-test fork options)
*/
defaultForkConfig?: ForkConfig;

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export type FoundationHandler<T extends FoundationType> = (params: {
}) => void;

/**
* Represents overrides for launching a test environment.
* BETA: Represents overrides for launching a test environment.
* @property forkConfig - Optional configuration for forking a network.
*/
export type LaunchOverrides = {
Expand Down
8 changes: 6 additions & 2 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -953,18 +953,22 @@
{
"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": [
{
"name": "moonbeam",
"binPath": "tmp/moonbeam",
"newRpcBehaviour": true,
"disableDefaultEthProviders": true,
"options": [
"--ethapi=txpool",
"--no-hardware-benchmarks",
"--no-telemetry",
"--wasmtime-precompiled=wasm",
"--wasmtime-precompiled=tmp/wasm",
"--unsafe-force-node-key-generation",
"--reserved-only",
"--no-grandpa",
Expand All @@ -977,7 +981,7 @@
],
"defaultForkConfig": {
"url": "https://moonbeam.unitedbloc.com",
"stateOverridePath": "tmp/mbStateOverride.json",
"stateOverridePath": "./configs/mbStateOverride.json",
"verbose": true
}
}
Expand Down
105 changes: 105 additions & 0 deletions test/scripts/compile-wasm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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 });
}
}
}
10 changes: 6 additions & 4 deletions test/suites/fork_test/test_fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ describeSuite({
foundationMethods: "dev",
options: {
forkConfig: {
endpoint: "https://moonbeam.public.blastapi.io",
block: 100,
url: "https://moonbeam.public.blastapi.io",
verbose: true
},
},
testCases: ({ it, context }) => {
testCases: ({ it, context , log}) => {
let polkadotJs: ApiPromise;

beforeAll(() => {
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({
Expand Down

0 comments on commit ce941a0

Please sign in to comment.