Skip to content

Commit

Permalink
add new events for regions pallet (#230)
Browse files Browse the repository at this point in the history
* add new events for regions pallet

* fix clippy

* add tests

---------

Co-authored-by: Szegoo <[email protected]>
  • Loading branch information
cuteolaf and Szegoo authored Aug 8, 2024
1 parent b99b5c7 commit f5cb824
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions pallets/regions/src/nonfungible_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl<T: Config> Mutate<T::AccountId> for Pallet<T> {
Region { owner: who.clone(), locked: false, record: Record::Unavailable },
);

Pallet::<T>::deposit_event(Event::RegionMinted { region_id });

log::info!(
target: LOG_TARGET,
"Minted region: {:?}",
Expand All @@ -90,6 +92,8 @@ impl<T: Config> Mutate<T::AccountId> for Pallet<T> {

Regions::<T>::remove(region_id);

Pallet::<T>::deposit_event(Event::RegionBurnt { region_id });

Ok(())
}
}
Expand Down Expand Up @@ -121,6 +125,7 @@ impl<T: Config> LockableNonFungible<T::AccountId> for Pallet<T> {
region.locked = true;
Regions::<T>::insert(region_id, region);

Pallet::<T>::deposit_event(Event::RegionLocked { region_id });
Ok(())
}

Expand All @@ -136,6 +141,8 @@ impl<T: Config> LockableNonFungible<T::AccountId> for Pallet<T> {
region.locked = false;
Regions::<T>::insert(region_id, region);

Pallet::<T>::deposit_event(Event::RegionUnlocked { region_id });

Ok(())
}
}
5 changes: 5 additions & 0 deletions pallets/regions/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn nonfungibles_implementation_works() {

assert!(Regions::regions(&region_id).is_none());
assert_ok!(Regions::mint_into(&region_id.into(), &2));
System::assert_last_event(Event::RegionMinted { region_id }.into());
assert_eq!(
Regions::regions(&region_id).unwrap(),
Region { owner: 2, locked: false, record: Record::Unavailable }
Expand All @@ -55,6 +56,7 @@ fn nonfungibles_implementation_works() {
assert_noop!(Regions::burn(&region_id.into(), Some(&1)), Error::<Test>::NotOwner);

assert_ok!(Regions::burn(&region_id.into(), Some(&2)));
System::assert_last_event(Event::RegionBurnt { region_id }.into());
assert!(Regions::regions(&region_id).is_none());

assert_noop!(Regions::burn(&region_id.into(), None), Error::<Test>::UnknownRegion);
Expand Down Expand Up @@ -427,6 +429,7 @@ fn region_locking_works() {
assert_noop!(Regions::lock(&region_id.into(), Some(2)), Error::<Test>::NotOwner);

assert_ok!(Regions::lock(&region_id.into(), Some(1)));
System::assert_last_event(Event::RegionLocked { region_id }.into());
assert_eq!(
Regions::regions(&region_id).unwrap(),
Region { owner: 1, locked: true, record: Record::Unavailable }
Expand Down Expand Up @@ -461,6 +464,7 @@ fn region_unlocking_works() {
assert_noop!(Regions::unlock(&region_id.into(), Some(1)), Error::<Test>::RegionNotLocked);

assert_ok!(Regions::lock(&region_id.into(), Some(1)));
System::assert_last_event(Event::RegionLocked { region_id }.into());
assert_eq!(
Regions::regions(&region_id).unwrap(),
Region { owner: 1, locked: true, record: Record::Unavailable }
Expand All @@ -470,6 +474,7 @@ fn region_unlocking_works() {
assert_noop!(Regions::unlock(&region_id.into(), Some(2)), Error::<Test>::NotOwner);

assert_ok!(Regions::unlock(&region_id.into(), Some(1)));
System::assert_last_event(Event::RegionUnlocked { region_id }.into());
assert_eq!(
Regions::regions(&region_id).unwrap(),
Region { owner: 1, locked: false, record: Record::Unavailable }
Expand Down

0 comments on commit f5cb824

Please sign in to comment.