-
Notifications
You must be signed in to change notification settings - Fork 50
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
chore(test): simulation unit tests #357
Conversation
191b0ef
to
deb34ed
Compare
b4e7f18
to
4285ec4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! A few notes inline, but these are really good tests.
src/common/simulation.rs
Outdated
Address::from_str("0xb856dbd4fa1a79a46d426f537455e7d3e79ab7c4").unwrap(), | ||
Address::from_str("0x8abb13360b87be5eeb1b98647a016add927a136c").unwrap(), | ||
], | ||
associated_slots_by_address: serde_json::from_str(r#" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might consider writing this using the json!
macro, which would let you parse the json at compile time, although it doesn't really matter (docs).
src/common/tracer.rs
Outdated
.simulate_validation(op, max_validation_gas) | ||
.await?; | ||
|
||
let asdf = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Nit) Needs a more descriptive name. trace
might be good.
src/common/simulation.rs
Outdated
|
||
tracer.expect_trace_simulate_validation().returning(move |_, _, _| Ok(SimulationTracerOutput { | ||
accessed_contract_addresses: vec![ | ||
Address::from_str("0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789").unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that you have the option of writing each of these as
"0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789".parse().unwrap()
although writing it with Address::from_str
is fine too if you like the clarity.
You also have the option of declaring the test return type as a result:
async fn test_simulate_validation() -> anyhow::Result<()> {
and then you could use ?
instead of .unwrap()
throughout, but that's just personal preference.
src/common/simulation.rs
Outdated
|
||
tracer.expect_trace_simulate_validation().returning(move |_, _, _| Ok(SimulationTracerOutput { | ||
accessed_contract_addresses: vec![ | ||
Address::from_str("0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789").unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's already written it might not be worth it, but there's enough of these that if you had to do this again I would consider writing some kind of helper function to write these with less boilerplate. Something like
fn address(s: &str) -> Address {
Address::from_str("0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789").unwrap()
}
and then you could have
accessed_contract_addresses: vec![
address("0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"),
address("0xb856dbd4fa1a79a46d426f537455e7d3e79ab7c4"),
address("0x8abb13360b87be5eeb1b98647a016add927a136c"),
],
b0ea131
to
b96ed01
Compare
[Closes/Fixes] #298
Proposed Changes
simulation.rs
,tracer.rs
, andprovider_like.rs
to be mockablesimulation.rs