Skip to content

Commit

Permalink
Port #2648 to polkadot-staging (#2651)
Browse files Browse the repository at this point in the history
* Deposit event when relayer reward is registered (#2648)

* RewardRegistered event

* test it

* fix compilation
  • Loading branch information
svyatonik authored Oct 27, 2023
1 parent 3896738 commit f7433b0
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion modules/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ pub mod pallet {
rewards_account_params,
new_reward,
);

Self::deposit_event(Event::<T>::RewardRegistered {
relayer: relayer.clone(),
rewards_account_params,
reward,
});
},
);
}
Expand Down Expand Up @@ -369,6 +375,15 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Relayer reward has been registered and may be claimed later.
RewardRegistered {
/// Relayer account that can claim reward.
relayer: T::AccountId,
/// Relayer can claim reward from this account.
rewards_account_params: RewardsAccountParams,
/// Reward amount.
reward: T::Reward,
},
/// Reward has been paid to the relayer.
RewardPaid {
/// Relayer account that has been rewarded.
Expand Down Expand Up @@ -455,7 +470,7 @@ mod tests {
use super::*;
use mock::{RuntimeEvent as TestEvent, *};

use crate::Event::RewardPaid;
use crate::Event::{RewardPaid, RewardRegistered};
use bp_messages::LaneId;
use bp_relayers::RewardsAccountOwner;
use frame_support::{
Expand All @@ -470,6 +485,33 @@ mod tests {
System::<TestRuntime>::reset_events();
}

#[test]
fn register_relayer_reward_emit_event() {
run_test(|| {
get_ready_for_events();

Pallet::<TestRuntime>::register_relayer_reward(
TEST_REWARDS_ACCOUNT_PARAMS,
&REGULAR_RELAYER,
100,
);

// Check if the `RewardRegistered` event was emitted.
assert_eq!(
System::<TestRuntime>::events().last(),
Some(&EventRecord {
phase: Phase::Initialization,
event: TestEvent::Relayers(RewardRegistered {
relayer: REGULAR_RELAYER,
rewards_account_params: TEST_REWARDS_ACCOUNT_PARAMS,
reward: 100
}),
topics: vec![],
}),
);
});
}

#[test]
fn root_cant_claim_anything() {
run_test(|| {
Expand Down

0 comments on commit f7433b0

Please sign in to comment.