-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(forge): selectively enable Etherscan trace resolving when a test in ran in a forked environment and return block number in trace on a failed test #7606
Changes from 45 commits
68bfdb8
7251ef4
5eca07c
004dc11
46ae039
acba4c4
f3fc621
d63e4fc
0ff4a3f
c42c3a6
f9ad7c0
c5a4690
15a9bfd
7e4bb99
c473f01
7f1f3c2
efc05d3
d2ba46b
5ae23e5
4edb749
8fb7445
676b249
d48c3b3
b48a587
5404c5c
059decc
5799cc2
07dde75
07fceb5
bfca63c
85bb139
39807c9
56e1006
52e2ca5
28986ac
ad74f98
4fcbdce
a2ba880
dd2592b
715d8b2
f6310ff
00897fa
163e337
e5037d1
2b6865f
b311550
1536799
af34ff8
d42eb2e
2e5918b
c0775aa
747e17c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use alloy_primitives::U256; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// An execution context | ||
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] | ||
pub struct Context { | ||
/// The block number of the context. | ||
pub block_number: U256, | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
use alloy_primitives::U256; | ||||||
use foundry_evm_core::fork::Context; | ||||||
use revm::{ | ||||||
interpreter::{CallInputs, CallOutcome}, | ||||||
Database, EvmContext, Inspector, | ||||||
}; | ||||||
|
||||||
/// An inspector that collects EVM context during execution. | ||||||
#[derive(Clone, Debug, Default)] | ||||||
pub struct ContextCollector { | ||||||
/// The collected execution contexts. | ||||||
pub contexts: Vec<Context>, | ||||||
} | ||||||
|
||||||
impl<DB: Database> Inspector<DB> for ContextCollector { | ||||||
fn call(&mut self, ecx: &mut EvmContext<DB>, _call: &mut CallInputs) -> Option<CallOutcome> { | ||||||
let block_number = ecx.inner.env.block.number; | ||||||
|
||||||
// Skip if the block number is at genesis | ||||||
if block_number == U256::from(1) { | ||||||
return None; | ||||||
} | ||||||
|
||||||
// Skip if the previous context is the same | ||||||
if let Some(Context { block_number: prev_block_number }) = self.contexts.last() { | ||||||
if *prev_block_number == block_number { | ||||||
return None; | ||||||
} | ||||||
} | ||||||
|
||||||
// Push the new context | ||||||
self.contexts.push(Context { block_number }); | ||||||
Comment on lines
+19
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, not sure this will work, because there are also cheatcodes that modify the block number. the fork context is essentially already tracked in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cheatcodes overwrite the foundry/crates/evm/core/src/backend/mod.rs Lines 782 to 783 in ba399ae
By extracting it after the test we can only capture the last context as the backend overwrites the |
||||||
|
||||||
None | ||||||
} | ||||||
} |
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.
why do we need an inspector for this?
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.
This was added as an inspector so that it would run on every call occurring inside the function body, that way we were able to track the modifications made to the environment (such as the updating of the block number).
It isn't strictly necessary as we only need the most recent change to the block env, excluding a reset to genesis