Skip to content
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
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"foundry-keystore": "^0.1.0",
"foundry-primitives": "^0.2.0",
"foundry-rpc": "^0.1.0",
"get-port": "^5.1.1",
"jayson": "^3.2.0",
"lodash": "^4.17.11",
"mkdirp": "^0.5.1",
Expand Down
30 changes: 19 additions & 11 deletions test/src/helper/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import * as stake from "../stakeholder";
import { faucetAddress, faucetSecret } from "./constants";
import { wait } from "./promise";

const getPort = require("get-port");

const projectRoot = `${__dirname}/../../..`;

export type SchemeFilepath = string;
Expand Down Expand Up @@ -69,7 +71,6 @@ export interface Signer {
export default class CodeChain {
private static idCounter = 0;
private readonly _id: number;
private readonly _rpc: RPC;
private readonly _testFramework: SDK;
private readonly _localKeyStorePath: string;
private readonly _dbPath: string;
Expand All @@ -78,9 +79,11 @@ export default class CodeChain {
private readonly _logFile: string;
private readonly _logPath: string;
private readonly _chain: ChainType;
private readonly _rpcPort: number;
private readonly argv: string[];
private readonly env: { [key: string]: string };
private _port?: number;
private _rpcPort?: number;
private _rpc?: RPC;
private process: ProcessState;
private restarts: number;
private _keepLogs: boolean;
Expand All @@ -99,7 +102,7 @@ export default class CodeChain {
}
public get rpc(): RPC {
if (this.process.state === "running") {
return this._rpc;
return this._rpc!;
} else {
throw new ProcessStateError(this.id, this.process);
}
Expand All @@ -123,10 +126,10 @@ export default class CodeChain {
return this._logPath;
}
public get rpcPort(): number {
return this._rpcPort;
return this._rpcPort!;
}
public get port(): number {
return 3486 + this.id;
return this._port!;
}
public get secretKey(): number {
return 1 + this.id;
Expand Down Expand Up @@ -160,9 +163,6 @@ export default class CodeChain {
const { chain, argv, additionalKeysPath, env } = options;
this._id = CodeChain.idCounter++;

const { rpcPort = 8081 + this.id } = options;
this._rpcPort = rpcPort;

mkdirp.sync(`${projectRoot}/db/`);
mkdirp.sync(`${projectRoot}/keys/`);
mkdirp.sync(`${projectRoot}/test/log/`);
Expand All @@ -188,9 +188,6 @@ export default class CodeChain {
this.id
}.log`;
this._logPath = `${projectRoot}/test/log/${this._logFile}`;
this._rpc = new RPC(`http://localhost:${this.rpcPort}`, {
devel: true
});
this._testFramework = new SDK({});
this._chain = chain || "solo";
this.argv = argv || [];
Expand All @@ -210,6 +207,12 @@ export default class CodeChain {
throw new ProcessStateError(this.id, this.process);
}

await this.initialize_port();

this._rpc = new RPC(`http://localhost:${this.rpcPort}`, {
devel: true
});

const {
argv = [],
logLevel = "trace,mio=warn,tokio=warn,hyper=warn,timer=warn",
Expand Down Expand Up @@ -769,4 +772,9 @@ export default class CodeChain {
}
}
}

private async initialize_port() {
this._port = await getPort({ port: this.id + 3486 });
this._rpcPort = await getPort({ port: this.id + 8081 });
}
}