From ac19e49b87dad7d23d9eea91e2bbca0e3a0f69e4 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Thu, 12 Nov 2020 12:38:29 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20method:=20QuorumTe?= =?UTF-8?q?stLedger#getGenesisAccount()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A utility method on to easily obtain an account from the genesis allocation that has a high balance to seed other accounts without having to mine for them (which doesn't make sense in a quorom ledger for us in a testing environment) Signed-off-by: Peter Somogyvari --- .../typescript/quorum/quorum-test-ledger.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts b/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts index e2ef61ecf2..c47977b04d 100644 --- a/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts +++ b/packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts @@ -105,6 +105,25 @@ export class QuorumTestLedger implements ITestLedger { }); } + /** + * Obtains the address of an account from the genesis allocation with a + * minimum balance of `minBalance`. + * + * @param minBalance The minimum balance to try and find a genesis account with. + * + * @throws {Error} If the balance is too high and there aren't any genesis + * accounts allocated with such a high balance then an exceptin is thrown. + */ + public async getGenesisAccount(minBalance: number = 10e7): Promise { + const { alloc } = await this.getGenesisJsObject(); + + const firstHighNetWorthAccount = Object.keys(alloc).find( + (addr) => parseInt(alloc[addr].balance, 10) > minBalance + ) as string; + + return firstHighNetWorthAccount; + } + public async getQuorumKeyPair(): Promise { const publicKey = await this.getFileContents("/nodekey"); const privateKey = await this.getFileContents("/key");