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

Confirm the relayer gets paid rewards in unit tests #1081

Merged
merged 1 commit into from
Dec 21, 2023
Merged
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
18 changes: 16 additions & 2 deletions parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use crate::mock::*;
fn test_submit_happy_path() {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
let channel_sovereign = sibling_sovereign_account::<Test>(ASSET_HUB_PARAID.into());

let origin = RuntimeOrigin::signed(relayer.clone());

// Submit message
let message = Message {
Expand All @@ -28,6 +30,11 @@ fn test_submit_happy_path() {
data: Default::default(),
},
};

let initial_fund = InitialFund::get();
assert_eq!(Balances::balance(&relayer), 0);
assert_eq!(Balances::balance(&channel_sovereign), initial_fund);

assert_ok!(InboundQueue::submit(origin.clone(), message.clone()));
expect_events(vec![InboundQueueEvent::MessageReceived {
channel_id: hex!("c173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539")
Expand All @@ -39,6 +46,13 @@ fn test_submit_happy_path() {
],
}
.into()]);

let reward = Parameters::get().rewards.local;
assert!(Balances::balance(&relayer) >= reward, "relayer was rewarded");
assert!(
Balances::balance(&channel_sovereign) <= initial_fund - reward,
"sovereign account paid reward"
);
Comment on lines +50 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let reward = Parameters::get().rewards.local;
assert!(Balances::balance(&relayer) >= reward, "relayer was rewarded");
assert!(
Balances::balance(&channel_sovereign) <= initial_fund - reward,
"sovereign account paid reward"
);
let delivery_cost = InboundQueue::calculate_delivery_cost(message.encode().len() as u32);
assert!(Parameters::get().rewards.local < delivery_cost, "delivery cost exceeds pure reward");
assert_eq!(Balances::balance(&relayer), delivery_cost, "relayer was reimbursed and rewarded");
assert!(
Balances::balance(&channel_sovereign) <= initial_fund - delivery_cost,
"sovereign account paid reward and delivery fee"
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1086

});
}

Expand All @@ -49,7 +63,7 @@ fn test_submit_xcm_invalid_channel() {
let origin = RuntimeOrigin::signed(relayer);

// Deposit funds into sovereign account of parachain 1001
let sovereign_account = sibling_sovereign_account::<Test>(1001u32.into());
let sovereign_account = sibling_sovereign_account::<Test>(TEMPLATE_PARAID.into());
println!("account: {}", sovereign_account);
let _ = Balances::mint_into(&sovereign_account, 10000);

Expand Down
Loading