Skip to content

Commit

Permalink
Separate check_exit_reason func
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed May 20, 2024
1 parent 0e2e2c5 commit fda0b97
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion evm-tests/ethcore-builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ mod tests {
assert_eq!(b.cost(&[0; 1], 99), U256::from(6_000), "use price #2");
assert_eq!(b.cost(&[0; 1], 100), U256::from(1_337), "use price #3");
assert_eq!(
b.cost(&[0; 1], u64::max_value()),
b.cost(&[0; 1], u64::MAX),
U256::from(1_337),
"use price #3 indefinitely"
);
Expand Down
38 changes: 21 additions & 17 deletions evm-tests/jsontests/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,24 @@ pub fn test(
child.join().unwrap()
}

/// Check Exit Reason of EVM execution
fn check_create_exit_reason(reason: &ExitReason, expect_exception: &Option<String>) -> bool {
if let Some(expect_exception) = expect_exception {
if matches!(reason, ExitReason::Error(ExitError::CreateContractLimit)) {
let exception: &str = expect_exception.as_ref();
let check_result = exception == "TR_InitCodeLimitExceeded"
|| exception == "TransactionException.INITCODE_SIZE_EXCEEDED";
assert!(
check_result,
"message: {exception}\nbut expected init code limit exceeded"
);
return true;
}
}
false
}

#[allow(clippy::cognitive_complexity)]
fn test_run(
verbose_output: &VerboseOutput,
name: &str,
Expand Down Expand Up @@ -566,23 +584,9 @@ fn test_run(
gas_limit,
access_list,
);
if let Some(expect_exception) = state.expect_exception.as_ref() {
match reason.0 {
ExitReason::Error(ref e) => match e {
ExitError::CreateContractLimit => {
// Check error message for EIP-3860
let check_result = matches!(
expect_exception.as_str(),
"TR_InitCodeLimitExceeded"
| "TransactionException.INITCODE_SIZE_EXCEEDED"
);
assert!(check_result, "message: {expect_exception}");
continue;
}
_ => (),
},
_ => (),
}
if check_create_exit_reason(&reason.0, &state.expect_exception) {
println!(" [{:?}] {}:{}", spec, name, i);
continue;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'config> StackSubstateMetadata<'config> {
Ok(())
}

pub fn swallow_discard(&mut self, _other: Self) -> Result<(), ExitError> {
pub fn swallow_discard(&self, _other: Self) -> Result<(), ExitError> {
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/executor/stack/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl<'config> MemoryStackSubstate<'config> {
self.account_mut(address, backend);
}

pub fn get_tstorage(&mut self, address: H160, key: H256) -> U256 {
pub fn get_tstorage(&self, address: H160, key: H256) -> U256 {
self.known_tstorage(address, key).unwrap_or_default()
}

Expand Down

0 comments on commit fda0b97

Please sign in to comment.