Skip to content

Commit

Permalink
Missing Events (#236)
Browse files Browse the repository at this point in the history
* add minter to RegionMinted event

* add timeout event

* fix

* remove unused import

---------

Co-authored-by: Szegoo <sakacszergej@gmail.com>
  • Loading branch information
cuteolaf and Szegoo authored Aug 11, 2024
1 parent d233b41 commit e33ef4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]
Expand Down Expand Up @@ -462,6 +466,7 @@ impl<T: Config> IsmpModule for IsmpModuleCallback<T> {
region.record = Record::Unavailable;
Regions::<T>::insert(region_id, region);

crate::Pallet::<T>::deposit_event(Event::RequestTimedOut { region_id });
Ok(())
}),
Timeout::Request(Request::Post(_)) => Ok(()),
Expand Down
2 changes: 1 addition & 1 deletion pallets/regions/src/nonfungible_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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 });
Pallet::<T>::deposit_event(Event::RegionMinted { region_id, by: who.clone() });

log::info!(
target: LOG_TARGET,
Expand Down
13 changes: 5 additions & 8 deletions pallets/regions/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +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());
System::assert_last_event(Event::RegionMinted { region_id, by: 2u32.into() }.into());
assert_eq!(
Regions::regions(&region_id).unwrap(),
Region { owner: 2, locked: false, record: Record::Unavailable }
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit e33ef4e

Please sign in to comment.