From 274309f68d4b9fe3cdd7b5dc62ec8dad75232c71 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Thu, 22 May 2025 13:39:25 +0900 Subject: [PATCH 1/6] accept custom timeouts --- .../source/generators/milestones.ts | 2 +- packages/contracts/source/contracts/network-generator.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/configuration-generator/source/generators/milestones.ts b/packages/configuration-generator/source/generators/milestones.ts index c6e05eebe3..268beabd9e 100644 --- a/packages/configuration-generator/source/generators/milestones.ts +++ b/packages/configuration-generator/source/generators/milestones.ts @@ -29,7 +29,7 @@ export class MilestonesGenerator { decimals: 18, denomination: 1e18, }, - timeouts: { + timeouts: options.timeouts ?? { blockPrepareTime: options.blockTime / 2, blockTime: options.blockTime, stageTimeout: 2000, diff --git a/packages/contracts/source/contracts/network-generator.ts b/packages/contracts/source/contracts/network-generator.ts index 6fe150321e..a9a708e429 100644 --- a/packages/contracts/source/contracts/network-generator.ts +++ b/packages/contracts/source/contracts/network-generator.ts @@ -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; }; From 369b9b23fc0b155b5c16cc948f821a6d6c7ae3f6 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Thu, 22 May 2025 13:40:43 +0900 Subject: [PATCH 2/6] add helper to generate network configs for e2e / functional tests --- .../bin/create-genesis-block.js | 166 ++++++++++++++++-- 1 file changed, 153 insertions(+), 13 deletions(-) diff --git a/packages/configuration-generator/bin/create-genesis-block.js b/packages/configuration-generator/bin/create-genesis-block.js index d7338af440..99ed839e9c 100644 --- a/packages/configuration-generator/bin/create-genesis-block.js +++ b/packages/configuration-generator/bin/create-genesis-block.js @@ -3,27 +3,167 @@ 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"; -async function run() { - const paths = envPaths("mainsail", { suffix: "" }); - const configCore = path.join(paths.config, "core"); - console.log(paths, configCore); - - const app = await makeApplication(configCore, {}); - const generator = app.get(Identifiers.ConfigurationGenerator); - - await generator.generate({ +const configurations = [ + // + // Default + { network: "devnet", symbol: "TѦ", token: "ARK", distribute: true, premine: "125000000000000000000000000", chainId: 10000, + validators: 53, initialHeight: 0, - // snapshot: { - // path: "../../snapshot-19a87c96dbe8ad1be06d33e97cd17f5662eb952c29efd3d8bb00c9c75e7582bc.json", - // }, - }); + }, + // + // 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)) { From bfe3b795e4aa403dfc7a43d952d3adaf0f661cb4 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Thu, 22 May 2025 04:43:12 +0000 Subject: [PATCH 3/6] style: resolve style guide violations --- .../bin/create-genesis-block.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/configuration-generator/bin/create-genesis-block.js b/packages/configuration-generator/bin/create-genesis-block.js index 99ed839e9c..eb688f76b2 100644 --- a/packages/configuration-generator/bin/create-genesis-block.js +++ b/packages/configuration-generator/bin/create-genesis-block.js @@ -3,7 +3,7 @@ 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 { fileURLToPath } from "url"; import { copyFileSync } from "fs"; import { readJSONSync, writeJSONSync } from "fs-extra/esm"; @@ -39,7 +39,7 @@ const configurations = [ // stageTimeout: 100, // stageTimeoutIncrease: 100, // tolerance: 100, - // }, + // }, // postGenerate: (location) => { // // Functional tests run on single node // const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -83,12 +83,12 @@ const configurations = [ // } // // 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, @@ -134,7 +134,7 @@ const configurations = [ // 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"); @@ -143,7 +143,7 @@ const configurations = [ // } // } // }, -] +]; async function run() { const paths = envPaths("mainsail", { suffix: "" }); @@ -160,7 +160,7 @@ const generateConfiguration = async (path, configuration) => { const generator = app.get(Identifiers.ConfigurationGenerator); await generator.generate(configuration); - + if (configuration.postGenerate) { configuration.postGenerate(generator.configurationPath); } @@ -170,6 +170,6 @@ const generateConfiguration = async (path, configuration) => { await app.getTagged(AppIdentifiers.Evm.Instance, "instance", tag).dispose(); } } -} +}; run(); From 62a430483d56bf8322a15a6ca8ddc511be22957a Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Thu, 22 May 2025 14:08:46 +0900 Subject: [PATCH 4/6] add to codecov.yml --- codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/codecov.yml b/codecov.yml index 300928b440..896c1b30c8 100644 --- a/codecov.yml +++ b/codecov.yml @@ -2,4 +2,5 @@ ignore: - "contracts/test" - "packages/contracts" - "packages/utils/benchmark" + - "packages/configuration-generator/bin" From cef87ef1a7983eedd50b4b2536602872d4052848 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Thu, 22 May 2025 17:09:21 +0900 Subject: [PATCH 5/6] split script --- .../bin/create-genesis-block.js | 170 ++---------------- .../bin/update-test-genesis-blocks.js | 163 +++++++++++++++++ 2 files changed, 178 insertions(+), 155 deletions(-) create mode 100644 packages/configuration-generator/bin/update-test-genesis-blocks.js diff --git a/packages/configuration-generator/bin/create-genesis-block.js b/packages/configuration-generator/bin/create-genesis-block.js index eb688f76b2..3775cc41ba 100644 --- a/packages/configuration-generator/bin/create-genesis-block.js +++ b/packages/configuration-generator/bin/create-genesis-block.js @@ -3,173 +3,33 @@ 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 = [ - // - // Default - { - network: "devnet", - symbol: "TѦ", - token: "ARK", - distribute: true, - premine: "125000000000000000000000000", - chainId: 10000, - validators: 53, - initialHeight: 0, - }, - // - // 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 app = await makeApplication(configCore, {}); const generator = app.get(Identifiers.ConfigurationGenerator); - await generator.generate(configuration); - - if (configuration.postGenerate) { - configuration.postGenerate(generator.configurationPath); - } + await generator.generate({ + network: "devnet", + symbol: "TѦ", + token: "ARK", + distribute: true, + premine: "125000000000000000000000000", + chainId: 10000, + initialHeight: 0, + // snapshot: { + // path: "../../snapshot-19a87c96dbe8ad1be06d33e97cd17f5662eb952c29efd3d8bb00c9c75e7582bc.json", + // }, + }); 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(); +run(); \ No newline at end of file diff --git a/packages/configuration-generator/bin/update-test-genesis-blocks.js b/packages/configuration-generator/bin/update-test-genesis-blocks.js new file mode 100644 index 0000000000..09ec347c61 --- /dev/null +++ b/packages/configuration-generator/bin/update-test-genesis-blocks.js @@ -0,0 +1,163 @@ +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(); From 9907f9defde8518a9a9e48b6a79170dd7aec5086 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Thu, 22 May 2025 08:14:58 +0000 Subject: [PATCH 6/6] style: resolve style guide violations --- .../bin/create-genesis-block.js | 2 +- .../bin/update-test-genesis-blocks.js | 337 ++++++++++-------- 2 files changed, 198 insertions(+), 141 deletions(-) diff --git a/packages/configuration-generator/bin/create-genesis-block.js b/packages/configuration-generator/bin/create-genesis-block.js index 3775cc41ba..d7338af440 100644 --- a/packages/configuration-generator/bin/create-genesis-block.js +++ b/packages/configuration-generator/bin/create-genesis-block.js @@ -32,4 +32,4 @@ async function run() { } } -run(); \ No newline at end of file +run(); diff --git a/packages/configuration-generator/bin/update-test-genesis-blocks.js b/packages/configuration-generator/bin/update-test-genesis-blocks.js index 09ec347c61..eaad66d367 100644 --- a/packages/configuration-generator/bin/update-test-genesis-blocks.js +++ b/packages/configuration-generator/bin/update-test-genesis-blocks.js @@ -8,156 +8,213 @@ 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); - } - } - }, + // + // 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); + 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); - } + 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); + const app = await makeApplication(path, {}); + const generator = app.get(Identifiers.ConfigurationGenerator); - await generator.generate(configuration); + await generator.generate(configuration); - if (configuration.postGenerate) { - configuration.postGenerate(generator.configurationPath); - } + 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(); - } - } + 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();