-
Notifications
You must be signed in to change notification settings - Fork 699
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 emulated tests for the Coretime Interface calls to ensure sufficient weights #2704
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a6e0214
Set up emulated relay chains
seadanda a832140
Add tests scaffolding
seadanda 29951ac
Merge branch 'master' into donal-coretime-tests
seadanda ab0e7ad
Merge branch 'master' into donal-coretime-tests
seadanda 729042b
Add coretime to network
seadanda a7f926a
Tidy up
seadanda 8a6fd0f
Add test for assign_core (WIP)
seadanda 298b3be
Merge branch 'master' into donal-coretime-tests
seadanda 8118ed2
Finalise coretime interface test
seadanda 15e643f
Add coretime-interface test for coretime-westend
seadanda f095c0d
Tidy up unnecessary differences
seadanda db5b579
Taplo
seadanda ebd1078
Merge branch 'master' into donal-coretime-tests
seadanda 85a62ea
Merge branch 'master' into donal-coretime-tests
seadanda c4ab844
Trigger Rococo once more to process the two XCMs separately
seadanda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...rachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...achains/integration-tests/emulated/chains/parachains/coretime/coretime-westend/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 235 additions & 0 deletions
235
...integration-tests/emulated/tests/coretime/coretime-rococo/src/tests/coretime_interface.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::imports::*; | ||
use frame_support::traits::OnInitialize; | ||
use pallet_broker::{ConfigRecord, Configuration, CoreAssignment, CoreMask, ScheduleItem}; | ||
use rococo_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; | ||
use sp_runtime::Perbill; | ||
|
||
#[test] | ||
fn transact_hardcoded_weights_are_sane() { | ||
// There are three transacts with hardcoded weights sent from the Coretime Chain to the Relay | ||
// Chain across the CoretimeInterface which are triggered at various points in the sales cycle. | ||
// - Request core count - triggered directly by `start_sales` or `request_core_count` | ||
// extrinsics. | ||
// - Request revenue info - triggered when each timeslice is committed. | ||
// - Assign core - triggered when an entry is encountered in the workplan for the next | ||
// timeslice. | ||
|
||
// RuntimeEvent aliases to avoid warning from usage of qualified paths in assertions due to | ||
// <https://github.com/rust-lang/rust/issues/86935> | ||
type CoretimeEvent = <CoretimeRococo as Chain>::RuntimeEvent; | ||
type RelayEvent = <Rococo as Chain>::RuntimeEvent; | ||
|
||
// Reserve a workload, configure broker and start sales. | ||
CoretimeRococo::execute_with(|| { | ||
// Hooks don't run in emulated tests - workaround as we need `on_initialize` to tick things | ||
// along and have no concept of time passing otherwise. | ||
<CoretimeRococo as CoretimeRococoPallet>::Broker::on_initialize( | ||
<CoretimeRococo as Chain>::System::block_number(), | ||
); | ||
|
||
let coretime_root_origin = <CoretimeRococo as Chain>::RuntimeOrigin::root(); | ||
|
||
// Create and populate schedule with the worst case assignment on this core. | ||
let mut schedule = Vec::new(); | ||
for i in 0..27 { | ||
schedule.push(ScheduleItem { | ||
mask: CoreMask::void().set(i), | ||
assignment: CoreAssignment::Task(2000 + i), | ||
}) | ||
} | ||
|
||
assert_ok!(<CoretimeRococo as CoretimeRococoPallet>::Broker::reserve( | ||
coretime_root_origin.clone(), | ||
schedule.try_into().expect("Vector is within bounds."), | ||
)); | ||
|
||
// Configure broker and start sales. | ||
let config = ConfigRecord { | ||
advance_notice: 1, | ||
interlude_length: 1, | ||
leadin_length: 2, | ||
region_length: 1, | ||
ideal_bulk_proportion: Perbill::from_percent(40), | ||
limit_cores_offered: None, | ||
renewal_bump: Perbill::from_percent(2), | ||
contribution_timeout: 1, | ||
}; | ||
assert_ok!(<CoretimeRococo as CoretimeRococoPallet>::Broker::configure( | ||
coretime_root_origin.clone(), | ||
config | ||
)); | ||
assert_ok!(<CoretimeRococo as CoretimeRococoPallet>::Broker::start_sales( | ||
coretime_root_origin, | ||
100, | ||
0 | ||
)); | ||
assert_eq!( | ||
pallet_broker::Status::<<CoretimeRococo as Chain>::Runtime>::get() | ||
.unwrap() | ||
.core_count, | ||
1 | ||
); | ||
|
||
assert_expected_events!( | ||
CoretimeRococo, | ||
vec![ | ||
CoretimeEvent::Broker( | ||
pallet_broker::Event::ReservationMade { .. } | ||
) => {}, | ||
CoretimeEvent::Broker( | ||
pallet_broker::Event::CoreCountRequested { core_count: 1 } | ||
) => {}, | ||
CoretimeEvent::ParachainSystem( | ||
cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. } | ||
) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Check that the request_core_count message was processed successfully. This will fail if the | ||
// weights are misconfigured. | ||
Rococo::execute_with(|| { | ||
Rococo::assert_ump_queue_processed(true, Some(CoretimeRococo::para_id()), None); | ||
|
||
assert_expected_events!( | ||
Rococo, | ||
vec![ | ||
RelayEvent::MessageQueue( | ||
pallet_message_queue::Event::Processed { success: true, .. } | ||
) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Keep track of the relay chain block number so we can fast forward while still checking the | ||
// right block. | ||
let mut block_number_cursor = Rococo::ext_wrapper(<Rococo as Chain>::System::block_number); | ||
|
||
let config = CoretimeRococo::ext_wrapper(|| { | ||
Configuration::<<CoretimeRococo as Chain>::Runtime>::get() | ||
.expect("Pallet was configured earlier.") | ||
}); | ||
|
||
// Now run up to the block before the sale is rotated. | ||
while block_number_cursor < TIMESLICE_PERIOD - config.advance_notice - 1 { | ||
CoretimeRococo::execute_with(|| { | ||
// Hooks don't run in emulated tests - workaround. | ||
<CoretimeRococo as CoretimeRococoPallet>::Broker::on_initialize( | ||
<CoretimeRococo as Chain>::System::block_number(), | ||
); | ||
}); | ||
|
||
Rococo::ext_wrapper(|| { | ||
block_number_cursor = <Rococo as Chain>::System::block_number(); | ||
}); | ||
} | ||
|
||
// In this block we trigger assign core. | ||
CoretimeRococo::execute_with(|| { | ||
// Hooks don't run in emulated tests - workaround. | ||
<CoretimeRococo as CoretimeRococoPallet>::Broker::on_initialize( | ||
<CoretimeRococo as Chain>::System::block_number(), | ||
); | ||
|
||
assert_expected_events!( | ||
CoretimeRococo, | ||
vec![ | ||
CoretimeEvent::Broker( | ||
pallet_broker::Event::SaleInitialized { .. } | ||
) => {}, | ||
CoretimeEvent::Broker( | ||
pallet_broker::Event::CoreAssigned { .. } | ||
) => {}, | ||
CoretimeEvent::ParachainSystem( | ||
cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. } | ||
) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Check that the assign_core message was processed successfully. | ||
// This will fail if the weights are misconfigured. | ||
Rococo::execute_with(|| { | ||
Rococo::assert_ump_queue_processed(true, Some(CoretimeRococo::para_id()), None); | ||
|
||
assert_expected_events!( | ||
Rococo, | ||
vec![ | ||
RelayEvent::MessageQueue( | ||
pallet_message_queue::Event::Processed { success: true, .. } | ||
) => {}, | ||
RelayEvent::Coretime( | ||
polkadot_runtime_parachains::coretime::Event::CoreAssigned { .. } | ||
) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// In this block we trigger request revenue. | ||
CoretimeRococo::execute_with(|| { | ||
// Hooks don't run in emulated tests - workaround. | ||
<CoretimeRococo as CoretimeRococoPallet>::Broker::on_initialize( | ||
<CoretimeRococo as Chain>::System::block_number(), | ||
); | ||
|
||
assert_expected_events!( | ||
CoretimeRococo, | ||
vec![ | ||
CoretimeEvent::ParachainSystem( | ||
cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. } | ||
) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Check that the request_revenue_info_at message was processed successfully. | ||
// This will fail if the weights are misconfigured. | ||
Rococo::execute_with(|| { | ||
Rococo::assert_ump_queue_processed(true, Some(CoretimeRococo::para_id()), None); | ||
|
||
assert_expected_events!( | ||
Rococo, | ||
vec![ | ||
RelayEvent::MessageQueue( | ||
pallet_message_queue::Event::Processed { success: true, .. } | ||
) => {}, | ||
] | ||
); | ||
}); | ||
|
||
// Here we receive and process the notify_revenue XCM with zero revenue. | ||
CoretimeRococo::execute_with(|| { | ||
// Hooks don't run in emulated tests - workaround. | ||
<CoretimeRococo as CoretimeRococoPallet>::Broker::on_initialize( | ||
<CoretimeRococo as Chain>::System::block_number(), | ||
); | ||
|
||
assert_expected_events!( | ||
CoretimeRococo, | ||
vec![ | ||
CoretimeEvent::MessageQueue( | ||
pallet_message_queue::Event::Processed { success: true, .. } | ||
) => {}, | ||
// Zero revenue in first timeslice so history is immediately dropped. | ||
CoretimeEvent::Broker( | ||
pallet_broker::Event::HistoryDropped { when: 0, revenue: 0 } | ||
) => {}, | ||
] | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
// limitations under the License. | ||
|
||
mod claim_assets; | ||
mod coretime_interface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder where is the sent event for this processed message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DMP messages don't emit an event like UMP messages when sent. Emulated tests don't get the XcmPallet sent events for some reason.