Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): improve dev test duration by not compiling wasm on startup #469

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
"name": "tanssi",
"binPath": "../target/release/tanssi-node",
"options": [
"--dev",
"--force-authoring",
"--rpc-cors=all",
"--no-prometheus",
"--no-telemetry",
"--reserved-only",
"--alice",
"--tmp",
"--chain=tmp/dancebox_dev-raw.json",
RomarQ marked this conversation as resolved.
Show resolved Hide resolved
"--sealing=manual",
"--no-hardware-benchmarks",
"--wasmtime-precompiled=wasm"
Expand Down Expand Up @@ -69,7 +76,14 @@
"name": "frontier-template",
"binPath": "../target/release/container-chain-template-frontier-node",
"options": [
"--dev",
"--force-authoring",
"--rpc-cors=all",
"--no-prometheus",
"--no-telemetry",
"--reserved-only",
"--alice",
"--tmp",
"--chain=tmp/dev-raw.json",
"--sealing=manual",
"--no-hardware-benchmarks",
"--wasmtime-precompiled=wasm"
Expand All @@ -95,7 +109,14 @@
"name": "simple-template",
"binPath": "../target/release/container-chain-template-simple-node",
"options": [
"--dev",
"--force-authoring",
"--rpc-cors=all",
"--no-prometheus",
"--no-telemetry",
"--reserved-only",
"--alice",
"--tmp",
"--chain=tmp/dev-raw.json",
"--sealing=manual",
"--no-hardware-benchmarks",
"--wasmtime-precompiled=wasm"
Expand Down
45 changes: 42 additions & 3 deletions test/scripts/compile-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ yargs(hideBin(process.argv))
})
.parse();

async function spawn(cmd: string) {
return new Promise((resolve, reject) => {
const 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;
Expand All @@ -50,12 +78,23 @@ async function main(args: any) {
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 ${args.argv.Chain} ${outputDirectory}`;
`--chain tmp/${args.argv.Chain}-raw.json ${outputDirectory}`;
console.log(`🗃️ ${command}`);

child_process.execSync(`${command}`);
await spawn(command);
} finally {
if ((await fs.stat(tmpDir)).isDirectory()) {
await fs.rm(tmpDir, { recursive: true, force: true });
Expand Down