Skip to content

Commit

Permalink
feat(besu-test-ledger): send funds to already created address
Browse files Browse the repository at this point in the history
Enable sending funds to an existing account

New method created:
* sendEthToAccount

Closes #2250

Co-authored-by: Peter Somogyvari <peter.somogyvari@accenture.com>

Signed-off-by: André Augusto <andre.augusto@tecnico.ulisboa.pt>
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
AndreAugusto11 authored and petermetz committed Aug 13, 2023
1 parent 350b7b7 commit 3a58508
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Account> {
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<void> {
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,
},
Expand All @@ -188,8 +205,6 @@ export class BesuTestLedger implements ITestLedger {

if (receipt instanceof Error) {
throw receipt;
} else {
return ethTestAccount;
}
}

Expand Down

0 comments on commit 3a58508

Please sign in to comment.