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

Add parachain testing #147

Merged
merged 18 commits into from
Dec 2, 2021
Merged
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"wsPort": 9988,
"port": 31200,
"name": "alice",
"flags": ["--force-authoring", "--", "--execution=wasm"]
"flags": ["--", "--execution=wasm"]
}
]
},
Expand All @@ -60,7 +60,7 @@
"wsPort": 9999,
"port": 31300,
"name": "alice",
"flags": ["--force-authoring", "--", "--execution=wasm"]
"flags": ["--", "--execution=wasm"]
}
]
}
Expand Down
22 changes: 18 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@
"build": "tsc",
"start": "yarn build && node dist/cli.js",
"lint": "prettier -v && prettier --check .",
"lint:write": "prettier --write ."
"lint:write": "prettier --write .",
"para-test": "mocha -r ts-node/register 'test/tests/**/test-*.ts'"
},
"dependencies": {
"@polkadot/api": "^6.3.1",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"@polkadot/api": "^6.10.3",
"@polkadot/keyring": "^8.0.5",
"@polkadot/types": "^6.10.3",
"@polkadot/util": "^8.0.5",
"@polkadot/util-crypto": "^8.0.5",
"@types/chai": "^4.2.22",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"ethers": "^5.4.7",
"filter-console": "^0.1.1",
"libp2p-crypto": "^0.20.0",
"mocha": "^9.1.2",
"peer-id": "^0.15.3",
"tcp-port-used": "^1.0.2",
"ts-node": "^10.3.0",
"web3": "^1.6.0",
"web3-core": "^1.6.0",
"web3-eth": "^1.6.0",
"yargs": "^15.4.1"
},
"files": [
Expand All @@ -29,6 +42,7 @@
},
"devDependencies": {
"@types/node": "^16.4.12",
"@types/tcp-port-used": "^1.0.0",
"prettier": "^2.4.1",
"typescript": "^4.1.5"
}
Expand Down
18 changes: 7 additions & 11 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,16 @@ export async function run(config_dir: string, rawConfig: LaunchConfig) {
console.log(
`Starting a Collator for parachain ${resolvedId}: ${account}, Collator port : ${port} wsPort : ${wsPort} rpcPort : ${rpcPort}`
);
const skipIdArg = !id;
await startCollator(
bin,
resolvedId,
wsPort,
rpcPort,
port,
const skip_id_arg = !id;
await startCollator(bin, resolvedId, wsPort, rpcPort, port, {
name,
chain,
spec,
flags,
basePath,
skipIdArg
);
skip_id_arg,
onlyOneParachainNode: config.parachains.length === 1,
});
}

