Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(besu-test-ledger): send funds to already created address #2251

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading