Skip to content

Commit

Permalink
Improvements, needs polkadot-launch pr #113
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystalin committed Jun 18, 2021
1 parent debee23 commit 744f067
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 42 deletions.
169 changes: 169 additions & 0 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test-with-logs": "mocha --printlogs -r ts-node/register 'tests/**/test-*.ts'",
"pre-build-contracts": "TS_NODE_TRANSPILE_ONLY=true ts-node ./pre-build-contracts.ts && npx prettier -w ./contracts/compiled/*.json",
"test": "TS_NODE_TRANSPILE_ONLY=true mocha --parallel -r ts-node/register 'tests/**/test-*.ts'",
"para-test": "TS_NODE_TRANSPILE_ONLY=true mocha -r ts-node/register 'para-tests/**/test-*.ts'",
"watch": "npm-watch",
"build": "cargo build --release",
"non-ci-test": "mocha -r ts-node/register 'non_ci_tests/**/test-*.ts'",
Expand All @@ -49,6 +50,7 @@
"ethers": "^5.1.0",
"mocha": "^8.3.2",
"npm-watch": "^0.9.0",
"polkadot-launch": "^1.6.2",
"rimraf": "^3.0.2",
"solc": "^0.8.3",
"tcp-port-used": "^1.0.2",
Expand Down
43 changes: 1 addition & 42 deletions tests/util/para-node.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import tcpPortUsed from "tcp-port-used";
import { Tail } from "tail";
import path from "path";
import fs from "fs";
import { killAll, run } from "polkadot-launch";
import { BINARY_PATH, RELAY_BINARY_PATH, DISPLAY_LOG, SPAWNING_TIME } from "./constants";
import { config } from "chai";
const debug = require("debug")("test:para-node");

export async function findAvailablePorts() {
Expand Down Expand Up @@ -129,7 +126,6 @@ export async function startParachainNodes(options: ParachainOptions): Promise<{
flags: [
`--no-telemetry`,
`--no-prometheus`,
`--ethapi=txpool,debug,trace`,
"--log=info,rpc=trace,evm=trace,ethereum=trace",
"--unsafe-rpc-external",
"--rpc-cors=all",
Expand All @@ -155,44 +151,7 @@ export async function startParachainNodes(options: ParachainOptions): Promise<{
process.once("exit", onProcessExit);
process.once("SIGINT", onProcessInterrupt);

run(path.join(__dirname, "../"), launchConfig);

const binaryLogs = [];
await new Promise<void>((resolve) => {
const timer = setTimeout(() => {
console.error(`\x1b[31m Failed to start Parachain Node.\x1b[0m`);
console.error(`see alice.log and ${ports[2].wsPort}.log for details`);
throw new Error("Failed to launch node");
}, 120000);

try {
// delete the file if already exists
fs.rmSync(`${ports[2].wsPort}.log`);
} catch (e) {}
const onFileReady = async () => {
console.log(`Tailing ${ports[2].wsPort}.log`);
const tail = new Tail(`${ports[2].wsPort}.log`);

tail.on("line", function (data) {
console.log(data);
if (/Local node identity/.test(data.toString())) {
tail.unwatch();
clearTimeout(timer);
// TODO: improve, but currently requires 6s
setTimeout(resolve, 6000);
}
});
};

const checkFile = () => {
if (fs.existsSync(`${ports[2].wsPort}.log`)) {
onFileReady();
return;
}
setTimeout(checkFile, 1000);
};
checkFile();
});
await run(path.join(__dirname, "../"), launchConfig);

return {
p2pPort: ports[2].p2pPort,
Expand Down

0 comments on commit 744f067

Please sign in to comment.