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 More HRMP Channel Opening Tests #2915

Merged
merged 1 commit into from
Jan 12, 2024
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
63 changes: 62 additions & 1 deletion polkadot/runtime/parachains/src/hrmp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ fn force_open_channel_works() {
register_parachain(para_a);
register_parachain(para_b);

let para_a_free_balance =
<Test as Config>::Currency::free_balance(&para_a.into_account_truncating());
let para_b_free_balance =
<Test as Config>::Currency::free_balance(&para_b.into_account_truncating());

run_to_block(5, Some(vec![4, 5]));
Hrmp::force_open_hrmp_channel(RuntimeOrigin::root(), para_a, para_b, 2, 8).unwrap();
Hrmp::force_open_hrmp_channel(RuntimeOrigin::root(), para_b, para_a, 2, 8).unwrap();
Hrmp::assert_storage_consistency_exhaustive();
assert!(System::events().iter().any(|record| record.event ==
MockEvent::Hrmp(Event::HrmpChannelForceOpened {
Expand All @@ -198,24 +201,82 @@ fn force_open_channel_works() {
proposed_max_capacity: 2,
proposed_max_message_size: 8
})));
assert!(System::events().iter().any(|record| record.event ==
MockEvent::Hrmp(Event::HrmpChannelForceOpened {
sender: para_b,
recipient: para_a,
proposed_max_capacity: 2,
proposed_max_message_size: 8
})));

// Advance to a block 6, but without session change. That means that the channel has
// not been created yet.
run_to_block(6, None);
assert!(!channel_exists(para_a, para_b));
assert!(!channel_exists(para_b, para_a));
Hrmp::assert_storage_consistency_exhaustive();

// Now let the session change happen and thus open the channel.
run_to_block(8, Some(vec![8]));
assert!(channel_exists(para_a, para_b));
// Because para_a is a system chain, para_b's free balance should not have changed.
assert!(channel_exists(para_b, para_a));
// Because para_a is a system chain, their free balances should not have changed.
assert_eq!(
<Test as Config>::Currency::free_balance(&para_a.into_account_truncating()),
para_a_free_balance
);
assert_eq!(
<Test as Config>::Currency::free_balance(&para_b.into_account_truncating()),
para_b_free_balance
);
});
}

#[test]
fn force_open_channel_without_free_balance_works() {
let para_a = 1.into();
let para_b = 2003.into();

new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| {
// We need both A & B to be registered and live parachains, but they should not have any
// balance in their sovereign accounts. Even without any balance, the channel opening should
// still be successful.
register_parachain_with_balance(para_a, 0);
register_parachain_with_balance(para_b, 0);

run_to_block(5, Some(vec![4, 5]));
Hrmp::force_open_hrmp_channel(RuntimeOrigin::root(), para_a, para_b, 2, 8).unwrap();
Hrmp::force_open_hrmp_channel(RuntimeOrigin::root(), para_b, para_a, 2, 8).unwrap();
Hrmp::assert_storage_consistency_exhaustive();
assert!(System::events().iter().any(|record| record.event ==
MockEvent::Hrmp(Event::HrmpChannelForceOpened {
sender: para_a,
recipient: para_b,
proposed_max_capacity: 2,
proposed_max_message_size: 8
})));
assert!(System::events().iter().any(|record| record.event ==
MockEvent::Hrmp(Event::HrmpChannelForceOpened {
sender: para_b,
recipient: para_a,
proposed_max_capacity: 2,
proposed_max_message_size: 8
})));

// Advance to a block 6, but without session change. That means that the channel has
// not been created yet.
run_to_block(6, None);
assert!(!channel_exists(para_a, para_b));
assert!(!channel_exists(para_b, para_a));
Hrmp::assert_storage_consistency_exhaustive();

// Now let the session change happen and thus open the channel.
run_to_block(8, Some(vec![8]));
assert!(channel_exists(para_a, para_b));
assert!(channel_exists(para_b, para_a));
});
}

#[test]
fn force_open_channel_works_with_existing_request() {
let para_a = 2001.into();
Expand Down