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

Broker pallet: RegionDropped event fix & additional tests #1609

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add insta pool payout test
  • Loading branch information
Szegoo committed Sep 18, 2023

Verified

This commit was signed with the committer’s verified signature.
xoxys Robert Kaussow
commit 397f17f4954020d6846920435f4868f133fc3948
8 changes: 6 additions & 2 deletions polkadot/xcm/xcm-builder/src/universal_exports.rs
Original file line number Diff line number Diff line change
@@ -171,7 +171,9 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorMulti
let xcm = msg.take().ok_or(MissingArgument)?;

// find exporter
let Some((bridge, maybe_payment)) = Bridges::exporter_for(&remote_network, &remote_location, &xcm) else {
let Some((bridge, maybe_payment)) =
Bridges::exporter_for(&remote_network, &remote_location, &xcm)
else {
// We need to make sure that msg is not consumed in case of `NotApplicable`.
*msg = Some(xcm);
return Err(SendError::NotApplicable)
@@ -236,7 +238,9 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorMulti
let xcm = msg.take().ok_or(MissingArgument)?;

// find exporter
let Some((bridge, maybe_payment)) = Bridges::exporter_for(&remote_network, &remote_location, &xcm) else {
let Some((bridge, maybe_payment)) =
Bridges::exporter_for(&remote_network, &remote_location, &xcm)
else {
// We need to make sure that msg is not consumed in case of `NotApplicable`.
*msg = Some(xcm);
return Err(SendError::NotApplicable)
44 changes: 35 additions & 9 deletions substrate/frame/broker/src/tests.rs
Original file line number Diff line number Diff line change
@@ -38,15 +38,6 @@ fn basic_initialize_works() {
});
}

/*
PERSONAL NOTES:
- Timeslice = 2 relay blocks
- Region length = 3 timeslices, i.e. 6 relay blocks
- Advance notice = 2 relay blocks. This means tasks will be added to the workload
2 blocks before teh start of the bulk period.
- When `do_start_sales` is called the next bulk period starts after a timeslice.
*/

#[test]
fn drop_region_works() {
TestExt::new().endow(1, 1000).execute_with(|| {
@@ -392,6 +383,41 @@ fn instapool_partial_core_payouts_work() {
});
}

#[test]
fn instapool_core_payouts_work_with_partitioned_region() {
TestExt::new().endow(1, 1000).execute_with(|| {
assert_ok!(Broker::do_start_sales(100, 1));
advance_to(2);
let region = Broker::do_purchase(1, u64::max_value()).unwrap();
let (region1, region2) = Broker::do_partition(region, None, 2).unwrap();
// `region1` duration is from rcblock 8 to rcblock 12. This means that the
// coretime purchased during this time period will be purchased from `region1`
//
// `region2` duration is from rcblock 12 to rcblock 14 and during this period
// coretime will be purchased from `region2`.
assert_ok!(Broker::do_pool(region1, None, 2, Final));
assert_ok!(Broker::do_pool(region2, None, 3, Final));
assert_ok!(Broker::do_purchase_credit(1, 20, 1));
advance_to(8);
assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10));
advance_to(11);
assert_eq!(pot(), 20);
assert_eq!(revenue(), 100);
assert_ok!(Broker::do_claim_revenue(region1, 100));
assert_eq!(pot(), 10);
assert_eq!(balance(2), 10);
advance_to(12);
assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10));
advance_to(15);
assert_eq!(pot(), 10);
assert_ok!(Broker::do_claim_revenue(region2, 100));
assert_eq!(pot(), 0);
// The balance of account `2` remains unchanged.
assert_eq!(balance(2), 10);
assert_eq!(balance(3), 10);
});
}

#[test]
fn initialize_with_system_paras_works() {
TestExt::new().execute_with(|| {