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

emit reward in OrderProcessed #247

Merged
merged 4 commits into from
Aug 15, 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
17 changes: 15 additions & 2 deletions pallets/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub use weights::WeightInfo;

const LOG_TARGET: &str = "runtime::order-creator";

pub type BalanceOf<T> =
<<T as crate::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

pub type RegionRecordOf<T> =
RegionRecord<<T as frame_system::Config>::AccountId, <T as crate::Config>::Balance>;

Expand Down Expand Up @@ -118,7 +121,12 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Order got fulfilled with a region which is matching the requirements.
OrderProcessed { order_id: OrderId, region_id: RegionId, seller: T::AccountId },
OrderProcessed {
order_id: OrderId,
region_id: RegionId,
seller: T::AccountId,
reward: BalanceOf<T>,
},
/// Region got successfully assigned to a parachain.
RegionAssigned { region_id: RegionId, para_id: ParaId },
/// Region assignment failed.
Expand Down Expand Up @@ -204,7 +212,12 @@ pub mod pallet {
// remove the order
T::Orders::remove_order(&order_id);

Self::deposit_event(Event::OrderProcessed { order_id, region_id, seller: who });
Self::deposit_event(Event::OrderProcessed {
order_id,
region_id,
seller: who,
reward: amount,
});

// NOTE: If the assignment fails, we don't return an error; instead, we return ok and
// allow anyone to attempt to assign the region.
Expand Down
10 changes: 9 additions & 1 deletion pallets/processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ fn fulfill_order_works() {
// Works with a region that meets the requirements and is unlocked:

Regions::unlock(&region_id.into(), None).unwrap();

assert_eq!(Balances::free_balance(region_owner), 0);
assert_ok!(Processor::fulfill_order(RuntimeOrigin::signed(region_owner), 0, region_id));
// Check events
System::assert_has_event(Event::RegionAssigned { region_id, para_id: 2000.into() }.into());
System::assert_has_event(
Event::OrderProcessed { order_id: 0, region_id, seller: region_owner }.into(),
Event::OrderProcessed {
order_id: 0,
region_id,
seller: region_owner,
reward: 1500u32.into(),
}
.into(),
);

// Ensure order is removed:
Expand Down
Loading