mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-17 19:25:41 +00:00
paras: dismiss pvf_checking_enabled configuration (#7138)
* paras: unconditionally precheck pvfs * Update integration tests * paras_registrar tests * runtime benchmark tests * fix bench * bypass prechecking in test node * adjust bench * ".git/.scripts/commands/bench/bench.sh" runtime polkadot runtime_parachains::paras * ".git/.scripts/commands/bench/bench.sh" runtime kusama runtime_parachains::paras * ".git/.scripts/commands/bench/bench.sh" runtime rococo runtime_parachains::paras * ".git/.scripts/commands/bench/bench.sh" runtime westend runtime_parachains::paras * use test helper * fix new test --------- Co-authored-by: command-bot <>
This commit is contained in:
@@ -1731,8 +1731,12 @@ mod tests {
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking {
|
||||
use super::{Pallet as Auctions, *};
|
||||
use frame_support::traits::{EnsureOrigin, OnInitialize};
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
traits::{EnsureOrigin, OnInitialize},
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
use runtime_parachains::paras;
|
||||
use sp_runtime::{traits::Bounded, SaturatedConversion};
|
||||
|
||||
use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError};
|
||||
@@ -1745,7 +1749,7 @@ mod benchmarking {
|
||||
assert_eq!(event, &system_event);
|
||||
}
|
||||
|
||||
fn fill_winners<T: Config>(lease_period_index: LeasePeriodOf<T>) {
|
||||
fn fill_winners<T: Config + paras::Config>(lease_period_index: LeasePeriodOf<T>) {
|
||||
let auction_index = AuctionCounter::<T>::get();
|
||||
let minimum_balance = CurrencyOf::<T>::minimum_balance();
|
||||
|
||||
@@ -1763,6 +1767,10 @@ mod benchmarking {
|
||||
)
|
||||
.is_ok());
|
||||
}
|
||||
assert_ok!(paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
T::Registrar::worst_validation_code(),
|
||||
));
|
||||
|
||||
T::Registrar::execute_pending_transitions();
|
||||
|
||||
@@ -1786,7 +1794,7 @@ mod benchmarking {
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
where_clause { where T: pallet_babe::Config }
|
||||
where_clause { where T: pallet_babe::Config + paras::Config }
|
||||
|
||||
new_auction {
|
||||
let duration = T::BlockNumber::max_value();
|
||||
@@ -1824,7 +1832,12 @@ mod benchmarking {
|
||||
let worst_head_data = T::Registrar::worst_head_data();
|
||||
let worst_validation_code = T::Registrar::worst_validation_code();
|
||||
T::Registrar::register(owner.clone(), para, worst_head_data.clone(), worst_validation_code.clone())?;
|
||||
T::Registrar::register(owner, new_para, worst_head_data, worst_validation_code)?;
|
||||
T::Registrar::register(owner, new_para, worst_head_data, worst_validation_code.clone())?;
|
||||
assert_ok!(paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
worst_validation_code,
|
||||
));
|
||||
|
||||
T::Registrar::execute_pending_transitions();
|
||||
|
||||
// Make an existing bid
|
||||
|
||||
@@ -1953,6 +1953,7 @@ mod benchmarking {
|
||||
use super::{Pallet as Crowdloan, *};
|
||||
use frame_support::{assert_ok, traits::OnInitialize};
|
||||
use frame_system::RawOrigin;
|
||||
use runtime_parachains::paras;
|
||||
use sp_core::crypto::UncheckedFrom;
|
||||
use sp_runtime::traits::{Bounded, CheckedSub};
|
||||
use sp_std::prelude::*;
|
||||
@@ -1967,7 +1968,7 @@ mod benchmarking {
|
||||
assert_eq!(event, &system_event);
|
||||
}
|
||||
|
||||
fn create_fund<T: Config>(id: u32, end: T::BlockNumber) -> ParaId {
|
||||
fn create_fund<T: Config + paras::Config>(id: u32, end: T::BlockNumber) -> ParaId {
|
||||
let cap = BalanceOf::<T>::max_value();
|
||||
let (_, offset) = T::Auctioneer::lease_period_length();
|
||||
// Set to the very beginning of lease period index 0.
|
||||
@@ -1987,7 +1988,16 @@ mod benchmarking {
|
||||
|
||||
let head_data = T::Registrar::worst_head_data();
|
||||
let validation_code = T::Registrar::worst_validation_code();
|
||||
assert_ok!(T::Registrar::register(caller.clone(), para_id, head_data, validation_code));
|
||||
assert_ok!(T::Registrar::register(
|
||||
caller.clone(),
|
||||
para_id,
|
||||
head_data,
|
||||
validation_code.clone()
|
||||
));
|
||||
assert_ok!(paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
validation_code,
|
||||
));
|
||||
T::Registrar::execute_pending_transitions();
|
||||
|
||||
assert_ok!(Crowdloan::<T>::create(
|
||||
@@ -2020,6 +2030,8 @@ mod benchmarking {
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
where_clause { where T: paras::Config }
|
||||
|
||||
create {
|
||||
let para_id = ParaId::from(1_u32);
|
||||
let cap = BalanceOf::<T>::max_value();
|
||||
@@ -2035,7 +2047,12 @@ mod benchmarking {
|
||||
let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0));
|
||||
|
||||
CurrencyOf::<T>::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
T::Registrar::register(caller.clone(), para_id, head_data, validation_code)?;
|
||||
T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?;
|
||||
assert_ok!(paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
validation_code,
|
||||
));
|
||||
|
||||
T::Registrar::execute_pending_transitions();
|
||||
|
||||
}: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier))
|
||||
@@ -2123,7 +2140,12 @@ mod benchmarking {
|
||||
let verifier = MultiSigner::unchecked_from(account::<[u8; 32]>("verifier", 0, 0));
|
||||
|
||||
CurrencyOf::<T>::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
T::Registrar::register(caller.clone(), para_id, head_data, validation_code)?;
|
||||
T::Registrar::register(caller.clone(), para_id, head_data, validation_code.clone())?;
|
||||
assert_ok!(paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
validation_code,
|
||||
));
|
||||
|
||||
T::Registrar::execute_pending_transitions();
|
||||
|
||||
Crowdloan::<T>::create(
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
//! Mocking utilities for testing with real pallets.
|
||||
|
||||
use crate::{
|
||||
auctions, crowdloan, paras_registrar,
|
||||
auctions, crowdloan,
|
||||
mock::{conclude_pvf_checking, validators_public_keys},
|
||||
paras_registrar,
|
||||
slot_range::SlotRange,
|
||||
slots,
|
||||
traits::{AuctionStatus, Auctioneer, Leaser, Registrar as RegistrarT},
|
||||
@@ -31,12 +33,15 @@ use frame_support::{
|
||||
use frame_support_test::TestRandomness;
|
||||
use frame_system::EnsureRoot;
|
||||
use parity_scale_codec::Encode;
|
||||
use primitives::{BlockNumber, HeadData, Header, Id as ParaId, ValidationCode, LOWEST_PUBLIC_ID};
|
||||
use primitives::{
|
||||
BlockNumber, HeadData, Header, Id as ParaId, SessionIndex, ValidationCode, LOWEST_PUBLIC_ID,
|
||||
};
|
||||
use runtime_parachains::{
|
||||
configuration, origin, paras, shared, Origin as ParaOrigin, ParaLifecycle,
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_io::TestExternalities;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentityLookup, One},
|
||||
@@ -298,9 +303,21 @@ pub fn new_test_ext_with_offset(n: BlockNumber) -> TestExternalities {
|
||||
|
||||
const BLOCKS_PER_SESSION: u32 = 10;
|
||||
|
||||
const VALIDATORS: &[Sr25519Keyring] = &[
|
||||
Sr25519Keyring::Alice,
|
||||
Sr25519Keyring::Bob,
|
||||
Sr25519Keyring::Charlie,
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
|
||||
fn maybe_new_session(n: u32) {
|
||||
if n % BLOCKS_PER_SESSION == 0 {
|
||||
shared::Pallet::<Test>::set_session_index(shared::Pallet::<Test>::session_index() + 1);
|
||||
let session_index = shared::Pallet::<Test>::session_index() + 1;
|
||||
let validators_pub_keys = validators_public_keys(VALIDATORS);
|
||||
|
||||
shared::Pallet::<Test>::set_session_index(session_index);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validators_pub_keys);
|
||||
Paras::test_on_new_session();
|
||||
}
|
||||
}
|
||||
@@ -357,6 +374,10 @@ fn basic_end_to_end_works() {
|
||||
let para_1 = LOWEST_PUBLIC_ID;
|
||||
let para_2 = LOWEST_PUBLIC_ID + 1;
|
||||
assert!(System::block_number().is_one());
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
let start_block = System::block_number();
|
||||
|
||||
// User 1 and 2 will own parachains
|
||||
Balances::make_free_balance_be(&account_id(1), 1_000_000_000);
|
||||
Balances::make_free_balance_be(&account_id(2), 1_000_000_000);
|
||||
@@ -370,6 +391,7 @@ fn basic_end_to_end_works() {
|
||||
genesis_head.clone(),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
assert_ok!(Registrar::reserve(signed(2)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(2),
|
||||
@@ -392,7 +414,7 @@ fn basic_end_to_end_works() {
|
||||
));
|
||||
|
||||
// 2 sessions later they are parathreads
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(para_1)), Some(ParaLifecycle::Parathread));
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(para_2)), Some(ParaLifecycle::Parathread));
|
||||
|
||||
@@ -411,7 +433,7 @@ fn basic_end_to_end_works() {
|
||||
let crowdloan_account = Crowdloan::fund_account_id(fund_2.fund_index);
|
||||
|
||||
// Auction ending begins on block 100 + offset, so we make a bid before then.
|
||||
run_to_block(90 + offset);
|
||||
run_to_block(start_block + 90 + offset);
|
||||
|
||||
Balances::make_free_balance_be(&account_id(10), 1_000_000_000);
|
||||
Balances::make_free_balance_be(&account_id(20), 1_000_000_000);
|
||||
@@ -431,7 +453,7 @@ fn basic_end_to_end_works() {
|
||||
assert_ok!(Crowdloan::contribute(signed(2), ParaId::from(para_2), 920, None));
|
||||
|
||||
// Auction ends at block 110 + offset
|
||||
run_to_block(109 + offset);
|
||||
run_to_block(start_block + 109 + offset);
|
||||
assert!(contains_event(
|
||||
crowdloan::Event::<Test>::HandleBidResult {
|
||||
para_id: ParaId::from(para_2),
|
||||
@@ -439,7 +461,7 @@ fn basic_end_to_end_works() {
|
||||
}
|
||||
.into()
|
||||
));
|
||||
run_to_block(110 + offset);
|
||||
run_to_block(start_block + 110 + offset);
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
auctions::Event::<Test>::AuctionClosed { auction_index: 1 }.into()
|
||||
@@ -473,7 +495,7 @@ fn basic_end_to_end_works() {
|
||||
);
|
||||
|
||||
// New leases will start on block 400
|
||||
let lease_start_block = 400 + offset;
|
||||
let lease_start_block = start_block + 400 + offset;
|
||||
run_to_block(lease_start_block);
|
||||
|
||||
// First slot, Para 1 should be transitioning to Parachain
|
||||
@@ -587,19 +609,24 @@ fn competing_slots() {
|
||||
let max_bids = 10u32;
|
||||
let para_id = LOWEST_PUBLIC_ID;
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// Create n paras and owners
|
||||
let validation_code = Registrar::worst_validation_code();
|
||||
for n in 1..=max_bids {
|
||||
Balances::make_free_balance_be(&account_id(n), 1_000_000_000);
|
||||
let genesis_head = Registrar::worst_head_data();
|
||||
let validation_code = Registrar::worst_validation_code();
|
||||
assert_ok!(Registrar::reserve(signed(n)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(n),
|
||||
para_id + n - 1,
|
||||
genesis_head,
|
||||
validation_code,
|
||||
validation_code.clone(),
|
||||
));
|
||||
}
|
||||
// The code undergoing the prechecking is the same for all paras.
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Start a new auction in the future
|
||||
let duration = 149u32;
|
||||
@@ -611,7 +638,7 @@ fn competing_slots() {
|
||||
));
|
||||
|
||||
// Paras should be onboarded
|
||||
run_to_block(20); // session 2
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
|
||||
for n in 1..=max_bids {
|
||||
// Increment block number
|
||||
@@ -645,7 +672,7 @@ fn competing_slots() {
|
||||
}
|
||||
|
||||
// Auction should be done after ending period
|
||||
run_to_block(160);
|
||||
run_to_block(180);
|
||||
|
||||
// Appropriate Paras should have won slots
|
||||
// 900 + 4500 + 2x 8100 = 21,600
|
||||
@@ -683,23 +710,28 @@ fn competing_bids() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one());
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
let start_para = LOWEST_PUBLIC_ID - 1;
|
||||
// Create 3 paras and owners
|
||||
let validation_code = Registrar::worst_validation_code();
|
||||
for n in 1..=3 {
|
||||
Balances::make_free_balance_be(&account_id(n), 1_000_000_000);
|
||||
let genesis_head = Registrar::worst_head_data();
|
||||
let validation_code = Registrar::worst_validation_code();
|
||||
assert_ok!(Registrar::reserve(signed(n)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(n),
|
||||
ParaId::from(start_para + n),
|
||||
genesis_head,
|
||||
validation_code,
|
||||
validation_code.clone(),
|
||||
));
|
||||
}
|
||||
// The code undergoing the prechecking is the same for all paras.
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Finish registration of paras.
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
|
||||
// Start a new auction in the future
|
||||
let starting_block = System::block_number();
|
||||
@@ -785,24 +817,33 @@ fn basic_swap_works() {
|
||||
// This test will test a swap between a parachain and parathread works successfully.
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one()); /* So events are emitted */
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// User 1 and 2 will own paras
|
||||
Balances::make_free_balance_be(&account_id(1), 1_000_000_000);
|
||||
Balances::make_free_balance_be(&account_id(2), 1_000_000_000);
|
||||
// First register 2 parathreads with different data
|
||||
let validation_code = test_validation_code(10);
|
||||
assert_ok!(Registrar::reserve(signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(1),
|
||||
ParaId::from(2000),
|
||||
test_genesis_head(10),
|
||||
test_validation_code(10),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
let validation_code = test_validation_code(20);
|
||||
assert_ok!(Registrar::reserve(signed(2)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(2),
|
||||
ParaId::from(2001),
|
||||
test_genesis_head(20),
|
||||
test_validation_code(20),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Paras should be onboarding
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding));
|
||||
@@ -818,7 +859,7 @@ fn basic_swap_works() {
|
||||
));
|
||||
|
||||
// 2 sessions later they are parathreads
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Parathread));
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(2001)), Some(ParaLifecycle::Parathread));
|
||||
|
||||
@@ -938,24 +979,33 @@ fn parachain_swap_works() {
|
||||
// This test will test a swap between two parachains works successfully.
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one()); /* So events are emitted */
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// User 1 and 2 will own paras
|
||||
Balances::make_free_balance_be(&account_id(1), 1_000_000_000);
|
||||
Balances::make_free_balance_be(&account_id(2), 1_000_000_000);
|
||||
// First register 2 parathreads with different data
|
||||
let validation_code = test_validation_code(10);
|
||||
assert_ok!(Registrar::reserve(signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(1),
|
||||
ParaId::from(2000),
|
||||
test_genesis_head(10),
|
||||
test_validation_code(10),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
let validation_code = test_validation_code(20);
|
||||
assert_ok!(Registrar::reserve(signed(2)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(2),
|
||||
ParaId::from(2001),
|
||||
test_genesis_head(20),
|
||||
test_validation_code(20),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Paras should be onboarding
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding));
|
||||
@@ -1107,24 +1157,34 @@ fn parachain_swap_works() {
|
||||
fn crowdloan_ending_period_bid() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one()); /* So events are emitted */
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// User 1 and 2 will own paras
|
||||
Balances::make_free_balance_be(&account_id(1), 1_000_000_000);
|
||||
Balances::make_free_balance_be(&account_id(2), 1_000_000_000);
|
||||
|
||||
// First register 2 parathreads
|
||||
let validation_code = test_validation_code(10);
|
||||
assert_ok!(Registrar::reserve(signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(1),
|
||||
ParaId::from(2000),
|
||||
test_genesis_head(10),
|
||||
test_validation_code(10),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
let validation_code = test_validation_code(20);
|
||||
assert_ok!(Registrar::reserve(signed(2)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(2),
|
||||
ParaId::from(2001),
|
||||
test_genesis_head(20),
|
||||
test_validation_code(20),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Paras should be onboarding
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Onboarding));
|
||||
@@ -1132,6 +1192,7 @@ fn crowdloan_ending_period_bid() {
|
||||
|
||||
// Start a new auction in the future
|
||||
let duration = 99u32;
|
||||
let ends_at = System::block_number() + duration;
|
||||
let lease_period_index_start = 4u32;
|
||||
assert_ok!(Auctions::new_auction(
|
||||
RuntimeOrigin::root(),
|
||||
@@ -1140,7 +1201,7 @@ fn crowdloan_ending_period_bid() {
|
||||
));
|
||||
|
||||
// 2 sessions later they are parathreads
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(2000)), Some(ParaLifecycle::Parathread));
|
||||
assert_eq!(Paras::lifecycle(ParaId::from(2001)), Some(ParaLifecycle::Parathread));
|
||||
|
||||
@@ -1179,9 +1240,9 @@ fn crowdloan_ending_period_bid() {
|
||||
));
|
||||
|
||||
// Go to beginning of ending period
|
||||
run_to_block(100);
|
||||
run_to_block(ends_at);
|
||||
|
||||
assert_eq!(Auctions::auction_status(100), AuctionStatus::<u32>::EndingPeriod(0, 0));
|
||||
assert_eq!(Auctions::auction_status(ends_at), AuctionStatus::<u32>::EndingPeriod(0, 0));
|
||||
let mut winning = [(); SlotRange::SLOT_RANGE_COUNT].map(|_| None);
|
||||
|
||||
winning[SlotRange::ZeroOne as u8 as usize] = Some((account_id(2), ParaId::from(2001), 900));
|
||||
@@ -1190,13 +1251,13 @@ fn crowdloan_ending_period_bid() {
|
||||
|
||||
assert_eq!(Auctions::winning(0), Some(winning));
|
||||
|
||||
run_to_block(101);
|
||||
run_to_block(ends_at + 1);
|
||||
|
||||
Balances::make_free_balance_be(&account_id(1234), 1_000_000_000);
|
||||
assert_ok!(Crowdloan::contribute(signed(1234), ParaId::from(2000), 900, None));
|
||||
|
||||
// Data propagates correctly
|
||||
run_to_block(102);
|
||||
run_to_block(ends_at + 2);
|
||||
let mut winning = [(); SlotRange::SLOT_RANGE_COUNT].map(|_| None);
|
||||
winning[SlotRange::ZeroOne as u8 as usize] = Some((account_id(2), ParaId::from(2001), 900));
|
||||
winning[SlotRange::ZeroThree as u8 as usize] =
|
||||
@@ -1210,6 +1271,9 @@ fn auction_bid_requires_registered_para() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one()); /* So events are emitted */
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// Start a new auction in the future
|
||||
let duration = 99u32;
|
||||
let lease_period_index_start = 4u32;
|
||||
@@ -1234,13 +1298,15 @@ fn auction_bid_requires_registered_para() {
|
||||
);
|
||||
|
||||
// Now we register the para
|
||||
let validation_code = test_validation_code(10);
|
||||
assert_ok!(Registrar::reserve(signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(1),
|
||||
ParaId::from(2000),
|
||||
test_genesis_head(10),
|
||||
test_validation_code(10),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Still can't bid until it is fully onboarded
|
||||
assert_noop!(
|
||||
@@ -1256,7 +1322,7 @@ fn auction_bid_requires_registered_para() {
|
||||
);
|
||||
|
||||
// Onboarded on Session 2
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
|
||||
// Success
|
||||
Balances::make_free_balance_be(&account_id(1), 1_000_000_000);
|
||||
@@ -1276,6 +1342,9 @@ fn gap_bids_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one()); /* So events are emitted */
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// Start a new auction in the future
|
||||
let duration = 99u32;
|
||||
let lease_period_index_start = 4u32;
|
||||
@@ -1288,23 +1357,25 @@ fn gap_bids_work() {
|
||||
Balances::make_free_balance_be(&account_id(2), 1_000_000_000);
|
||||
|
||||
// Now register 2 paras
|
||||
let validation_code = test_validation_code(10);
|
||||
assert_ok!(Registrar::reserve(signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(1),
|
||||
ParaId::from(2000),
|
||||
test_genesis_head(10),
|
||||
test_validation_code(10),
|
||||
validation_code.clone(),
|
||||
));
|
||||
assert_ok!(Registrar::reserve(signed(2)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(2),
|
||||
ParaId::from(2001),
|
||||
test_genesis_head(10),
|
||||
test_validation_code(10),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Onboarded on Session 2
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
|
||||
// Make bids
|
||||
Balances::make_free_balance_be(&account_id(10), 1_000_000_000);
|
||||
@@ -1359,7 +1430,7 @@ fn gap_bids_work() {
|
||||
));
|
||||
|
||||
// Finish the auction
|
||||
run_to_block(110 + LeaseOffset::get());
|
||||
run_to_block(130 + LeaseOffset::get());
|
||||
|
||||
// Should have won the lease periods
|
||||
assert_eq!(
|
||||
@@ -1457,15 +1528,21 @@ fn gap_bids_work() {
|
||||
fn cant_bid_on_existing_lease_periods() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one()); /* So events are emitted */
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
Balances::make_free_balance_be(&account_id(1), 1_000_000_000);
|
||||
// First register a parathread
|
||||
let validation_code = test_validation_code(10);
|
||||
assert_ok!(Registrar::reserve(signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
signed(1),
|
||||
ParaId::from(2000),
|
||||
test_genesis_head(10),
|
||||
test_validation_code(10),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Start a new auction in the future
|
||||
let starting_block = System::block_number();
|
||||
@@ -1478,7 +1555,7 @@ fn cant_bid_on_existing_lease_periods() {
|
||||
));
|
||||
|
||||
// 2 sessions later they are parathreads
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
|
||||
// Open a crowdloan for Para 1 for slots 0-3
|
||||
assert_ok!(Crowdloan::create(
|
||||
|
||||
@@ -22,7 +22,9 @@ use frame_support::{
|
||||
weights::Weight,
|
||||
};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use primitives::{HeadData, Id as ParaId, ValidationCode};
|
||||
use primitives::{HeadData, Id as ParaId, PvfCheckStatement, SessionIndex, ValidationCode};
|
||||
use runtime_parachains::paras;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_runtime::{traits::SaturatedConversion, Permill};
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
||||
@@ -231,3 +233,30 @@ impl frame_support::traits::EstimateNextSessionRotation<u32> for TestNextSession
|
||||
(None, Weight::zero())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validators_public_keys(validators: &[Sr25519Keyring]) -> Vec<primitives::ValidatorId> {
|
||||
validators.iter().map(|v| v.public().into()).collect()
|
||||
}
|
||||
|
||||
pub fn conclude_pvf_checking<T: paras::Config>(
|
||||
validation_code: &ValidationCode,
|
||||
validators: &[Sr25519Keyring],
|
||||
session_index: SessionIndex,
|
||||
) {
|
||||
let num_required = primitives::supermajority_threshold(validators.len());
|
||||
validators.iter().enumerate().take(num_required).for_each(|(idx, key)| {
|
||||
let validator_index = idx as u32;
|
||||
let statement = PvfCheckStatement {
|
||||
accept: true,
|
||||
subject: validation_code.hash(),
|
||||
session_index,
|
||||
validator_index: validator_index.into(),
|
||||
};
|
||||
let signature = key.sign(&statement.signing_payload());
|
||||
let _ = paras::Pallet::<T>::include_pvf_check_statement(
|
||||
frame_system::Origin::<T>::None.into(),
|
||||
statement,
|
||||
signature.into(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -655,7 +655,9 @@ impl<T: Config> Pallet<T> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{paras_registrar, traits::Registrar as RegistrarTrait};
|
||||
use crate::{
|
||||
mock::conclude_pvf_checking, paras_registrar, traits::Registrar as RegistrarTrait,
|
||||
};
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok,
|
||||
error::BadOrigin,
|
||||
@@ -664,10 +666,11 @@ mod tests {
|
||||
};
|
||||
use frame_system::limits;
|
||||
use pallet_balances::Error as BalancesError;
|
||||
use primitives::{Balance, BlockNumber, Header};
|
||||
use primitives::{Balance, BlockNumber, Header, SessionIndex};
|
||||
use runtime_parachains::{configuration, origin, shared};
|
||||
use sp_core::H256;
|
||||
use sp_io::TestExternalities;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
transaction_validity::TransactionPriority,
|
||||
@@ -835,6 +838,14 @@ mod tests {
|
||||
|
||||
const BLOCKS_PER_SESSION: u32 = 3;
|
||||
|
||||
const VALIDATORS: &[Sr25519Keyring] = &[
|
||||
Sr25519Keyring::Alice,
|
||||
Sr25519Keyring::Bob,
|
||||
Sr25519Keyring::Charlie,
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
|
||||
fn run_to_block(n: BlockNumber) {
|
||||
// NOTE that this function only simulates modules of interest. Depending on new pallet may
|
||||
// require adding it here.
|
||||
@@ -847,9 +858,12 @@ mod tests {
|
||||
}
|
||||
// Session change every 3 blocks.
|
||||
if (b + 1) % BLOCKS_PER_SESSION == 0 {
|
||||
shared::Pallet::<Test>::set_session_index(
|
||||
shared::Pallet::<Test>::session_index() + 1,
|
||||
);
|
||||
let session_index = shared::Pallet::<Test>::session_index() + 1;
|
||||
let validators_pub_keys = VALIDATORS.iter().map(|v| v.public().into()).collect();
|
||||
|
||||
shared::Pallet::<Test>::set_session_index(session_index);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validators_pub_keys);
|
||||
|
||||
Parachains::test_on_new_session();
|
||||
}
|
||||
System::set_block_number(b + 1);
|
||||
@@ -895,35 +909,41 @@ mod tests {
|
||||
fn end_to_end_scenario_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let para_id = LOWEST_PUBLIC_ID;
|
||||
run_to_block(1);
|
||||
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// first para is not yet registered
|
||||
assert!(!Parachains::is_parathread(para_id));
|
||||
// We register the Para ID
|
||||
let validation_code = test_validation_code(32);
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(1),
|
||||
para_id,
|
||||
test_genesis_head(32),
|
||||
test_validation_code(32),
|
||||
validation_code.clone(),
|
||||
));
|
||||
run_to_session(2);
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
// It is now a parathread.
|
||||
assert!(Parachains::is_parathread(para_id));
|
||||
assert!(!Parachains::is_parachain(para_id));
|
||||
// Some other external process will elevate parathread to parachain
|
||||
assert_ok!(Registrar::make_parachain(para_id));
|
||||
run_to_session(4);
|
||||
run_to_session(START_SESSION_INDEX + 4);
|
||||
// It is now a parachain.
|
||||
assert!(!Parachains::is_parathread(para_id));
|
||||
assert!(Parachains::is_parachain(para_id));
|
||||
// Turn it back into a parathread
|
||||
assert_ok!(Registrar::make_parathread(para_id));
|
||||
run_to_session(6);
|
||||
run_to_session(START_SESSION_INDEX + 6);
|
||||
assert!(Parachains::is_parathread(para_id));
|
||||
assert!(!Parachains::is_parachain(para_id));
|
||||
// Deregister it
|
||||
assert_ok!(Registrar::deregister(RuntimeOrigin::root(), para_id,));
|
||||
run_to_session(8);
|
||||
run_to_session(START_SESSION_INDEX + 8);
|
||||
// It is nothing
|
||||
assert!(!Parachains::is_parathread(para_id));
|
||||
assert!(!Parachains::is_parachain(para_id));
|
||||
@@ -933,18 +953,24 @@ mod tests {
|
||||
#[test]
|
||||
fn register_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
let para_id = LOWEST_PUBLIC_ID;
|
||||
assert!(!Parachains::is_parathread(para_id));
|
||||
|
||||
let validation_code = test_validation_code(32);
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1)));
|
||||
assert_eq!(Balances::reserved_balance(&1), <Test as Config>::ParaDeposit::get());
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(1),
|
||||
para_id,
|
||||
test_genesis_head(32),
|
||||
test_validation_code(32),
|
||||
validation_code.clone(),
|
||||
));
|
||||
run_to_session(2);
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
assert!(Parachains::is_parathread(para_id));
|
||||
assert_eq!(
|
||||
Balances::reserved_balance(&1),
|
||||
@@ -988,7 +1014,7 @@ mod tests {
|
||||
test_genesis_head(max_head_size() as usize),
|
||||
test_validation_code(max_code_size() as usize),
|
||||
));
|
||||
|
||||
// Can skip pre-check and deregister para which's still onboarding.
|
||||
run_to_session(2);
|
||||
|
||||
assert_ok!(Registrar::deregister(RuntimeOrigin::root(), para_id));
|
||||
@@ -1038,20 +1064,26 @@ mod tests {
|
||||
#[test]
|
||||
fn deregister_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
let para_id = LOWEST_PUBLIC_ID;
|
||||
assert!(!Parachains::is_parathread(para_id));
|
||||
|
||||
let validation_code = test_validation_code(32);
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(1),
|
||||
para_id,
|
||||
test_genesis_head(32),
|
||||
test_validation_code(32),
|
||||
validation_code.clone(),
|
||||
));
|
||||
run_to_session(2);
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
assert!(Parachains::is_parathread(para_id));
|
||||
assert_ok!(Registrar::deregister(RuntimeOrigin::root(), para_id,));
|
||||
run_to_session(4);
|
||||
run_to_session(START_SESSION_INDEX + 4);
|
||||
assert!(paras::Pallet::<Test>::lifecycle(para_id).is_none());
|
||||
assert_eq!(Balances::reserved_balance(&1), 0);
|
||||
});
|
||||
@@ -1060,22 +1092,28 @@ mod tests {
|
||||
#[test]
|
||||
fn deregister_handles_basic_errors() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
let para_id = LOWEST_PUBLIC_ID;
|
||||
assert!(!Parachains::is_parathread(para_id));
|
||||
|
||||
let validation_code = test_validation_code(32);
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(1),
|
||||
para_id,
|
||||
test_genesis_head(32),
|
||||
test_validation_code(32),
|
||||
validation_code.clone(),
|
||||
));
|
||||
run_to_session(2);
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
assert!(Parachains::is_parathread(para_id));
|
||||
// Owner check
|
||||
assert_noop!(Registrar::deregister(RuntimeOrigin::signed(2), para_id,), BadOrigin);
|
||||
assert_ok!(Registrar::make_parachain(para_id));
|
||||
run_to_session(4);
|
||||
run_to_session(START_SESSION_INDEX + 4);
|
||||
// Cant directly deregister parachain
|
||||
assert_noop!(
|
||||
Registrar::deregister(RuntimeOrigin::root(), para_id,),
|
||||
@@ -1087,24 +1125,31 @@ mod tests {
|
||||
#[test]
|
||||
fn swap_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
// Successfully register first two parachains
|
||||
let para_1 = LOWEST_PUBLIC_ID;
|
||||
let para_2 = LOWEST_PUBLIC_ID + 1;
|
||||
|
||||
let validation_code = test_validation_code(max_code_size() as usize);
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(1),
|
||||
para_1,
|
||||
test_genesis_head(max_head_size() as usize),
|
||||
test_validation_code(max_code_size() as usize),
|
||||
validation_code.clone(),
|
||||
));
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(2),
|
||||
para_2,
|
||||
test_genesis_head(max_head_size() as usize),
|
||||
test_validation_code(max_code_size() as usize),
|
||||
validation_code.clone(),
|
||||
));
|
||||
run_to_session(2);
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
|
||||
// Upgrade para 1 into a parachain
|
||||
assert_ok!(Registrar::make_parachain(para_1));
|
||||
@@ -1115,7 +1160,7 @@ mod tests {
|
||||
swap_data.insert(para_2, 1337);
|
||||
SwapData::set(swap_data);
|
||||
|
||||
run_to_session(4);
|
||||
run_to_session(START_SESSION_INDEX + 4);
|
||||
|
||||
// Roles are as we expect
|
||||
assert!(Parachains::is_parachain(para_1));
|
||||
@@ -1132,7 +1177,7 @@ mod tests {
|
||||
other_id: para_1,
|
||||
}));
|
||||
|
||||
run_to_session(6);
|
||||
run_to_session(START_SESSION_INDEX + 6);
|
||||
|
||||
// Roles are swapped
|
||||
assert!(!Parachains::is_parachain(para_1));
|
||||
@@ -1159,15 +1204,17 @@ mod tests {
|
||||
|
||||
// Parachain to parachain swap
|
||||
let para_3 = LOWEST_PUBLIC_ID + 2;
|
||||
let validation_code = test_validation_code(max_code_size() as usize);
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(3)));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(3),
|
||||
para_3,
|
||||
test_genesis_head(max_head_size() as usize),
|
||||
test_validation_code(max_code_size() as usize),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX + 6);
|
||||
|
||||
run_to_session(8);
|
||||
run_to_session(START_SESSION_INDEX + 8);
|
||||
|
||||
// Upgrade para 3 into a parachain
|
||||
assert_ok!(Registrar::make_parachain(para_3));
|
||||
@@ -1177,7 +1224,7 @@ mod tests {
|
||||
swap_data.insert(para_3, 777);
|
||||
SwapData::set(swap_data);
|
||||
|
||||
run_to_session(10);
|
||||
run_to_session(START_SESSION_INDEX + 10);
|
||||
|
||||
// Both are parachains
|
||||
assert!(Parachains::is_parachain(para_3));
|
||||
@@ -1234,9 +1281,12 @@ mod tests {
|
||||
#[test]
|
||||
fn swap_handles_bad_states() {
|
||||
new_test_ext().execute_with(|| {
|
||||
const START_SESSION_INDEX: SessionIndex = 1;
|
||||
run_to_session(START_SESSION_INDEX);
|
||||
|
||||
let para_1 = LOWEST_PUBLIC_ID;
|
||||
let para_2 = LOWEST_PUBLIC_ID + 1;
|
||||
run_to_block(1);
|
||||
|
||||
// paras are not yet registered
|
||||
assert!(!Parachains::is_parathread(para_1));
|
||||
assert!(!Parachains::is_parathread(para_2));
|
||||
@@ -1248,20 +1298,22 @@ mod tests {
|
||||
);
|
||||
|
||||
// We register Paras 1 and 2
|
||||
let validation_code = test_validation_code(32);
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(1)));
|
||||
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(2)));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(1),
|
||||
para_1,
|
||||
test_genesis_head(32),
|
||||
test_validation_code(32),
|
||||
validation_code.clone(),
|
||||
));
|
||||
assert_ok!(Registrar::register(
|
||||
RuntimeOrigin::signed(2),
|
||||
para_2,
|
||||
test_genesis_head(32),
|
||||
test_validation_code(32),
|
||||
validation_code.clone(),
|
||||
));
|
||||
conclude_pvf_checking::<Test>(&validation_code, VALIDATORS, START_SESSION_INDEX);
|
||||
|
||||
// Cannot swap
|
||||
assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2));
|
||||
@@ -1270,7 +1322,7 @@ mod tests {
|
||||
Error::<Test>::CannotSwap
|
||||
);
|
||||
|
||||
run_to_session(2);
|
||||
run_to_session(START_SESSION_INDEX + 2);
|
||||
|
||||
// They are now a parathread.
|
||||
assert!(Parachains::is_parathread(para_1));
|
||||
@@ -1293,7 +1345,7 @@ mod tests {
|
||||
Error::<Test>::CannotSwap
|
||||
);
|
||||
|
||||
run_to_session(3);
|
||||
run_to_session(START_SESSION_INDEX + 3);
|
||||
|
||||
// Cannot swap
|
||||
assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2));
|
||||
@@ -1302,7 +1354,7 @@ mod tests {
|
||||
Error::<Test>::CannotSwap
|
||||
);
|
||||
|
||||
run_to_session(4);
|
||||
run_to_session(START_SESSION_INDEX + 4);
|
||||
|
||||
// It is now a parachain.
|
||||
assert!(Parachains::is_parachain(para_1));
|
||||
@@ -1316,7 +1368,7 @@ mod tests {
|
||||
RuntimeEvent::Registrar(paras_registrar::Event::Swapped { .. })
|
||||
)));
|
||||
|
||||
run_to_session(5);
|
||||
run_to_session(START_SESSION_INDEX + 5);
|
||||
|
||||
// Cannot swap
|
||||
assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2));
|
||||
@@ -1325,7 +1377,7 @@ mod tests {
|
||||
Error::<Test>::CannotSwap
|
||||
);
|
||||
|
||||
run_to_session(6);
|
||||
run_to_session(START_SESSION_INDEX + 6);
|
||||
|
||||
// Swap worked!
|
||||
assert!(Parachains::is_parachain(para_2));
|
||||
@@ -1338,7 +1390,7 @@ mod tests {
|
||||
// Something starts to downgrade a para
|
||||
assert_ok!(Registrar::make_parathread(para_2));
|
||||
|
||||
run_to_session(7);
|
||||
run_to_session(START_SESSION_INDEX + 7);
|
||||
|
||||
// Cannot swap
|
||||
assert_ok!(Registrar::swap(RuntimeOrigin::root(), para_1, para_2));
|
||||
@@ -1347,7 +1399,7 @@ mod tests {
|
||||
Error::<Test>::CannotSwap
|
||||
);
|
||||
|
||||
run_to_session(8);
|
||||
run_to_session(START_SESSION_INDEX + 8);
|
||||
|
||||
assert!(Parachains::is_parathread(para_1));
|
||||
assert!(Parachains::is_parathread(para_2));
|
||||
@@ -1386,7 +1438,11 @@ mod benchmarking {
|
||||
RawOrigin::Signed(caller).into(),
|
||||
para,
|
||||
genesis_head,
|
||||
validation_code
|
||||
validation_code.clone()
|
||||
));
|
||||
assert_ok!(runtime_parachains::paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
validation_code,
|
||||
));
|
||||
return para
|
||||
}
|
||||
@@ -1421,10 +1477,14 @@ mod benchmarking {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
assert_ok!(Registrar::<T>::reserve(RawOrigin::Signed(caller.clone()).into()));
|
||||
}: _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code)
|
||||
}: _(RawOrigin::Signed(caller.clone()), para, genesis_head, validation_code.clone())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::<T>::Registered{ para_id: para, manager: caller }.into());
|
||||
assert_eq!(paras::Pallet::<T>::lifecycle(para), Some(ParaLifecycle::Onboarding));
|
||||
assert_ok!(runtime_parachains::paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
validation_code,
|
||||
));
|
||||
next_scheduled_session::<T>();
|
||||
assert_eq!(paras::Pallet::<T>::lifecycle(para), Some(ParaLifecycle::Parathread));
|
||||
}
|
||||
@@ -1435,10 +1495,14 @@ mod benchmarking {
|
||||
let para = ParaId::from(69);
|
||||
let genesis_head = Registrar::<T>::worst_head_data();
|
||||
let validation_code = Registrar::<T>::worst_validation_code();
|
||||
}: _(RawOrigin::Root, manager.clone(), deposit, para, genesis_head, validation_code)
|
||||
}: _(RawOrigin::Root, manager.clone(), deposit, para, genesis_head, validation_code.clone())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::<T>::Registered { para_id: para, manager }.into());
|
||||
assert_eq!(paras::Pallet::<T>::lifecycle(para), Some(ParaLifecycle::Onboarding));
|
||||
assert_ok!(runtime_parachains::paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
validation_code,
|
||||
));
|
||||
next_scheduled_session::<T>();
|
||||
assert_eq!(paras::Pallet::<T>::lifecycle(para), Some(ParaLifecycle::Parathread));
|
||||
}
|
||||
|
||||
@@ -988,6 +988,7 @@ mod benchmarking {
|
||||
use super::*;
|
||||
use frame_support::assert_ok;
|
||||
use frame_system::RawOrigin;
|
||||
use runtime_parachains::paras;
|
||||
use sp_runtime::traits::{Bounded, One};
|
||||
|
||||
use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError};
|
||||
@@ -1002,7 +1003,7 @@ mod benchmarking {
|
||||
assert_eq!(event, &system_event);
|
||||
}
|
||||
|
||||
fn register_a_parathread<T: Config>(i: u32) -> (ParaId, T::AccountId) {
|
||||
fn register_a_parathread<T: Config + paras::Config>(i: u32) -> (ParaId, T::AccountId) {
|
||||
let para = ParaId::from(i);
|
||||
let leaser: T::AccountId = account("leaser", i, 0);
|
||||
T::Currency::make_free_balance_be(&leaser, BalanceOf::<T>::max_value());
|
||||
@@ -1013,14 +1014,21 @@ mod benchmarking {
|
||||
leaser.clone(),
|
||||
para,
|
||||
worst_head_data,
|
||||
worst_validation_code
|
||||
worst_validation_code.clone(),
|
||||
));
|
||||
assert_ok!(paras::Pallet::<T>::add_trusted_validation_code(
|
||||
frame_system::Origin::<T>::Root.into(),
|
||||
worst_validation_code,
|
||||
));
|
||||
|
||||
T::Registrar::execute_pending_transitions();
|
||||
|
||||
(para, leaser)
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
where_clause { where T: paras::Config }
|
||||
|
||||
force_lease {
|
||||
// If there is an offset, we need to be on that block to be able to do lease things.
|
||||
frame_system::Pallet::<T>::set_block_number(T::LeaseOffset::get() + One::one());
|
||||
|
||||
Reference in New Issue
Block a user