Unverified Commit 30d669d1 authored by Shawn Tabrizi's avatar Shawn Tabrizi Committed by GitHub
Browse files

Check Parachain is Fully Registered Before Starting a Crowdloan (#3018)

* Add check that parachain is fully registered before starting crowdloan

* fix tests

* fix benchmarks
parent 0b1cf10d
Pipeline #138060 passed with stages
in 25 minutes and 40 seconds
...@@ -323,6 +323,7 @@ decl_module! { ...@@ -323,6 +323,7 @@ decl_module! {
let manager = T::Registrar::manager_of(index).ok_or(Error::<T>::InvalidParaId)?; let manager = T::Registrar::manager_of(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(depositor == manager, Error::<T>::InvalidOrigin); ensure!(depositor == manager, Error::<T>::InvalidOrigin);
ensure!(T::Registrar::is_registered(index), Error::<T>::InvalidParaId);
let trie_index = Self::next_trie_index(); let trie_index = Self::next_trie_index();
let new_trie_index = trie_index.checked_add(1).ok_or(Error::<T>::Overflow)?; let new_trie_index = trie_index.checked_add(1).ok_or(Error::<T>::Overflow)?;
...@@ -1644,6 +1645,7 @@ mod benchmarking { ...@@ -1644,6 +1645,7 @@ mod benchmarking {
CurrencyOf::<T>::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); 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)?;
T::Registrar::execute_pending_transitions();
}: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier)) }: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier))
verify { verify {
...@@ -1721,6 +1723,7 @@ mod benchmarking { ...@@ -1721,6 +1723,7 @@ mod benchmarking {
CurrencyOf::<T>::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); 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)?;
T::Registrar::execute_pending_transitions();
Crowdloan::<T>::create( Crowdloan::<T>::create(
RawOrigin::Signed(caller).into(), RawOrigin::Signed(caller).into(),
......
...@@ -570,10 +570,6 @@ fn competing_bids() { ...@@ -570,10 +570,6 @@ fn competing_bids() {
// This test will verify that competing bids, from different sources will resolve appropriately. // This test will verify that competing bids, from different sources will resolve appropriately.
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
assert!(System::block_number().is_one()); assert!(System::block_number().is_one());
// Start a new auction in the future
let duration = 99u32;
let lease_period_index_start = 4u32;
assert_ok!(Auctions::new_auction(Origin::root(), duration, lease_period_index_start));
let start_para = LOWEST_PUBLIC_ID - 1; let start_para = LOWEST_PUBLIC_ID - 1;
// Create 3 paras and owners // Create 3 paras and owners
...@@ -588,7 +584,18 @@ fn competing_bids() { ...@@ -588,7 +584,18 @@ fn competing_bids() {
genesis_head, genesis_head,
validation_code, validation_code,
)); ));
}
// Finish registration of paras.
run_to_session(2);
// Start a new auction in the future
let starting_block = System::block_number();
let duration = 99u32;
let lease_period_index_start = 4u32;
assert_ok!(Auctions::new_auction(Origin::root(), duration, lease_period_index_start));
for n in 1 ..= 3 {
// Create a crowdloan for each para // Create a crowdloan for each para
assert_ok!(Crowdloan::create( assert_ok!(Crowdloan::create(
Origin::signed(n), Origin::signed(n),
...@@ -603,7 +610,7 @@ fn competing_bids() { ...@@ -603,7 +610,7 @@ fn competing_bids() {
for n in 1 ..= 9 { for n in 1 ..= 9 {
// Increment block number // Increment block number
run_to_block(n * 10); run_to_block(starting_block + n * 10);
Balances::make_free_balance_be(&(n * 10), n * 1_000); Balances::make_free_balance_be(&(n * 10), n * 1_000);
...@@ -631,7 +638,7 @@ fn competing_bids() { ...@@ -631,7 +638,7 @@ fn competing_bids() {
} }
// Auction should be done // Auction should be done
run_to_block(110); run_to_block(starting_block + 110);
// Appropriate Paras should have won slots // Appropriate Paras should have won slots
let crowdloan_2 = Crowdloan::fund_account_id(ParaId::from(2001)); let crowdloan_2 = Crowdloan::fund_account_id(ParaId::from(2001));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment