From 8b5a8fb254881eab536b80425ae1ba118579dc7e Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Fri, 20 Jan 2023 14:03:15 +0000 Subject: [PATCH] EVM-IT: Test that nonces are increased even during balance queries. --- .../tests/evm/features/SimpleCoin.feature | 11 +++++++++ testing/integration/tests/fevm.rs | 23 +++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/testing/integration/tests/evm/features/SimpleCoin.feature b/testing/integration/tests/evm/features/SimpleCoin.feature index b4202a0cc0..cd7cab1e9b 100644 --- a/testing/integration/tests/evm/features/SimpleCoin.feature +++ b/testing/integration/tests/evm/features/SimpleCoin.feature @@ -29,3 +29,14 @@ Feature: SimpleCoin | 5e969c4ac2f287128d6fd71e7d111dbd19a5b2bea59da5d5d908044a514f5f8e | When account 1 creates a SimpleCoin contract Then account 2 fails to create a SimpleCoin contract with 'Actor sequence invalid: 0 != 1' + + Rule: Nonce increases + + @wip + Scenario: Sending multiple messages to views, the tester and the state stay in sync + Given 1 random account + When account 1 creates a SimpleCoin contract + Then the balance of account 1 is 10000 coins + And the balance of account 1 is 10000 coins + And the balance of account 1 is 10000 coins + And the seqno of account 1 is 4 diff --git a/testing/integration/tests/fevm.rs b/testing/integration/tests/fevm.rs index 768dfcc450..2636533fd1 100644 --- a/testing/integration/tests/fevm.rs +++ b/testing/integration/tests/fevm.rs @@ -208,6 +208,11 @@ impl ContractTester { self.account_mut(acct).account.0 } + /// Get the nonce of an account.` + pub fn account_seqno(&mut self, acct: &AccountNumber) -> u64 { + self.account_mut(acct).seqno + } + /// Deploy a contract owned by an account. pub fn create_contract( &mut self, @@ -282,13 +287,12 @@ impl ContractTester { .expect("too much gas"), ); - // I think the nonce doesn't need to increase for views. Need to check. - match call.function.state_mutability { - StateMutability::View | StateMutability::Pure => {} - _ => { - *self.account_mut(&acct) = account; - } - } + // I think the nonce doesn't need to increase for views, but + // maybe that's just an optimisation by actually using a local node. + // FWIW the system increases the seqno, it doesn't have a special + // relationship with the EVM actor. + // NB `call.function.state_mutability` would tell us. + *self.account_mut(&acct) = account; if !invoke_res.msg_receipt.exit_code.is_success() { return Err(ExecError { @@ -343,6 +347,11 @@ macro_rules! contract_matchers { .expect_err("contract creation should fail"); assert!(format!("{err:?}").contains(&message)) } + + #[then(expr = "the seqno of {acct} is {int}")] + fn check_seqno(world: &mut $world, acct: $crate::AccountNumber, seqno: u64) { + assert_eq!(world.tester.account_seqno(&acct), seqno) + } }; }