Cleanup mutability

This commit is contained in:
Omar Abdulla
2025-07-21 19:47:17 +03:00
parent d7bc4f1fab
commit 7cda3416f0
3 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ fn main() -> anyhow::Result<()> {
None None
} }
}) { }) {
replacement_map.get(address); replacement_map.add(address);
} }
case.handle_address_replacement(&mut replacement_map)?; case.handle_address_replacement(&mut replacement_map)?;
replacement_private_keys.extend( replacement_private_keys.extend(
+5 -5
View File
@@ -104,7 +104,7 @@ impl ExpectedOutput {
pub fn handle_address_replacement( pub fn handle_address_replacement(
&mut self, &mut self,
old_to_new_mapping: &mut AddressReplacementMap, old_to_new_mapping: &AddressReplacementMap,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if let Some(ref mut calldata) = self.return_data { if let Some(ref mut calldata) = self.return_data {
calldata.handle_address_replacement(old_to_new_mapping)?; calldata.handle_address_replacement(old_to_new_mapping)?;
@@ -121,7 +121,7 @@ impl ExpectedOutput {
impl Event { impl Event {
pub fn handle_address_replacement( pub fn handle_address_replacement(
&mut self, &mut self,
old_to_new_mapping: &mut AddressReplacementMap, old_to_new_mapping: &AddressReplacementMap,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if let Some(ref mut address) = self.address { if let Some(ref mut address) = self.address {
if let Some(new_address) = old_to_new_mapping.resolve(address.to_string().as_str()) { if let Some(new_address) = old_to_new_mapping.resolve(address.to_string().as_str()) {
@@ -157,7 +157,7 @@ impl Calldata {
pub fn handle_address_replacement( pub fn handle_address_replacement(
&mut self, &mut self,
old_to_new_mapping: &mut AddressReplacementMap, old_to_new_mapping: &AddressReplacementMap,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match self { match self {
Calldata::Single(_) => {} Calldata::Single(_) => {}
@@ -220,7 +220,7 @@ impl Calldata {
impl Expected { impl Expected {
pub fn handle_address_replacement( pub fn handle_address_replacement(
&mut self, &mut self,
old_to_new_mapping: &mut AddressReplacementMap, old_to_new_mapping: &AddressReplacementMap,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match self { match self {
Expected::Calldata(calldata) => { Expected::Calldata(calldata) => {
@@ -347,7 +347,7 @@ impl Input {
old_to_new_mapping: &mut AddressReplacementMap, old_to_new_mapping: &mut AddressReplacementMap,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if self.caller != default_caller() { if self.caller != default_caller() {
self.caller = old_to_new_mapping.get(self.caller); self.caller = old_to_new_mapping.add(self.caller);
} }
self.calldata self.calldata
.handle_address_replacement(old_to_new_mapping)?; .handle_address_replacement(old_to_new_mapping)?;
+2 -2
View File
@@ -339,7 +339,7 @@ impl AddressReplacementMap {
self.0.contains_key(address) self.0.contains_key(address)
} }
pub fn get(&mut self, address: Address) -> Address { pub fn add(&mut self, address: Address) -> Address {
self.0 self.0
.entry(address) .entry(address)
.or_insert_with(|| { .or_insert_with(|| {
@@ -355,7 +355,7 @@ impl AddressReplacementMap {
.1 .1
} }
pub fn resolve(&mut self, value: &str) -> Option<Address> { pub fn resolve(&self, value: &str) -> Option<Address> {
// We attempt to resolve the given string without any additional context of the deployed // We attempt to resolve the given string without any additional context of the deployed
// contracts or the node API as we do not need them. If the resolution fails then we know // contracts or the node API as we do not need them. If the resolution fails then we know
// that this isn't an address and we skip it. // that this isn't an address and we skip it.