Skip to content

Commit ac19e49

Browse files
committed
feat: 🎸 add method: QuorumTestLedger#getGenesisAccount()
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 <[email protected]>
1 parent c21c873 commit ac19e49

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/cactus-test-tooling/src/main/typescript/quorum/quorum-test-ledger.ts

+19
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,25 @@ export class QuorumTestLedger implements ITestLedger {
105105
});
106106
}
107107

108+
/**
109+
* Obtains the address of an account from the genesis allocation with a
110+
* minimum balance of `minBalance`.
111+
*
112+
* @param minBalance The minimum balance to try and find a genesis account with.
113+
*
114+
* @throws {Error} If the balance is too high and there aren't any genesis
115+
* accounts allocated with such a high balance then an exceptin is thrown.
116+
*/
117+
public async getGenesisAccount(minBalance: number = 10e7): Promise<string> {
118+
const { alloc } = await this.getGenesisJsObject();
119+
120+
const firstHighNetWorthAccount = Object.keys(alloc).find(
121+
(addr) => parseInt(alloc[addr].balance, 10) > minBalance
122+
) as string;
123+
124+
return firstHighNetWorthAccount;
125+
}
126+
108127
public async getQuorumKeyPair(): Promise<IKeyPair> {
109128
const publicKey = await this.getFileContents("/nodekey");
110129
const privateKey = await this.getFileContents("/key");

0 commit comments

Comments
 (0)