Skip to content

Commit

Permalink
Bytes -> Vec<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Apr 5, 2024
1 parent 7758823 commit e9e7e4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
1 change: 0 additions & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
msrv = "1.76"
ignore-interior-mutability = ["bytes::Bytes", "alloy_primitives::Bytes"]
35 changes: 22 additions & 13 deletions crates/cheatcodes/src/test/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const DUMMY_CREATE_ADDRESS: Address = address!("00000000000000000000000000000000
/// This then allows us to customize the matching behavior for each call data on the
/// `ExpectedCallData` struct and track how many times we've actually seen the call on the second
/// element of the tuple.
pub type ExpectedCallTracker = HashMap<Address, HashMap<Bytes, (ExpectedCallData, u64)>>;
pub type ExpectedCallTracker = HashMap<Address, HashMap<Vec<u8>, (ExpectedCallData, u64)>>;

#[derive(Clone, Debug)]
pub struct ExpectedCallData {
Expand Down Expand Up @@ -98,21 +98,30 @@ pub struct ExpectedEmit {
impl Cheatcode for expectCall_0Call {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self { callee, data } = self;
expect_call(state, callee, data, None, None, None, 1, ExpectedCallType::NonCount)
expect_call(state, callee, data.to_vec(), None, None, None, 1, ExpectedCallType::NonCount)
}
}

impl Cheatcode for expectCall_1Call {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self { callee, data, count } = self;
expect_call(state, callee, data, None, None, None, *count, ExpectedCallType::Count)
expect_call(state, callee, data.to_vec(), None, None, None, *count, ExpectedCallType::Count)
}
}

impl Cheatcode for expectCall_2Call {
fn apply(&self, state: &mut Cheatcodes) -> Result {
let Self { callee, msgValue, data } = self;
expect_call(state, callee, data, Some(msgValue), None, None, 1, ExpectedCallType::NonCount)
expect_call(
state,
callee,
data.to_vec(),
Some(msgValue),
None,
None,
1,
ExpectedCallType::NonCount,
)
}
}

Expand All @@ -122,7 +131,7 @@ impl Cheatcode for expectCall_3Call {
expect_call(
state,
callee,
data,
data.to_vec(),
Some(msgValue),
None,
None,
Expand All @@ -138,7 +147,7 @@ impl Cheatcode for expectCall_4Call {
expect_call(
state,
callee,
data,
data.to_vec(),
Some(msgValue),
Some(*gas),
None,
Expand All @@ -154,7 +163,7 @@ impl Cheatcode for expectCall_5Call {
expect_call(
state,
callee,
data,
data.to_vec(),
Some(msgValue),
Some(*gas),
None,
Expand All @@ -170,7 +179,7 @@ impl Cheatcode for expectCallMinGas_0Call {
expect_call(
state,
callee,
data,
data.to_vec(),
Some(msgValue),
None,
Some(*minGas),
Expand All @@ -186,7 +195,7 @@ impl Cheatcode for expectCallMinGas_1Call {
expect_call(
state,
callee,
data,
data.to_vec(),
Some(msgValue),
None,
Some(*minGas),
Expand Down Expand Up @@ -318,7 +327,7 @@ impl Cheatcode for expectSafeMemoryCallCall {
fn expect_call(
state: &mut Cheatcodes,
target: &Address,
calldata: &Bytes,
calldata: Vec<u8>,
value: Option<&U256>,
mut gas: Option<u64>,
mut min_gas: Option<u64>,
Expand Down Expand Up @@ -347,18 +356,18 @@ fn expect_call(
// In this case, as we're using counted expectCalls, we should not be able to set them
// more than once.
ensure!(
!expecteds.contains_key(calldata),
!expecteds.contains_key(&calldata),
"counted expected calls can only bet set once"
);
expecteds.insert(
calldata.clone(),
calldata,
(ExpectedCallData { value: value.copied(), gas, min_gas, count, call_type }, 0),
);
}
ExpectedCallType::NonCount => {
// Check if the expected calldata exists.
// If it does, increment the count by one as we expect to see it one more time.
match expecteds.entry(calldata.clone()) {
match expecteds.entry(calldata) {
Entry::Occupied(mut entry) => {
let (expected, _) = entry.get_mut();
// Ensure we're not overwriting a counted expectCall.
Expand Down

0 comments on commit e9e7e4f

Please sign in to comment.