reth_e2e_test_utils/
wallet.rs
1use alloy_signer::Signer;
2use alloy_signer_local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner};
3
4#[derive(Debug)]
6pub struct Wallet {
7 pub inner: PrivateKeySigner,
9 pub inner_nonce: u64,
11 pub chain_id: u64,
13 amount: usize,
14 derivation_path: Option<String>,
15}
16
17impl Wallet {
18 pub fn new(amount: usize) -> Self {
20 let inner = MnemonicBuilder::<English>::default().phrase(TEST_MNEMONIC).build().unwrap();
21 Self { inner, chain_id: 1, amount, derivation_path: None, inner_nonce: 0 }
22 }
23
24 pub const fn with_chain_id(mut self, chain_id: u64) -> Self {
26 self.chain_id = chain_id;
27 self
28 }
29
30 fn get_derivation_path(&self) -> &str {
31 self.derivation_path.as_deref().unwrap_or("m/44'/60'/0'/0/")
32 }
33
34 pub fn wallet_gen(&self) -> Vec<PrivateKeySigner> {
36 let builder = MnemonicBuilder::<English>::default().phrase(TEST_MNEMONIC);
37
38 let derivation_path = self.get_derivation_path();
40
41 let mut wallets = Vec::with_capacity(self.amount);
42 for idx in 0..self.amount {
43 let builder =
44 builder.clone().derivation_path(format!("{derivation_path}{idx}")).unwrap();
45 let wallet = builder.build().unwrap().with_chain_id(Some(self.chain_id));
46 wallets.push(wallet)
47 }
48 wallets
49 }
50}
51
52const TEST_MNEMONIC: &str = "test test test test test test test test test test test junk";
53
54impl Default for Wallet {
55 fn default() -> Self {
56 Self::new(1)
57 }
58}