Skip to content

Commit 9979a41

Browse files
authored
chore: Bump 1.3.5, backport state overrides fix (#11577)
* fix(cast): allow comma-separated values for overrides (#11553) * fix(cast): allow comma sepparated values for overrides * Fix multiple slots * Tests with traces * chore: bump v1.3.5 (#11576)
1 parent fd677c8 commit 9979a41

File tree

4 files changed

+120
-59
lines changed

4 files changed

+120
-59
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ members = [
2929
resolver = "2"
3030

3131
[workspace.package]
32-
version = "1.3.4"
32+
version = "1.3.5"
3333
edition = "2024"
3434
# Remember to update clippy.toml as well
3535
rust-version = "1.88"

crates/cast/src/cmd/call.rs

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use super::run::fetch_contracts_bytecode_from_trace;
12
use crate::{
23
Cast,
34
traces::TraceKind,
45
tx::{CastTxBuilder, SenderKind},
56
};
67
use alloy_ens::NameOrAddress;
7-
use alloy_primitives::{Address, Bytes, TxKind, U256};
8+
use alloy_primitives::{Address, B256, Bytes, TxKind, U256, map::HashMap};
89
use alloy_provider::Provider;
910
use alloy_rpc_types::{
1011
BlockId, BlockNumberOrTag, BlockOverrides,
@@ -34,8 +35,6 @@ use regex::Regex;
3435
use revm::context::TransactionType;
3536
use std::{str::FromStr, sync::LazyLock};
3637

37-
use super::run::fetch_contracts_bytecode_from_trace;
38-
3938
// matches override pattern <address>:<slot>:<value>
4039
// e.g. 0x123:0x1:0x1234
4140
static OVERRIDE_PATTERN: LazyLock<Regex> =
@@ -131,29 +130,29 @@ pub struct CallArgs {
131130
#[arg(long, visible_alias = "la")]
132131
pub with_local_artifacts: bool,
133132

134-
/// Override the balance of an account.
135-
/// Format: address:balance
136-
#[arg(long = "override-balance", value_name = "ADDRESS:BALANCE")]
133+
/// Override the accounts balance.
134+
/// Format: "address:balance,address:balance"
135+
#[arg(long = "override-balance", value_name = "ADDRESS:BALANCE", value_delimiter = ',')]
137136
pub balance_overrides: Option<Vec<String>>,
138137

139-
/// Override the nonce of an account.
140-
/// Format: address:nonce
141-
#[arg(long = "override-nonce", value_name = "ADDRESS:NONCE")]
138+
/// Override the accounts nonce.
139+
/// Format: "address:nonce,address:nonce"
140+
#[arg(long = "override-nonce", value_name = "ADDRESS:NONCE", value_delimiter = ',')]
142141
pub nonce_overrides: Option<Vec<String>>,
143142

144-
/// Override the code of an account.
145-
/// Format: address:code
146-
#[arg(long = "override-code", value_name = "ADDRESS:CODE")]
143+
/// Override the accounts code.
144+
/// Format: "address:code,address:code"
145+
#[arg(long = "override-code", value_name = "ADDRESS:CODE", value_delimiter = ',')]
147146
pub code_overrides: Option<Vec<String>>,
148147

149-
/// Override the state of an account.
150-
/// Format: address:slot:value
151-
#[arg(long = "override-state", value_name = "ADDRESS:SLOT:VALUE")]
148+
/// Override the accounts state and replace the current state entirely with the new one.
149+
/// Format: "address:slot:value,address:slot:value"
150+
#[arg(long = "override-state", value_name = "ADDRESS:SLOT:VALUE", value_delimiter = ',')]
152151
pub state_overrides: Option<Vec<String>>,
153152

154-
/// Override the state diff of an account.
155-
/// Format: address:slot:value
156-
#[arg(long = "override-state-diff", value_name = "ADDRESS:SLOT:VALUE")]
153+
/// Override the accounts state specific slots and preserve the rest of the state.
154+
/// Format: "address:slot:value,address:slot:value"
155+
#[arg(long = "override-state-diff", value_name = "ADDRESS:SLOT:VALUE", value_delimiter = ',')]
157156
pub state_diff_overrides: Option<Vec<String>>,
158157

159158
/// Override the block timestamp.
@@ -393,18 +392,29 @@ impl CallArgs {
393392
state_overrides_builder.with_code(addr.parse()?, Bytes::from_str(code_str)?);
394393
}
395394

396-
// Parse state overrides
397-
for override_str in self.state_overrides.iter().flatten() {
398-
let (addr, slot, value) = address_slot_value_override(override_str)?;
399-
state_overrides_builder =
400-
state_overrides_builder.with_state(addr, [(slot.into(), value.into())]);
395+
type StateOverrides = HashMap<Address, HashMap<B256, B256>>;
396+
let parse_state_overrides =
397+
|overrides: &Option<Vec<String>>| -> Result<StateOverrides, eyre::Report> {
398+
let mut state_overrides: StateOverrides = StateOverrides::default();
399+
400+
overrides.iter().flatten().try_for_each(|s| -> Result<(), eyre::Report> {
401+
let (addr, slot, value) = address_slot_value_override(s)?;
402+
state_overrides.entry(addr).or_default().insert(slot.into(), value.into());
403+
Ok(())
404+
})?;
405+
406+
Ok(state_overrides)
407+
};
408+
409+
// Parse and apply state overrides
410+
for (addr, entries) in parse_state_overrides(&self.state_overrides)? {
411+
state_overrides_builder = state_overrides_builder.with_state(addr, entries.into_iter());
401412
}
402413

403-
// Parse state diff overrides
404-
for override_str in self.state_diff_overrides.iter().flatten() {
405-
let (addr, slot, value) = address_slot_value_override(override_str)?;
414+
// Parse and apply state diff overrides
415+
for (addr, entries) in parse_state_overrides(&self.state_diff_overrides)? {
406416
state_overrides_builder =
407-
state_overrides_builder.with_state_diff(addr, [(slot.into(), value.into())]);
417+
state_overrides_builder.with_state_diff(addr, entries.into_iter())
408418
}
409419

410420
Ok(Some(state_overrides_builder.build()))

0 commit comments

Comments
 (0)