// Allow time for the TX to complete, avoiding nonce issues.
Expand Down Expand Up @@ -223,8 +219,8 @@ async function addParachainsToGenesis(
// If it isn't registered yet, register the parachain in genesis
if (!registeredParachains[resolvedId]) {
// Get the information required to register the parachain in genesis.
let genesisState;
let genesisWasm;
let genesisState: string;
let genesisWasm: string;
try {
if (isSimple) {
// adder-collator does not support `--parachain-id` for export-genesis-state (and it is
Expand Down
22 changes: 16 additions & 6 deletions src/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "child_process";
import util from "util";
import fs from "fs";
import { CollatorOptions } from "./types";

// This tracks all the processes that we spawn from this file.
// Used to clean up processes when exiting this program.
Expand Down Expand Up @@ -189,16 +190,21 @@ export function startCollator(
wsPort: number,
rpcPort: number | undefined,
port: number,
name?: string,
chain?: string,
spec?: string,
flags?: string[],
basePath?: string,
skip_id_arg?: boolean
options: CollatorOptions
) {
return new Promise<void>(function (resolve) {
// TODO: Make DB directory configurable rather than just `tmp`
let args = ["--ws-port=" + wsPort, "--port=" + port];
const {
basePath,
name,
skip_id_arg,
onlyOneParachainNode,
chain,
flags,
spec,
} = options;

if (rpcPort) {
args.push("--rpc-port=" + rpcPort);
console.log(`Added --rpc-port=" + ${rpcPort}`);
Expand All @@ -219,6 +225,10 @@ export function startCollator(
args.push("--parachain-id=" + id);
console.log(`Added --parachain-id=${id}`);
}
if (onlyOneParachainNode) {
args.push("--force-authoring");
console.log(`Added --force-authoring`);
}
if (chain) {
args.push("--chain=" + chain);
console.log(`Added --chain=${chain}`);
Expand Down
15 changes: 14 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export interface CollatorOptions {
name?: string;
chain?: string;
spec?: string;
flags?: string[];
basePath?: string;
skip_id_arg?: boolean;
onlyOneParachainNode?: boolean;
}

export interface LaunchConfig {
relaychain: RelayChainConfig;
parachains: ParachainConfig[];
Expand Down Expand Up @@ -33,6 +43,9 @@ export interface HrmpChannelsConfig {
maxCapacity: number;
maxMessageSize: number;
}
interface ObjectJSON {
[key: string]: ObjectJSON | number | string;
}
export interface RelayChainConfig {
bin: string;
chain: string;
Expand All @@ -45,7 +58,7 @@ export interface RelayChainConfig {
port: number;
flags?: string[];
}[];
genesis?: JSON;
genesis?: JSON | ObjectJSON;
}

export interface ChainSpec {
Expand Down
109 changes: 109 additions & 0 deletions test/test-utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
export const SPECS_PATH = `./moonbeam-test-specs`;

export const DEBUG_MODE = process.env.DEBUG_MODE || false;
export const DISPLAY_LOG = process.env.PARACHAIN_LOG || false;
export const PARACHAIN_LOG = process.env.PARACHAIN_LOG || "info";

export const BINARY_PATH =
process.env.BINARY_PATH || `../bin/polkadot-collator-mac`;
export const RELAY_BINARY_PATH =
process.env.RELAY_BINARY_PATH || `../bin/polkadot-relaychain-mac`;
export const SPAWNING_TIME = 20000;
export const ETHAPI_CMD = process.env.ETHAPI_CMD || "";

export const RELAY_CHAIN_NODE_NAMES = [
"Alice",
"Bob",
"Charlie",
"Dave",
"Eve",
"Ferdie",
"One",
];

// Test variables
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
export const TREASURY_ACCOUNT = "0x6d6f646c70632f74727372790000000000000000";
export const GENESIS_ACCOUNT = "0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b";
export const GENESIS_ACCOUNT_PRIVATE_KEY =
"0x99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342";
export const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111";
export const ALITH = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac";
export const ALITH_PRIV_KEY =
"0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133";
export const BALTATHAR = "0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0";
export const BALTATHAR_PRIV_KEY =
"0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b";
export const CHARLETH = "0x798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc";
export const CHARLETH_PRIV_KEY =
"0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b";
export const DOROTHY = "0x773539d4Ac0e786233D90A233654ccEE26a613D9";
export const DOROTHY_PRIV_KEY =
"0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68";
export const RANDOM_PRIV_KEY =
"0x66d8d3bdfc9d678c1ea6dc3e15a81cb98dcd4d456f5ce0519479df1fba70cc5e";
export const ETHAN_PRIVKEY =
"0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4";
export const ETHAN = "0xFf64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB";
export const RANDOM_ADDRESS = "0x39Cccb8cc2A821eB5cDADc656fF4229398AbA190";
export const GLMR = 1_000_000_000_000_000_000n;
export const DEFAULT_GENESIS_BALANCE = 2n ** 80n;
export const DEFAULT_GENESIS_STAKING = 1_000n * GLMR;
export const DEFAULT_GENESIS_MAPPING = 100n * GLMR;
export const PROPOSAL_AMOUNT = 1000n * GLMR;
export const VOTE_AMOUNT = 10n * GLMR;
export const MIN_GLMR_STAKING = 1000n * GLMR;
export const MIN_GLMR_NOMINATOR = 5n * GLMR;
export const MIN_GLMR_NOMINATOR_PLUS_ONE = 6n * GLMR;
export const GENESIS_ACCOUNT_BALANCE = DEFAULT_GENESIS_BALANCE;
// This is Alice
export const COLLATOR_ACCOUNT = "0xf24ff3a9cf04c71dbc94d0b566f7a27b94566cac";
export const COLLATOR_ACCOUNT_BALANCE =
DEFAULT_GENESIS_BALANCE - DEFAULT_GENESIS_STAKING - DEFAULT_GENESIS_MAPPING;

// Prefunded accounts.
export const ALITH_ADDRESS = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac";
export const ALITH_PRIVATE_KEY =
"0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133";

export const BALTATHAR_ADDRESS = "0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0";
export const BALTATHAR_PRIVATE_KEY =
"0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b";

export const CHARLETH_ADDRESS = "0x798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc";
export const CHARLETH_PRIVATE_KEY =
"0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b";

export const DOROTHY_ADDRESS = "0x773539d4Ac0e786233D90A233654ccEE26a613D9";
export const DOROTHY_PRIVATE_KEY =
"0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68";

export const ETHAN_ADDRESS = "0xFf64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB";
export const ETHAN_PRIVATE_KEY =
"0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4";

export const FAITH_ADDRESS = "0xC0F0f4ab324C46e55D02D0033343B4Be8A55532d";
export const FAITH_PRIVATE_KEY =
"0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df";

export const GERALD_ADDRESS = "0x7BF369283338E12C90514468aa3868A551AB2929";
export const GERALD_PRIVATE_KEY =
"0x96b8a38e12e1a31dee1eab2fffdf9d9990045f5b37e44d8cc27766ef294acf18";

// Current gas per second
export const GAS_PER_SECOND = 40_000_000;
// The real computation is 1_000_000_000_000 / 40_000_000, but we simplify to avoid bigint.
export const GAS_PER_WEIGHT = 1_000_000 / 40;

// Our weight limit is 500ms.
export const BLOCK_TX_LIMIT = GAS_PER_SECOND * 0.5;

// Current implementation is limiting block transactions to 75% of the block gas limit
export const BLOCK_TX_GAS_LIMIT = BLOCK_TX_LIMIT * 0.75;
// 125_000_000 Weight per extrinsics
export const EXTRINSIC_BASE_COST = 125_000_000 / GAS_PER_WEIGHT;

// Maximum extrinsic weight is taken from the max allowed transaction weight per block,
// minus the block initialization (10%) and minus the extrinsic base cost.
export const EXTRINSIC_GAS_LIMIT =
BLOCK_TX_GAS_LIMIT - BLOCK_TX_LIMIT * 0.1 - EXTRINSIC_BASE_COST;
Loading