From 44de2be0c8319a7f3ac5f5fcae50bf2e03711905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Augusto?= Date: Sat, 4 Feb 2023 00:44:48 +0000 Subject: [PATCH] feat(besu-test-ledger): send funds to already created address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable sending funds to an existing account New method created: * sendEthToAccount Closes #2250 Co-authored-by: Peter Somogyvari Signed-off-by: André Augusto Signed-off-by: Peter Somogyvari --- .../main/typescript/besu/besu-test-ledger.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts b/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts index bf9cb41e00..2641fa6cc9 100644 --- a/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts +++ b/packages/cactus-test-tooling/src/main/typescript/besu/besu-test-ledger.ts @@ -164,16 +164,33 @@ export class BesuTestLedger implements ITestLedger { * @param [seedMoney=10e8] The amount of money to seed the new test account with. */ public async createEthTestAccount(seedMoney = 10e8): Promise { - const fnTag = `BesuTestLedger#getEthTestAccount()`; - const rpcApiHttpHost = await this.getRpcApiHttpHost(); const web3 = new Web3(rpcApiHttpHost); const ethTestAccount = web3.eth.accounts.create(uuidv4()); + await this.sendEthToAccount(ethTestAccount.address, seedMoney); + + return ethTestAccount; + } + + /** + * Sends seed money to a provided address to get things started. + * + * @param [seedMoney=10e8] The amount of money to seed the new test account with. + */ + public async sendEthToAccount( + address: string, + seedMoney = 10e8, + ): Promise { + const fnTag = `BesuTestLedger#sendEthToAccount()`; + + const rpcApiHttpHost = await this.getRpcApiHttpHost(); + const web3 = new Web3(rpcApiHttpHost); + const tx = await web3.eth.accounts.signTransaction( { from: this.getGenesisAccountPubKey(), - to: ethTestAccount.address, + to: address, value: seedMoney, gas: 1000000, }, @@ -188,8 +205,6 @@ export class BesuTestLedger implements ITestLedger { if (receipt instanceof Error) { throw receipt; - } else { - return ethTestAccount; } }