From e33ef4e8ad656daca238b89a550e5a6ae10ae002 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Sun, 11 Aug 2024 00:41:18 -0700 Subject: [PATCH] Missing Events (#236) * add minter to RegionMinted event * add timeout event * fix * remove unused import --------- Co-authored-by: Szegoo --- pallets/regions/src/lib.rs | 5 +++++ pallets/regions/src/nonfungible_impls.rs | 2 +- pallets/regions/src/tests.rs | 13 +++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index 5c49a5c5..7efa5995 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -157,6 +157,8 @@ pub mod pallet { RegionMinted { /// id of the minted region region_id: RegionId, + /// address of the minter + by: T::AccountId, }, /// A region was burnt. RegionBurnt { @@ -180,6 +182,8 @@ pub mod pallet { /// the account that dropped the region who: T::AccountId, }, + /// Request for a region record timed out. + RequestTimedOut { region_id: RegionId }, } #[pallet::error] @@ -462,6 +466,7 @@ impl IsmpModule for IsmpModuleCallback { region.record = Record::Unavailable; Regions::::insert(region_id, region); + crate::Pallet::::deposit_event(Event::RequestTimedOut { region_id }); Ok(()) }), Timeout::Request(Request::Post(_)) => Ok(()), diff --git a/pallets/regions/src/nonfungible_impls.rs b/pallets/regions/src/nonfungible_impls.rs index bf05d0d7..6ce0e8ea 100644 --- a/pallets/regions/src/nonfungible_impls.rs +++ b/pallets/regions/src/nonfungible_impls.rs @@ -70,7 +70,7 @@ impl Mutate for Pallet { Region { owner: who.clone(), locked: false, record: Record::Unavailable }, ); - Pallet::::deposit_event(Event::RegionMinted { region_id }); + Pallet::::deposit_event(Event::RegionMinted { region_id, by: who.clone() }); log::info!( target: LOG_TARGET, diff --git a/pallets/regions/src/tests.rs b/pallets/regions/src/tests.rs index 616b174d..571a6395 100644 --- a/pallets/regions/src/tests.rs +++ b/pallets/regions/src/tests.rs @@ -41,7 +41,7 @@ fn nonfungibles_implementation_works() { assert!(Regions::regions(®ion_id).is_none()); assert_ok!(Regions::mint_into(®ion_id.into(), &2)); - System::assert_last_event(Event::RegionMinted { region_id }.into()); + System::assert_last_event(Event::RegionMinted { region_id, by: 2u32.into() }.into()); assert_eq!( Regions::regions(®ion_id).unwrap(), Region { owner: 2, locked: false, record: Record::Unavailable } @@ -286,19 +286,15 @@ fn on_timeout_works() { // failed to decode region_id let mut invalid_get_req = get.clone(); - invalid_get_req.keys.push(vec![0u8; 15]); + invalid_get_req.keys = vec![vec![0u8; 15]]; assert_noop!( module.on_timeout(Timeout::Request(Request::Get(invalid_get_req.clone()))), IsmpCustomError::KeyDecodeFailed ); // invalid id: region not found - invalid_get_req.keys.pop(); - if let Some(key) = invalid_get_req.keys.get_mut(0) { - for i in 0..key.len() { - key[i] = key[i].reverse_bits(); - } - } + let non_existing_region = RegionId { begin: 42, core: 72, mask: CoreMask::complete() }; + invalid_get_req.keys = vec![non_existing_region.encode()]; assert_noop!( module.on_timeout(Timeout::Request(Request::Get(invalid_get_req.clone()))), IsmpCustomError::RegionNotFound @@ -314,6 +310,7 @@ fn on_timeout_works() { data: Default::default(), }; assert_ok!(module.on_timeout(Timeout::Request(Request::Post(post.clone())))); + System::assert_last_event(Event::RequestTimedOut { region_id }.into()); assert_ok!(module.on_timeout(Timeout::Response(PostResponse { post,