From 2d57d1f2441f29431c65b54fac29b04c61325f7a Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Thu, 8 Aug 2024 03:55:24 +0200 Subject: [PATCH 1/3] add new events for regions pallet --- pallets/regions/src/lib.rs | 24 ++++++++++++++++++++++++ pallets/regions/src/nonfungible_impls.rs | 12 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index 3bf90dae..c44200ea 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -129,6 +129,30 @@ 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..eb5af40e 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(()) } } @@ -111,7 +115,10 @@ impl RegionInspect> for Pallet { impl LockableNonFungible for Pallet { fn lock(item: &Self::ItemId, maybe_check_owner: Option) -> DispatchResult { let region_id: RegionId = (*item).into(); - let mut region = Regions::::get(region_id).ok_or(Error::::UnknownRegion)?; + let mut region: Region< + ::AccountId, + <::Currency as Inspect<::AccountId>>::Balance, + > = Regions::::get(region_id).ok_or(Error::::UnknownRegion)?; if let Some(owner) = maybe_check_owner { ensure!(owner.clone() == region.owner, Error::::NotOwner); @@ -121,6 +128,7 @@ impl LockableNonFungible for Pallet { region.locked = true; Regions::::insert(region_id, region); + Pallet::::deposit_event(Event::RegionLocked { region_id }); Ok(()) } @@ -136,6 +144,8 @@ impl LockableNonFungible for Pallet { region.locked = false; Regions::::insert(region_id, region); + Pallet::::deposit_event(Event::RegionUnlocked { region_id }); + Ok(()) } } From 0a51612e1ff7ba5f8b14d050b640bd9bf59ad20f Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Thu, 8 Aug 2024 04:03:51 +0200 Subject: [PATCH 2/3] fix clippy --- pallets/regions/src/nonfungible_impls.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/regions/src/nonfungible_impls.rs b/pallets/regions/src/nonfungible_impls.rs index eb5af40e..bf05d0d7 100644 --- a/pallets/regions/src/nonfungible_impls.rs +++ b/pallets/regions/src/nonfungible_impls.rs @@ -115,10 +115,7 @@ impl RegionInspect> for Pallet { impl LockableNonFungible for Pallet { fn lock(item: &Self::ItemId, maybe_check_owner: Option) -> DispatchResult { let region_id: RegionId = (*item).into(); - let mut region: Region< - ::AccountId, - <::Currency as Inspect<::AccountId>>::Balance, - > = Regions::::get(region_id).ok_or(Error::::UnknownRegion)?; + let mut region = Regions::::get(region_id).ok_or(Error::::UnknownRegion)?; if let Some(owner) = maybe_check_owner { ensure!(owner.clone() == region.owner, Error::::NotOwner); From 414acfa2cc1033d8a9df618cc8289b22f973421c Mon Sep 17 00:00:00 2001 From: Szegoo Date: Thu, 8 Aug 2024 08:17:15 +0200 Subject: [PATCH 3/3] add tests --- pallets/regions/src/lib.rs | 4 ---- pallets/regions/src/tests.rs | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index c44200ea..8f6a3406 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -129,25 +129,21 @@ 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 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 }