Skip to content

Commit f653eda

Browse files
kien6034onbjerg
andauthored
feat: add trace transaction opts (#11781)
* feat: add trace transaction opts * chore: rm comment * chore: rm newline --------- Co-authored-by: onbjerg <[email protected]>
1 parent 16658c2 commit f653eda

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

crates/cast/src/cmd/call.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,31 @@ impl CallArgs {
297297
let tx_kind = tx.inner.to.expect("set by builder");
298298
let env_tx = &mut executor.env_mut().tx;
299299

300+
// Set transaction options with --trace
301+
if let Some(gas_limit) = tx.inner.gas {
302+
env_tx.gas_limit = gas_limit;
303+
}
304+
305+
if let Some(gas_price) = tx.inner.gas_price {
306+
env_tx.gas_price = gas_price;
307+
}
308+
309+
if let Some(max_fee_per_gas) = tx.inner.max_fee_per_gas {
310+
env_tx.gas_price = max_fee_per_gas;
311+
}
312+
313+
if let Some(max_priority_fee_per_gas) = tx.inner.max_priority_fee_per_gas {
314+
env_tx.gas_priority_fee = Some(max_priority_fee_per_gas);
315+
}
316+
317+
if let Some(max_fee_per_blob_gas) = tx.inner.max_fee_per_blob_gas {
318+
env_tx.max_fee_per_blob_gas = max_fee_per_blob_gas;
319+
}
320+
321+
if let Some(nonce) = tx.inner.nonce {
322+
env_tx.nonce = nonce;
323+
}
324+
300325
if let Some(tx_type) = tx.inner.transaction_type {
301326
env_tx.tx_type = tx_type;
302327
}
@@ -479,7 +504,7 @@ fn address_slot_value_override(address_override: &str) -> Result<(Address, U256,
479504
#[cfg(test)]
480505
mod tests {
481506
use super::*;
482-
use alloy_primitives::{address, b256, fixed_bytes, hex};
507+
use alloy_primitives::{U64, address, b256, fixed_bytes, hex};
483508

484509
#[test]
485510
fn test_get_state_overrides() {
@@ -673,4 +698,36 @@ mod tests {
673698
assert!(args.debug);
674699
assert_eq!(args.args, vec!["-999999"]);
675700
}
701+
702+
#[test]
703+
fn test_transaction_opts_with_trace() {
704+
// Test that transaction options are correctly parsed when using --trace
705+
let args = CallArgs::parse_from([
706+
"foundry-cli",
707+
"--trace",
708+
"--gas-limit",
709+
"1000000",
710+
"--gas-price",
711+
"20000000000",
712+
"--priority-gas-price",
713+
"2000000000",
714+
"--nonce",
715+
"42",
716+
"--value",
717+
"1000000000000000000", // 1 ETH
718+
"--blob-gas-price",
719+
"10000000000",
720+
"0xDeaDBeeFcAfEbAbEfAcEfEeDcBaDbEeFcAfEbAbE",
721+
"balanceOf(address)",
722+
"0x123456789abcdef123456789abcdef123456789a",
723+
]);
724+
725+
assert!(args.trace);
726+
assert_eq!(args.tx.gas_limit, Some(U256::from(1000000u32)));
727+
assert_eq!(args.tx.gas_price, Some(U256::from(20000000000u64)));
728+
assert_eq!(args.tx.priority_gas_price, Some(U256::from(2000000000u64)));
729+
assert_eq!(args.tx.nonce, Some(U64::from(42)));
730+
assert_eq!(args.tx.value, Some(U256::from(1000000000000000000u64)));
731+
assert_eq!(args.tx.blob_gas_price, Some(U256::from(10000000000u64)));
732+
}
676733
}

0 commit comments

Comments
 (0)