Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new events for regions pallet #230

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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
Loading