diff --git a/frame/evm-system/src/lib.rs b/frame/evm-system/src/lib.rs index ecd8c63aa9..b8585ca470 100644 --- a/frame/evm-system/src/lib.rs +++ b/frame/evm-system/src/lib.rs @@ -114,12 +114,15 @@ pub mod pallet { #[pallet::error] pub enum Error { + /// The account already exists in case creating it. AccountAlreadyExist, + /// The account doesn't exist in case removing it. AccountNotExist, } } impl Pallet { + /// Check the account existence. pub fn account_exists(who: &::AccountId) -> bool { FullAccount::::contains_key(who) } @@ -169,11 +172,13 @@ impl Pallet { } } +/// Interface to handle account creation. pub trait OnNewAccount { /// A new account `who` has been registered. fn on_new_account(who: &AccountId); } +/// Interface to handle account killing. pub trait OnKilledAccount { /// The account with the given id was reaped. fn on_killed_account(who: &AccountId); diff --git a/frame/evm-system/src/mock.rs b/frame/evm-system/src/mock.rs index 56c71bf7e6..dea0704fa4 100644 --- a/frame/evm-system/src/mock.rs +++ b/frame/evm-system/src/mock.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Test mock for unit tests and benchmarking. +//! Test mock for unit tests. use frame_support::{ traits::{ConstU32, ConstU64}, diff --git a/frame/evm-system/src/tests.rs b/frame/evm-system/src/tests.rs index 9d73ff0be6..f200ab6284 100644 --- a/frame/evm-system/src/tests.rs +++ b/frame/evm-system/src/tests.rs @@ -18,6 +18,9 @@ fn create_account_works() { // Check test preconditions. assert!(!EvmSystem::account_exists(&account_id)); + // Set block number to enable events. + System::set_block_number(1); + // Set mock expectations. let on_new_account_ctx = MockDummyOnNewAccount::on_new_account_context(); on_new_account_ctx @@ -33,6 +36,7 @@ fn create_account_works() { // Assert state changes. assert!(EvmSystem::account_exists(&account_id)); + System::assert_has_event(RuntimeEvent::EvmSystem(Event::NewAccount { account: account_id } )); // Assert mock invocations. on_new_account_ctx.checkpoint(); @@ -60,6 +64,9 @@ fn remove_account_works() { let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap(); >::insert(account_id.clone(), AccountInfo::<_, _>::default()); + // Set block number to enable events. + System::set_block_number(1); + // Set mock expectations. let on_killed_account_ctx = MockDummyOnKilledAccount::on_killed_account_context(); on_killed_account_ctx @@ -73,6 +80,10 @@ fn remove_account_works() { // Invoke the function under test. assert_ok!(EvmSystem::remove_account(&account_id)); + // Assert state changes. + assert!(!EvmSystem::account_exists(&account_id)); + System::assert_has_event(RuntimeEvent::EvmSystem(Event::KilledAccount { account: account_id } )); + // Assert mock invocations. on_killed_account_ctx.checkpoint(); });