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 codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ ignore:
- "contracts/test"
- "packages/contracts"
- "packages/utils/benchmark"
- "packages/configuration-generator/bin"

220 changes: 220 additions & 0 deletions packages/configuration-generator/bin/update-test-genesis-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import envPaths from "env-paths";
import path from "path";
import { Identifiers as AppIdentifiers } from "@mainsail/contracts";
import { makeApplication } from "../distribution/application-factory.js";
import { Identifiers } from "../distribution/identifiers.js";
import { fileURLToPath } from "url";
import { copyFileSync } from "fs";
import { readJSONSync, writeJSONSync } from "fs-extra/esm";

const configurations = [
//
// Functional Tests
// tests/functional/transaction-pool-api/paths/config/
{
network: "devnet",
symbol: "TѦ",
token: "ARK",
distribute: true,
premine: "125000000000000000000000000",
chainId: 10000,
validators: 53,
initialHeight: 0,
overwriteConfig: true,
timeouts: {
blockPrepareTime: 100,
blockTime: 100,
stageTimeout: 100,
stageTimeoutIncrease: 100,
tolerance: 100,
},
postGenerate: (location) => {
// Functional tests run on single node
const __dirname = path.dirname(fileURLToPath(import.meta.url));

for (const file of ["crypto.json", "validators.json", "genesis-wallet.json"]) {
const source = path.join(location, file);
const target = path.join(
__dirname,
"..",
"..",
"..",
"tests",
"functional",
"transaction-pool-api",
"paths",
"config",
file,
);
copyFileSync(source, target);
}
},
},

// E2E Consensus
// tests/e2e/consensus
{
network: "devnet",
symbol: "TѦ",
token: "ARK",
distribute: true,
premine: "125000000000000000000000000",
chainId: 10000,
validators: 5,
initialHeight: 0,
overwriteConfig: true,
timeouts: {
blockPrepareTime: 500,
blockTime: 500,
stageTimeout: 500,
stageTimeoutIncrease: 500,
tolerance: 100,
},
postGenerate: (location) => {
// E2E tests run multiple nodes (1 validator per node)
const __dirname = path.dirname(fileURLToPath(import.meta.url));

// E2E Clients
for (const file of ["crypto.json", "validators.json"]) {
const source = path.join(location, file);
const target = path.join(
__dirname,
"..",
"..",
"..",
"tests",
"e2e",
"clients",
"config",
"core",
file,
);
copyFileSync(source, target);
}

// E2E Consensus

// Validator Node0 - Node4
for (let i = 0; i < 5; i++) {
const validators = readJSONSync(path.join(location, "validators.json"));
validators.secrets = [validators.secrets[i]];

const targetPath = path.join(
__dirname,
"..",
"..",
"..",
"tests",
"e2e",
"consensus",
"nodes",
`node${i}`,
"core",
);
writeJSONSync(path.join(targetPath, "validators.json"), validators, {
spaces: 4,
});

copyFileSync(path.join(location, "crypto.json"), path.join(targetPath, "crypto.json"));
}

// Api Node
for (const file of ["crypto.json"]) {
const source = path.join(location, file);
const target = path.join(
__dirname,
"..",
"..",
"..",
"tests",
"e2e",
"consensus",
"nodes",
`api-node`,
"core",
file,
);
copyFileSync(source, target);
}
},
},

// E2E Snapshot
// tests/e2e/snapshot
{
network: "devnet",
symbol: "TѦ",
token: "ARK",
distribute: true,
premine: "125000000000000000000000000",
chainId: 10000,
initialHeight: 0,
validators: 5,
overwriteConfig: true,
mockFakeValidatorBlsKeys: true,
timeouts: {
blockPrepareTime: 500,
blockTime: 500,
stageTimeout: 500,
stageTimeoutIncrease: 500,
tolerance: 100,
},
snapshot: {
// reuse existing snapshot to build new genesis block
// also see commit: 718b4cf2f1b49df9b80e6474be06fa97acc80d44
path: "../../tests/e2e/snapshot/nodes/node0/core/snapshot/f11b12e6d3a7524482deaacf745d5411d476ae39beeb7ce5141bfeee912cd08d.compressed",
},
postGenerate: (location) => {
// E2E tests run multiple nodes (1 validator per node)
const __dirname = path.dirname(fileURLToPath(import.meta.url));

// Validator Node0 - Node4 (only needs updated crypto.json)
for (let i = 0; i < 5; i++) {
const source = path.join(location, "crypto.json");
const target = path.join(
__dirname,
"..",
"..",
"..",
"tests",
"e2e",
"snapshot",
"nodes",
`node${i}`,
"core",
"crypto.json",
);
copyFileSync(source, target);
}
},
},
];

async function run() {
const paths = envPaths("mainsail", { suffix: "" });
const configCore = path.join(paths.config, "core");
console.log(paths, configCore);

for (const configuration of configurations) {
await generateConfiguration(configCore, configuration);
}
}

const generateConfiguration = async (path, configuration) => {
const app = await makeApplication(path, {});
const generator = app.get(Identifiers.ConfigurationGenerator);

await generator.generate(configuration);

if (configuration.postGenerate) {
configuration.postGenerate(generator.configurationPath);
}

for (const tag of ["evm", "validator", "transaction-pool", "rpc"]) {
if (app.isBoundTagged(AppIdentifiers.Evm.Instance, "instance", tag)) {
await app.getTagged(AppIdentifiers.Evm.Instance, "instance", tag).dispose();
}
}
};

run();
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class MilestonesGenerator {
decimals: 18,
denomination: 1e18,
},
timeouts: {
timeouts: options.timeouts ?? {
blockPrepareTime: options.blockTime / 2,
blockTime: options.blockTime,
stageTimeout: 2000,
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/source/contracts/network-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export type MilestoneOptions = {
maxBlockGasLimit: number;
maxTxPerBlock: number;
blockTime: number;
timeouts?: {
blockPrepareTime: number;
blockTime: number;
stageTimeout: number;
stageTimeoutIncrease: number;
tolerance: number;
};
epoch: Date;
vendorFieldLength: number;
};
Expand Down
Loading