From c2c033884c785e7f6f817ce5eb87608cf368cb99 Mon Sep 17 00:00:00 2001 From: Abhinav Mishra Date: Tue, 24 Oct 2023 04:53:35 +0545 Subject: [PATCH] feature: support custom balance allocation to nodes (#51) --- src/index.ts | 7 +++++++ src/lib/genesisGenerate.ts | 4 ++-- src/questions/commonQs.ts | 6 ++++++ src/questions/qbftQs.ts | 12 +++++++++++- src/types/quorumConfig.ts | 1 + tests/lib/testConstants.ts | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index cce509d..0f7b341 100644 --- a/src/index.ts +++ b/src/index.ts @@ -141,6 +141,12 @@ export async function main(): Promise { default: false, describe: "Include quorum-dev-quickstart test accounts", }, + genesisNodeAllocation: { + type: "string", + demandOption: true, + default: "1000000000000000000000000000", + describe: "Balance allocated to each nodes", + }, alloc: { type: "string", demandOption: true, @@ -181,6 +187,7 @@ export async function main(): Promise { quickstartDevAccounts: args.quickstartDevAccounts, noOutputTimestamp: args.noOutputTimestamp, prefundedAccounts: args.alloc, + genesisNodeAllocation: args.genesisNodeAllocation, }; } else { const qr = new QuestionRenderer(rootQuestion); diff --git a/src/lib/genesisGenerate.ts b/src/lib/genesisGenerate.ts index 806b8de..633f588 100644 --- a/src/lib/genesisGenerate.ts +++ b/src/lib/genesisGenerate.ts @@ -80,7 +80,7 @@ export function createBesuGenesis( } node.forEach((account) => { besu.alloc[account.ethAccount.address] = { - balance: "1000000000000000000000000000", + balance: quorumConfig.genesisNodeAllocation, }; }); @@ -153,7 +153,7 @@ export function createGoQuorumGenesis( } node.forEach((account) => { goquorum.alloc[account.ethAccount.address] = { - balance: "1000000000000000000000000000", + balance: quorumConfig.genesisNodeAllocation, }; }); diff --git a/src/questions/commonQs.ts b/src/questions/commonQs.ts index 50619dc..7c3d8fe 100644 --- a/src/questions/commonQs.ts +++ b/src/questions/commonQs.ts @@ -10,6 +10,12 @@ export const quickstartDevAccountsQuestion: QuestionTree = { prompt: "Include quorum-dev-quickstart test accounts: [y/N]", }; +export const genesisNodeAllocationQuestion: QuestionTree = { + name: "genesisNodeAllocation", + prompt: + "Balance allocated to each nodes: (default 1000000000000000000000000000)", +}; + export const prefundedAccountsQuestion: QuestionTree = { name: "prefundedAccounts", prompt: diff --git a/src/questions/qbftQs.ts b/src/questions/qbftQs.ts index 2aa5ad2..40a96da 100644 --- a/src/questions/qbftQs.ts +++ b/src/questions/qbftQs.ts @@ -31,6 +31,16 @@ _prefundedAccountsQuestion.transformerValidator = allocStringValidator( "{}" ); +const _genesisNodeAllocationQuestion: QuestionTree = Object.assign( + {}, + commonQs.genesisNodeAllocationQuestion +); +_genesisNodeAllocationQuestion.transformerValidator = stringValidator( + _genesisNodeAllocationQuestion, + _prefundedAccountsQuestion, + "1000000000000000000000000000" +); + const _quickstartDevAccountsQuestion: QuestionTree = Object.assign( {}, @@ -38,7 +48,7 @@ const _quickstartDevAccountsQuestion: QuestionTree = Object.assign( ); _quickstartDevAccountsQuestion.transformerValidator = getYesNoValidator( _quickstartDevAccountsQuestion, - _prefundedAccountsQuestion, + _genesisNodeAllocationQuestion, "n" ); diff --git a/src/types/quorumConfig.ts b/src/types/quorumConfig.ts index a3acaf3..d6aa773 100644 --- a/src/types/quorumConfig.ts +++ b/src/types/quorumConfig.ts @@ -24,4 +24,5 @@ export type QuorumConfig = { quickstartDevAccounts: boolean; noOutputTimestamp: boolean; prefundedAccounts: string; + genesisNodeAllocation: string; }; diff --git a/tests/lib/testConstants.ts b/tests/lib/testConstants.ts index 24e8761..6f7fbab 100644 --- a/tests/lib/testConstants.ts +++ b/tests/lib/testConstants.ts @@ -25,6 +25,7 @@ export const TEST_QUORUM_CONFIG: QuorumConfig = { quickstartDevAccounts: false, noOutputTimestamp: false, prefundedAccounts: "{}", + genesisNodeAllocation: "100", }; export const TEST_NODE = {