From bc96757ab2583ccb9334ba62ee26c98de41c6e8e Mon Sep 17 00:00:00 2001 From: alnoki <43892045+alnoki@users.noreply.github.com> Date: Sat, 18 Jun 2022 18:20:08 -0700 Subject: [PATCH] Add test-only sequence number mocking, tests Closes: #1504 --- .../aptos-framework/sources/Account.move | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/aptos-move/framework/aptos-framework/sources/Account.move b/aptos-move/framework/aptos-framework/sources/Account.move index 9ca29d2560678..05f2989e85895 100644 --- a/aptos-move/framework/aptos-framework/sources/Account.move +++ b/aptos-move/framework/aptos-framework/sources/Account.move @@ -434,4 +434,43 @@ module AptosFramework::Account { move_to(&resource_account_from_cap, DummyResource { }); borrow_global(Signer::address_of(&resource_account)); } + + /////////////////////////////////////////////////////////////////////////// + // Test-only sequence number mocking for extant Account resource + /////////////////////////////////////////////////////////////////////////// + + #[test_only] + /// Increment sequence number of account at address `addr` + public fun increment_sequence_number( + addr: address, + ) acquires Account { + let acct = borrow_global_mut(addr); + acct.sequence_number = acct.sequence_number + 1; + } + + #[test_only] + /// Update address `addr` to have `s` as its sequence number + public fun set_sequence_number( + addr: address, + s: u64 + ) acquires Account { + borrow_global_mut(addr).sequence_number = s; + } + + #[test] + /// Verify test-only sequence number mocking + public(script) fun mock_sequence_numbers() + acquires Account { + let addr: address = @0x1234; // Define test address + create_account(addr); // Initialize account resource + // Assert sequence number intializes to 0 + assert!(borrow_global(addr).sequence_number == 0, 0); + increment_sequence_number(addr); // Increment sequence number + // Assert correct mock value post-increment + assert!(borrow_global(addr).sequence_number == 1, 1); + set_sequence_number(addr, 10); // Set mock sequence number + // Assert correct mock value post-modification + assert!(borrow_global(addr).sequence_number == 10, 2); + } + }