Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: parse privat keys correctly #2548

Merged
merged 1 commit into from
Aug 11, 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
11 changes: 10 additions & 1 deletion ethers-core/src/utils/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ impl Anvil {
}

if is_private_key && line.starts_with('(') {
let key_str = &line[6..line.len() - 1];
let key_str = line
.split("0x")
.last()
.unwrap_or_else(|| panic!("could not parse private key: {}", line))
.trim();
let key_hex = hex::decode(key_str).expect("could not parse as hex");
let key = K256SecretKey::from_bytes(&GenericArray::clone_from_slice(&key_hex))
.expect("did not get private key");
Expand All @@ -293,4 +297,9 @@ mod tests {
fn can_launch_anvil() {
let _ = Anvil::new().spawn();
}

#[test]
fn can_launch_anvil_with_more_accounts() {
let _ = Anvil::new().arg("--accounts").arg("20").spawn();
}
}