From 65a6a846115fcac4143e8fa2107969e29a6a36db 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 | 25 +++++++++++++------ 2 files changed, 28 insertions(+), 8 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..2dd01213a7 100644 --- a/testing/integration/tests/fevm.rs +++ b/testing/integration/tests/fevm.rs @@ -10,7 +10,7 @@ use std::str::FromStr; use cucumber::gherkin::Step; use cucumber::{Parameter, World}; -use ethers::abi::{Detokenize, StateMutability}; +use ethers::abi::Detokenize; use ethers::prelude::builders::ContractCall; use ethers::prelude::decode_function_data; use fvm::executor::ApplyFailure; @@ -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) + } }; }