Skip to content
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(anvil): Apply state overrides in debug_traceCall #9172

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,13 +1430,20 @@ impl Backend {
block_request: Option<BlockRequest>,
opts: GethDebugTracingCallOptions,
) -> Result<GethTrace, BlockchainError> {
let GethDebugTracingCallOptions { tracing_options, block_overrides: _, state_overrides: _ } =
let GethDebugTracingCallOptions { tracing_options, block_overrides: _, state_overrides } =
opts;
let GethDebugTracingOptions { config, tracer, tracer_config, .. } = tracing_options;

self.with_database_at(block_request, |state, block| {
let block_number = block.number;

let state = if let Some(overrides) = state_overrides {
Box::new(state::apply_state_override(overrides, state)?)
as Box<dyn MaybeFullDatabase>
} else {
state
};

if let Some(tracer) = tracer {
return match tracer {
GethDebugTracerType::BuiltInTracer(tracer) => match tracer {
Expand Down
50 changes: 49 additions & 1 deletion crates/anvil/tests/it/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ use crate::{
};
use alloy_eips::BlockId;
use alloy_network::{EthereumWallet, TransactionBuilder};
use alloy_primitives::{hex, Address, Bytes, U256};
use alloy_primitives::{
hex::{self, FromHex},
Address, Bytes, U256,
};
use alloy_provider::{
ext::{DebugApi, TraceApi},
Provider,
};
use alloy_rpc_types::{
state::StateOverride,
trace::{
filter::{TraceFilter, TraceFilterMode},
geth::{
Expand Down Expand Up @@ -259,6 +263,50 @@ async fn test_call_tracer_debug_trace_call() {
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_debug_trace_call_state_override() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let wallets = handle.dev_wallets().collect::<Vec<_>>();

let tx = TransactionRequest::default()
.from(wallets[1].address())
.to("0x1234567890123456789012345678901234567890".parse().unwrap());

let override_json = r#"{
"0x1234567890123456789012345678901234567890": {
"balance": "0x01",
"code": "0x30315f5260205ff3"
}
}"#;

let state_override: StateOverride = serde_json::from_str(override_json).unwrap();

let tx_traces = handle
.http_provider()
.debug_trace_call(
tx.clone(),
BlockId::latest(),
GethDebugTracingCallOptions::default()
.with_tracing_options(GethDebugTracingOptions::default())
.with_state_overrides(state_override),
)
.await
.unwrap();

match tx_traces {
GethTrace::Default(trace_res) => {
assert_eq!(
trace_res.return_value,
Bytes::from_hex("0000000000000000000000000000000000000000000000000000000000000001")
.unwrap()
);
}
_ => {
unreachable!()
}
}
}

// <https://github.com/foundry-rs/foundry/issues/2656>
#[tokio::test(flavor = "multi_thread")]
async fn test_trace_address_fork() {
Expand Down
Loading