Skip to content

Commit 5874266

Browse files
authored
chore: migrate test-utils crate (#5874)
1 parent adb526b commit 5874266

File tree

5 files changed

+60
-31
lines changed

5 files changed

+60
-31
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/forge/tests/cli/multi_script.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use foundry_test_utils::{
55
util::{TestCommand, TestProject},
66
ScriptOutcome, ScriptTester,
77
};
8+
use foundry_utils::types::ToEthers;
89

910
forgetest_async!(
1011
can_deploy_multi_chain_script_without_lib,
@@ -20,11 +21,35 @@ forgetest_async!(
2021
.args(vec![handle1.http_endpoint(), handle2.http_endpoint()])
2122
.broadcast(ScriptOutcome::OkBroadcast);
2223

23-
assert!(1 == api1.transaction_count(tester.accounts_pub[0], None).await.unwrap().as_u32());
24-
assert!(1 == api1.transaction_count(tester.accounts_pub[1], None).await.unwrap().as_u32());
24+
assert!(
25+
1 == api1
26+
.transaction_count(tester.accounts_pub[0].to_ethers(), None)
27+
.await
28+
.unwrap()
29+
.as_u32()
30+
);
31+
assert!(
32+
1 == api1
33+
.transaction_count(tester.accounts_pub[1].to_ethers(), None)
34+
.await
35+
.unwrap()
36+
.as_u32()
37+
);
2538

26-
assert!(2 == api2.transaction_count(tester.accounts_pub[0], None).await.unwrap().as_u32());
27-
assert!(3 == api2.transaction_count(tester.accounts_pub[1], None).await.unwrap().as_u32());
39+
assert!(
40+
2 == api2
41+
.transaction_count(tester.accounts_pub[0].to_ethers(), None)
42+
.await
43+
.unwrap()
44+
.as_u32()
45+
);
46+
assert!(
47+
3 == api2
48+
.transaction_count(tester.accounts_pub[1].to_ethers(), None)
49+
.await
50+
.unwrap()
51+
.as_u32()
52+
);
2853
}
2954
);
3055

crates/forge/tests/cli/script.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use foundry_test_utils::{
88
util::{OutputExt, TestCommand, TestProject},
99
ScriptOutcome, ScriptTester,
1010
};
11-
use foundry_utils::rpc;
11+
use foundry_utils::{rpc, types::ToAlloy};
1212
use regex::Regex;
1313
use serde_json::Value;
1414
use std::{env, path::PathBuf, str::FromStr};
@@ -456,15 +456,15 @@ forgetest_async!(
456456
let mut tester = ScriptTester::new_broadcast(cmd, &handle.http_endpoint(), prj.root());
457457

458458
tester
459-
.load_addresses(vec![
460-
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap()
461-
])
459+
.load_addresses(vec![Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906")
460+
.unwrap()
461+
.to_alloy()])
462462
.await
463463
.add_sig("BroadcastTest", "deployPrivateKey()")
464464
.simulate(ScriptOutcome::OkSimulation)
465465
.broadcast(ScriptOutcome::OkBroadcast)
466466
.assert_nonce_increment_addresses(vec![(
467-
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap(),
467+
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap().to_alloy(),
468468
3,
469469
)])
470470
.await;
@@ -495,15 +495,15 @@ forgetest_async!(
495495
let mut tester = ScriptTester::new_broadcast(cmd, &handle.http_endpoint(), prj.root());
496496

497497
tester
498-
.load_addresses(vec![
499-
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap()
500-
])
498+
.load_addresses(vec![Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906")
499+
.unwrap()
500+
.to_alloy()])
501501
.await
502502
.add_sig("BroadcastTest", "deployRememberKey()")
503503
.simulate(ScriptOutcome::OkSimulation)
504504
.broadcast(ScriptOutcome::OkBroadcast)
505505
.assert_nonce_increment_addresses(vec![(
506-
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap(),
506+
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap().to_alloy(),
507507
2,
508508
)])
509509
.await;
@@ -519,9 +519,9 @@ forgetest_async!(
519519

520520
tester
521521
.add_deployer(0)
522-
.load_addresses(vec![
523-
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap()
524-
])
522+
.load_addresses(vec![Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906")
523+
.unwrap()
524+
.to_alloy()])
525525
.await
526526
.add_sig("BroadcastTest", "deployRememberKeyResume()")
527527
.simulate(ScriptOutcome::OkSimulation)
@@ -531,7 +531,7 @@ forgetest_async!(
531531
.await
532532
.run(ScriptOutcome::OkBroadcast)
533533
.assert_nonce_increment_addresses(vec![(
534-
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap(),
534+
Address::from_str("0x90F79bf6EB2c4f870365E785982E1f101E93b906").unwrap().to_alloy(),
535535
1,
536536
)])
537537
.await

crates/test-utils/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ repository.workspace = true
1414
[dependencies]
1515
foundry-config.workspace = true
1616
foundry-common.workspace = true
17+
foundry-utils.workspace = true
1718

1819
ethers.workspace = true
1920
ethers-solc = { workspace = true, features = ["project-util"] }
21+
alloy-primitives = { workspace = true, features = ["std"]}
2022

2123
eyre = "0.6"
2224
once_cell = "1"

crates/test-utils/src/script.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use crate::TestCommand;
2-
use ethers::{
3-
abi::Address,
4-
prelude::{Middleware, NameOrAddress, U256},
5-
utils::hex,
6-
};
2+
use alloy_primitives::{hex, Address, U256};
3+
use ethers::prelude::{Middleware, NameOrAddress};
74
use eyre::Result;
85
use foundry_common::{get_http_provider, RetryProvider};
6+
use foundry_utils::types::{ToAlloy, ToEthers};
97
use std::{collections::BTreeMap, path::Path, str::FromStr};
108

119
pub const BROADCAST_TEST_PATH: &str = "src/Broadcast.t.sol";
@@ -112,12 +110,12 @@ impl ScriptTester {
112110
if let Some(provider) = &self.provider {
113111
let nonce = provider
114112
.get_transaction_count(
115-
NameOrAddress::Address(self.accounts_pub[index as usize]),
113+
NameOrAddress::Address(self.accounts_pub[index as usize].to_ethers()),
116114
None,
117115
)
118116
.await
119117
.unwrap();
120-
self.nonces.insert(index, nonce);
118+
self.nonces.insert(index, nonce.to_alloy());
121119
}
122120
}
123121
self
@@ -129,18 +127,18 @@ impl ScriptTester {
129127
.provider
130128
.as_ref()
131129
.unwrap()
132-
.get_transaction_count(NameOrAddress::Address(address), None)
130+
.get_transaction_count(NameOrAddress::Address(address.to_ethers()), None)
133131
.await
134132
.unwrap();
135-
self.address_nonces.insert(address, nonce);
133+
self.address_nonces.insert(address, nonce.to_alloy());
136134
}
137135
self
138136
}
139137

140138
pub fn add_deployer(&mut self, index: u32) -> &mut Self {
141139
self.cmd.args([
142140
"--sender",
143-
&format!("0x{}", hex::encode(self.accounts_pub[index as usize].as_bytes())),
141+
&format!("0x{}", hex::encode(self.accounts_pub[index as usize].to_ethers())),
144142
]);
145143
self
146144
}
@@ -184,14 +182,16 @@ impl ScriptTester {
184182
.as_ref()
185183
.unwrap()
186184
.get_transaction_count(
187-
NameOrAddress::Address(self.accounts_pub[private_key_slot as usize]),
185+
NameOrAddress::Address(
186+
self.accounts_pub[private_key_slot as usize].to_ethers(),
187+
),
188188
None,
189189
)
190190
.await
191191
.unwrap();
192192
let prev_nonce = self.nonces.get(&private_key_slot).unwrap();
193193

194-
assert_eq!(nonce, prev_nonce + U256::from(expected_increment));
194+
assert_eq!(nonce, (prev_nonce + U256::from(expected_increment)).to_ethers());
195195
}
196196
self
197197
}
@@ -206,12 +206,12 @@ impl ScriptTester {
206206
.provider
207207
.as_ref()
208208
.unwrap()
209-
.get_transaction_count(NameOrAddress::Address(address), None)
209+
.get_transaction_count(NameOrAddress::Address(address.to_ethers()), None)
210210
.await
211211
.unwrap();
212212
let prev_nonce = self.address_nonces.get(&address).unwrap();
213213

214-
assert_eq!(nonce, prev_nonce + U256::from(expected_increment));
214+
assert_eq!(nonce, (prev_nonce + U256::from(expected_increment)).to_ethers());
215215
}
216216
self
217217
}

0 commit comments

Comments
 (0)