From f5cb824868dfb5862a9b4c6e6e0b698df3963edb Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Wed, 7 Aug 2024 23:42:46 -0700 Subject: [PATCH] add new events for regions pallet (#230) * add new events for regions pallet * fix clippy * add tests --------- Co-authored-by: Szegoo --- pallets/regions/src/lib.rs | 20 ++++++++++++++++++++ pallets/regions/src/nonfungible_impls.rs | 7 +++++++ pallets/regions/src/tests.rs | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index 201692f8..fefb4880 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -137,6 +137,26 @@ pub mod pallet { /// The ismp get request commitment. request_commitment: H256, }, + /// A region was minted via a cross chain transfer. + RegionMinted { + /// minted region id + region_id: RegionId, + }, + /// A region was burnt. + RegionBurnt { + /// burnt region id + region_id: RegionId, + }, + /// A region was locked. + RegionLocked { + /// locked region id + region_id: RegionId, + }, + /// A region was unlocked. + RegionUnlocked { + /// unlocked region id + region_id: RegionId, + }, } #[pallet::error] diff --git a/pallets/regions/src/nonfungible_impls.rs b/pallets/regions/src/nonfungible_impls.rs index 02d2fbf6..bf05d0d7 100644 --- a/pallets/regions/src/nonfungible_impls.rs +++ b/pallets/regions/src/nonfungible_impls.rs @@ -70,6 +70,8 @@ impl Mutate for Pallet { Region { owner: who.clone(), locked: false, record: Record::Unavailable }, ); + Pallet::::deposit_event(Event::RegionMinted { region_id }); + log::info!( target: LOG_TARGET, "Minted region: {:?}", @@ -90,6 +92,8 @@ impl Mutate for Pallet { Regions::::remove(region_id); + Pallet::::deposit_event(Event::RegionBurnt { region_id }); + Ok(()) } } @@ -121,6 +125,7 @@ impl LockableNonFungible for Pallet { region.locked = true; Regions::::insert(region_id, region); + Pallet::::deposit_event(Event::RegionLocked { region_id }); Ok(()) } @@ -136,6 +141,8 @@ impl LockableNonFungible for Pallet { region.locked = false; Regions::::insert(region_id, region); + Pallet::::deposit_event(Event::RegionUnlocked { region_id }); + Ok(()) } } diff --git a/pallets/regions/src/tests.rs b/pallets/regions/src/tests.rs index 0d5da3db..d4d460e1 100644 --- a/pallets/regions/src/tests.rs +++ b/pallets/regions/src/tests.rs @@ -41,6 +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()); assert_eq!( Regions::regions(®ion_id).unwrap(), Region { owner: 2, locked: false, record: Record::Unavailable } @@ -55,6 +56,7 @@ fn nonfungibles_implementation_works() { assert_noop!(Regions::burn(®ion_id.into(), Some(&1)), Error::::NotOwner); assert_ok!(Regions::burn(®ion_id.into(), Some(&2))); + System::assert_last_event(Event::RegionBurnt { region_id }.into()); assert!(Regions::regions(®ion_id).is_none()); assert_noop!(Regions::burn(®ion_id.into(), None), Error::::UnknownRegion); @@ -427,6 +429,7 @@ fn region_locking_works() { assert_noop!(Regions::lock(®ion_id.into(), Some(2)), Error::::NotOwner); assert_ok!(Regions::lock(®ion_id.into(), Some(1))); + System::assert_last_event(Event::RegionLocked { region_id }.into()); assert_eq!( Regions::regions(®ion_id).unwrap(), Region { owner: 1, locked: true, record: Record::Unavailable } @@ -461,6 +464,7 @@ fn region_unlocking_works() { assert_noop!(Regions::unlock(®ion_id.into(), Some(1)), Error::::RegionNotLocked); assert_ok!(Regions::lock(®ion_id.into(), Some(1))); + System::assert_last_event(Event::RegionLocked { region_id }.into()); assert_eq!( Regions::regions(®ion_id).unwrap(), Region { owner: 1, locked: true, record: Record::Unavailable } @@ -470,6 +474,7 @@ fn region_unlocking_works() { assert_noop!(Regions::unlock(®ion_id.into(), Some(2)), Error::::NotOwner); assert_ok!(Regions::unlock(®ion_id.into(), Some(1))); + System::assert_last_event(Event::RegionUnlocked { region_id }.into()); assert_eq!( Regions::regions(®ion_id).unwrap(), Region { owner: 1, locked: false, record: Record::Unavailable }