Skip to content

Commit

Permalink
feat: 馃幐 add method: QuorumTestLedger#getGenesisAccount()
Browse files Browse the repository at this point in the history
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 <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Dec 1, 2020
1 parent c21c873 commit ac19e49
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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<IKeyPair> {
const publicKey = await this.getFileContents("/nodekey");
const privateKey = await this.getFileContents("/key");
Expand Down

0 comments on commit ac19e49

Please sign in to comment.