Skip to content

Commit

Permalink
EVM-IT: Test that nonces are increased even during balance queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jan 20, 2023
1 parent 3c9c9a3 commit 8b5a8fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
11 changes: 11 additions & 0 deletions testing/integration/tests/evm/features/SimpleCoin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 16 additions & 7 deletions testing/integration/tests/fevm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
};
}

Expand Down

0 comments on commit 8b5a8fb

Please sign in to comment.