Skip to content

Commit df46793

Browse files
authored
test(op-revm): Adds caller nonce assertion to op-revm intergation tests (#2815)
* Adds handler test for verifying unchanged nonce on balance too low revert * Fix system call test * fixup! Fix merge conflicts
1 parent f2d73c4 commit df46793

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

crates/ee-tests/src/op_revm_tests.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,11 +1134,9 @@ fn test_system_call() {
11341134

11351135
let mut evm = ctx.build_op();
11361136

1137-
evm.system_call_one(SYSTEM_ADDRESS, BENCH_TARGET, bytes!("0x0001"))
1138-
.unwrap();
1139-
1140-
// Run evm.
1141-
let output = evm.replay().unwrap();
1137+
let _ = evm.system_call_one(SYSTEM_ADDRESS, BENCH_TARGET, bytes!("0x0001"));
1138+
let state = evm.finalize();
11421139

1143-
compare_or_save_op_testdata("test_system_call.json", &output);
1140+
assert!(state.get(&SYSTEM_ADDRESS).is_none());
1141+
assert!(state.get(&BENCH_TARGET).unwrap().is_touched());
11441142
}

crates/op-revm/src/handler.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,4 +1109,37 @@ mod tests {
11091109
let account = evm.ctx().journal_mut().load_account(SENDER).unwrap();
11101110
assert_eq!(account.info.balance, expected_refund);
11111111
}
1112+
1113+
#[test]
1114+
fn test_tx_low_balance_nonce_unchanged() {
1115+
let ctx = Context::op().with_tx(
1116+
OpTransaction::builder()
1117+
.base(TxEnv::builder().value(U256::from(1000)))
1118+
.build_fill(),
1119+
);
1120+
1121+
let mut evm = ctx.build_op();
1122+
1123+
let handler =
1124+
OpHandler::<_, EVMError<_, OpTransactionError>, EthFrame<EthInterpreter>>::new();
1125+
1126+
let result = handler.validate_against_state_and_deduct_caller(&mut evm);
1127+
1128+
assert!(matches!(
1129+
result.err().unwrap(),
1130+
EVMError::Transaction(OpTransactionError::Base(
1131+
InvalidTransaction::LackOfFundForMaxFee { .. }
1132+
))
1133+
));
1134+
assert_eq!(
1135+
evm.0
1136+
.ctx
1137+
.journal_mut()
1138+
.load_account(Address::ZERO)
1139+
.unwrap()
1140+
.info
1141+
.nonce,
1142+
0
1143+
);
1144+
}
11121145
}

0 commit comments

Comments
 (0)