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 bf9cb41e00a..a064bcf9dfb 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 @@ -4,7 +4,7 @@ import Joi from "joi"; import tar from "tar-stream"; import { EventEmitter } from "events"; import Web3 from "web3"; -import { Account } from "web3-core"; +import { Account, TransactionReceipt } from "web3-core"; import { LogLevelDesc, Logger, @@ -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()); + 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,9 +205,8 @@ export class BesuTestLedger implements ITestLedger { if (receipt instanceof Error) { throw receipt; - } else { - return ethTestAccount; } + return receipt; } public async getBesuKeyPair(): Promise {