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 hyperledger-cacti#2250

Co-authored-by: Peter Somogyvari <[email protected]>

Signed-off-by: André Augusto <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
AndreAugusto11 authored and sandeepnRES committed Dec 21, 2023
1 parent 2191f5f commit fb64660
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 fb64660

Please sign in to comment.