diff --git a/node/src/chain_spec/dancebox.rs b/node/src/chain_spec/dancebox.rs index 58b96306a..e5a82e21f 100644 --- a/node/src/chain_spec/dancebox.rs +++ b/node/src/chain_spec/dancebox.rs @@ -216,7 +216,7 @@ fn testnet_genesis( .collect(); let para_ids: Vec<_> = para_ids .into_iter() - .map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data)) + .map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data, None)) .collect(); let accounts_with_ed = [ diff --git a/node/src/chain_spec/flashbox.rs b/node/src/chain_spec/flashbox.rs index d45323f1b..2e69c6c5c 100644 --- a/node/src/chain_spec/flashbox.rs +++ b/node/src/chain_spec/flashbox.rs @@ -217,7 +217,7 @@ fn testnet_genesis( let para_ids: Vec<_> = para_ids .into_iter() - .map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data)) + .map(|(para_id, genesis_data, _boot_nodes)| (para_id, genesis_data, None)) .collect(); let accounts_with_ed = [ diff --git a/pallets/registrar/src/lib.rs b/pallets/registrar/src/lib.rs index d77950eda..eb0452b9a 100644 --- a/pallets/registrar/src/lib.rs +++ b/pallets/registrar/src/lib.rs @@ -81,7 +81,11 @@ pub mod pallet { #[derive(DefaultNoBound)] pub struct GenesisConfig { /// Para ids - pub para_ids: Vec<(ParaId, ContainerChainGenesisData)>, + pub para_ids: Vec<( + ParaId, + ContainerChainGenesisData, + Option, + )>, pub phantom: PhantomData, } @@ -102,7 +106,7 @@ pub mod pallet { let mut bounded_para_ids = BoundedVec::default(); - for (para_id, genesis_data) in para_ids { + for (para_id, genesis_data, parathread_params) in para_ids { bounded_para_ids .try_push(*para_id) .expect("too many para ids in genesis: bounded vec full"); @@ -117,6 +121,10 @@ pub mod pallet { ); } >::insert(para_id, genesis_data); + + if let Some(parathread_params) = parathread_params { + >::insert(para_id, parathread_params); + } } >::put(bounded_para_ids); diff --git a/pallets/registrar/src/mock.rs b/pallets/registrar/src/mock.rs index f3ded871d..0b58df6ab 100644 --- a/pallets/registrar/src/mock.rs +++ b/pallets/registrar/src/mock.rs @@ -15,7 +15,7 @@ // along with Tanssi. If not, see use { - crate::{self as pallet_registrar, RegistrarHooks}, + crate::{self as pallet_registrar, ParathreadParamsTy, RegistrarHooks}, dp_container_chain_genesis_data::ContainerChainGenesisData, frame_support::{ traits::{ConstU16, ConstU64}, @@ -311,7 +311,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities { // Build genesis storage according to the mock runtime. pub fn new_test_ext_with_genesis( - para_ids: Vec<(ParaId, ContainerChainGenesisData)>, + para_ids: Vec<( + ParaId, + ContainerChainGenesisData, + Option, + )>, ) -> sp_io::TestExternalities { RuntimeGenesisConfig { system: Default::default(), diff --git a/pallets/registrar/src/tests.rs b/pallets/registrar/src/tests.rs index 84b92a5da..bf4fccecc 100644 --- a/pallets/registrar/src/tests.rs +++ b/pallets/registrar/src/tests.rs @@ -539,10 +539,10 @@ fn unpause_para_id_42_fails_not_registered() { #[test] fn genesis_loads_para_ids() { new_test_ext_with_genesis(vec![ - (1.into(), empty_genesis_data()), - (2.into(), empty_genesis_data()), - (3.into(), empty_genesis_data()), - (4.into(), empty_genesis_data()), + (1.into(), empty_genesis_data(), None), + (2.into(), empty_genesis_data(), None), + (3.into(), empty_genesis_data(), None), + (4.into(), empty_genesis_data(), None), ]) .execute_with(|| { run_to_block(1); @@ -556,10 +556,10 @@ fn genesis_loads_para_ids() { #[test] fn genesis_sorts_para_ids() { new_test_ext_with_genesis(vec![ - (4.into(), empty_genesis_data()), - (2.into(), empty_genesis_data()), - (3.into(), empty_genesis_data()), - (1.into(), empty_genesis_data()), + (4.into(), empty_genesis_data(), None), + (2.into(), empty_genesis_data(), None), + (3.into(), empty_genesis_data(), None), + (1.into(), empty_genesis_data(), None), ]) .execute_with(|| { run_to_block(1); @@ -574,10 +574,10 @@ fn genesis_sorts_para_ids() { #[should_panic = "Duplicate para_id: 2"] fn genesis_error_on_duplicate() { new_test_ext_with_genesis(vec![ - (2.into(), empty_genesis_data()), - (3.into(), empty_genesis_data()), - (4.into(), empty_genesis_data()), - (2.into(), empty_genesis_data()), + (2.into(), empty_genesis_data(), None), + (3.into(), empty_genesis_data(), None), + (4.into(), empty_genesis_data(), None), + (2.into(), empty_genesis_data(), None), ]) .execute_with(|| { run_to_block(1); @@ -595,7 +595,7 @@ fn genesis_error_genesis_data_size_too_big() { extensions: Default::default(), properties: Default::default(), }; - new_test_ext_with_genesis(vec![(2.into(), genesis_data)]).execute_with(|| { + new_test_ext_with_genesis(vec![(2.into(), genesis_data, None)]).execute_with(|| { run_to_block(1); }); } diff --git a/runtime/dancebox/src/tests/common/mod.rs b/runtime/dancebox/src/tests/common/mod.rs index 7447b8511..7cef1a7e3 100644 --- a/runtime/dancebox/src/tests/common/mod.rs +++ b/runtime/dancebox/src/tests/common/mod.rs @@ -302,21 +302,11 @@ pub fn set_parachain_inherent_data_random_seed(random_seed: [u8; 32]) { #[derive(Default, Clone)] pub struct ParaRegistrationParams { - para_id: u32, - genesis_data: ContainerChainGenesisData, - block_production_credits: u32, - collator_assignment_credits: u32, -} - -impl From<(u32, ContainerChainGenesisData, u32, u32)> for ParaRegistrationParams { - fn from(value: (u32, ContainerChainGenesisData, u32, u32)) -> Self { - Self { - para_id: value.0, - genesis_data: value.1, - block_production_credits: value.2, - collator_assignment_credits: value.3, - } - } + pub para_id: u32, + pub genesis_data: ContainerChainGenesisData, + pub block_production_credits: u32, + pub collator_assignment_credits: u32, + pub parathread_params: Option, } pub fn default_config() -> pallet_configuration::HostConfiguration { @@ -387,6 +377,22 @@ impl ExtBuilder { self } + /// Helper function like `with_para_ids` but registering parachains with an empty genesis data, + /// and max amount of credits. + pub fn with_empty_parachains(mut self, para_ids: Vec) -> Self { + self.para_ids = para_ids + .into_iter() + .map(|para_id| ParaRegistrationParams { + para_id, + genesis_data: empty_genesis_data(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + }) + .collect(); + self + } + pub fn with_config(mut self, config: pallet_configuration::HostConfiguration) -> Self { self.config = config; self @@ -422,7 +428,11 @@ impl ExtBuilder { .iter() .cloned() .map(|registered_para| { - (registered_para.para_id.into(), registered_para.genesis_data) + ( + registered_para.para_id.into(), + registered_para.genesis_data, + registered_para.parathread_params, + ) }) .collect(), phantom: Default::default(), diff --git a/runtime/dancebox/src/tests/integration_test.rs b/runtime/dancebox/src/tests/integration_test.rs index 7a0096252..bbbccad7e 100644 --- a/runtime/dancebox/src/tests/integration_test.rs +++ b/runtime/dancebox/src/tests/integration_test.rs @@ -98,10 +98,7 @@ fn genesis_balances() { #[test] fn genesis_para_registrar() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -114,10 +111,7 @@ fn genesis_para_registrar() { #[test] fn genesis_para_registrar_deregister() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -153,10 +147,7 @@ fn genesis_para_registrar_deregister() { #[test] fn genesis_para_registrar_runtime_api() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -195,8 +186,19 @@ fn genesis_para_registrar_container_chain_genesis_data_runtime_api() { }; ExtBuilder::default() .with_para_ids(vec![ - (1001, genesis_data_1001.clone(), u32::MAX, u32::MAX).into(), - (1002, genesis_data_1002.clone(), u32::MAX, u32::MAX).into(), + ParaRegistrationParams { + para_id: 1001, + genesis_data: genesis_data_1001.clone(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + },ParaRegistrationParams { + para_id: 1002, + genesis_data: genesis_data_1002.clone(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + }, ]) .build() .execute_with(|| { @@ -258,10 +260,7 @@ fn genesis_para_registrar_container_chain_genesis_data_runtime_api() { #[test] fn test_author_collation_aura() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(5); @@ -288,10 +287,7 @@ fn test_author_collation_aura_change_of_authorities_on_session() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -364,10 +360,7 @@ fn test_author_collation_aura_add_assigned_to_paras() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -880,10 +873,7 @@ fn test_parachains_deregister_collators_re_assigned() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -942,10 +932,7 @@ fn test_parachains_deregister_collators_config_change_reassigned() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1008,10 +995,7 @@ fn test_orchestrator_collators_with_non_sufficient_collators() { (AccountId::from(ALICE), 210_000 * UNIT), ]) .with_collators(vec![(AccountId::from(ALICE), 210 * UNIT)]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1077,10 +1061,7 @@ fn test_author_collation_aura_add_assigned_to_paras_runtime_api() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1234,10 +1215,7 @@ fn test_consensus_runtime_api() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1325,10 +1303,7 @@ fn test_consensus_runtime_api_session_changes() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1437,10 +1412,7 @@ fn test_consensus_runtime_api_next_session() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1639,10 +1611,7 @@ fn test_author_noting_not_self_para() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let mut sproof = ParaHeaderSproofBuilder::default(); @@ -1699,10 +1668,7 @@ fn test_author_noting_set_author_and_kill_author_data() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let other_para: ParaId = 1001u32.into(); @@ -1746,10 +1712,7 @@ fn test_author_noting_set_author_and_kill_author_data_bad_origin() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let other_para: ParaId = 1001u32.into(); @@ -1788,10 +1751,7 @@ fn test_author_noting_runtime_api() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let mut sproof = ParaHeaderSproofBuilder::default(); @@ -1854,10 +1814,7 @@ fn test_collator_assignment_rotation() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { // Charlie and Dave to 1001 @@ -1906,10 +1863,7 @@ fn test_session_keys_with_authority_mapping() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1986,10 +1940,7 @@ fn test_session_keys_with_authority_assignment() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2307,10 +2258,7 @@ fn test_staking_no_candidates_in_genesis() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2338,10 +2286,7 @@ fn test_staking_join() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2390,9 +2335,9 @@ fn test_staking_join_no_keys_registered() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), + .with_empty_parachains(vec![ + 1001, + 1002, ]) .build() @@ -2446,9 +2391,9 @@ fn test_staking_register_keys_after_joining() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), + .with_empty_parachains(vec![ + 1001, + 1002, ]) .build() @@ -2535,10 +2480,7 @@ fn test_staking_join_bad_origin() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2572,10 +2514,7 @@ fn test_staking_join_below_self_delegation_min() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2644,10 +2583,7 @@ fn test_staking_join_no_self_delegation() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2683,10 +2619,7 @@ fn test_staking_join_before_self_delegation() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2753,10 +2686,7 @@ fn test_staking_join_twice_in_same_block() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2822,10 +2752,7 @@ fn test_staking_join_execute_before_time() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2897,10 +2824,7 @@ fn test_staking_join_execute_any_origin() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2956,10 +2880,7 @@ fn test_staking_join_execute_bad_origin() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -3024,10 +2945,7 @@ fn setup_staking_join_and_execute(ops: Vec, f: impl FnOnce() -> R) { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -3460,10 +3378,7 @@ fn test_pallet_session_takes_validators_from_invulnerables_and_staking() { (AccountId::from(BOB), 100 * UNIT), (AccountId::from(CHARLIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -3550,10 +3465,7 @@ fn test_pallet_session_limits_num_validators() { (AccountId::from(BOB), 100 * UNIT), (AccountId::from(CHARLIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .with_config(pallet_configuration::HostConfiguration { max_collators: 2, min_orchestrator_collators: 2, @@ -3639,10 +3551,7 @@ fn test_pallet_session_limits_num_validators_from_staking() { (AccountId::from(DAVE), 100_000 * UNIT), ]) .with_collators(vec![(AccountId::from(ALICE), 210 * UNIT)]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .with_config(pallet_configuration::HostConfiguration { max_collators: 2, min_orchestrator_collators: 2, @@ -3751,10 +3660,7 @@ fn test_reward_to_staking_candidate() { (AccountId::from(DAVE), 100_000 * UNIT), ]) .with_collators(vec![(AccountId::from(ALICE), 210 * UNIT)]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -3858,10 +3764,7 @@ fn test_reward_to_invulnerable() { (AccountId::from(BOB), 100 * UNIT), (AccountId::from(CHARLIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -3948,10 +3851,7 @@ fn test_reward_to_invulnerable_with_key_change() { (AccountId::from(DAVE), 100_000 * UNIT), ]) .with_collators(vec![(AccountId::from(ALICE), 210 * UNIT)]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -4089,10 +3989,7 @@ fn test_collator_assignment_gives_priority_to_invulnerables() { (AccountId::from(ALICE), 210 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -4598,6 +4495,50 @@ fn test_register_parathread() { }); } +#[test] +fn test_register_parathread_genesis() { + let parathread_params = tp_traits::ParathreadParams { + slot_frequency: SlotFrequency { min: 1, max: 1 }, + }; + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 10k extra tokens for her mapping deposit + (AccountId::from(ALICE), 210_000 * UNIT), + (AccountId::from(BOB), 100_000 * UNIT), + (AccountId::from(CHARLIE), 100_000 * UNIT), + (AccountId::from(DAVE), 100_000 * UNIT), + ]) + .with_collators(vec![ + (AccountId::from(ALICE), 210 * UNIT), + (AccountId::from(BOB), 100 * UNIT), + (AccountId::from(CHARLIE), 100 * UNIT), + (AccountId::from(DAVE), 100 * UNIT), + ]) + .with_para_ids(vec![ParaRegistrationParams { + para_id: 3001, + genesis_data: empty_genesis_data(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: Some(parathread_params.clone()), + }]) + .build() + .execute_with(|| { + run_to_block(2); + + assert_eq!(Registrar::registered_para_ids(), vec![3001.into()]); + assert_eq!( + pallet_registrar::ParathreadParams::::get(ParaId::from(3001)), + Some(parathread_params) + ); + + let assignment = CollatorAssignment::collator_container_chain(); + assert_eq!( + assignment.container_chains[&ParaId::from(3001)], + vec![CHARLIE.into()] + ); + }); +} + #[test] fn test_ed_plus_block_credit_session_purchase_works() { ExtBuilder::default() @@ -5596,7 +5537,7 @@ fn test_max_collators_uses_pending_value() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![(1001, empty_genesis_data(), u32::MAX, u32::MAX).into()]) + .with_empty_parachains(vec![1001]) .with_config(pallet_configuration::HostConfiguration { max_collators: 100, min_orchestrator_collators: 1, @@ -5697,11 +5638,7 @@ fn test_collator_assignment_tip_priority_on_congestion() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let para_id = 1003u32; @@ -5752,11 +5689,7 @@ fn test_collator_assignment_tip_charged_on_congestion() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 100 * UNIT; @@ -5800,11 +5733,7 @@ fn test_collator_assignment_tip_not_assigned_on_insufficient_balance() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 1 * UNIT; @@ -5853,11 +5782,7 @@ fn test_collator_assignment_tip_only_charge_willing_paras() { (AccountId::from(EVE), 100 * UNIT), (AccountId::from(FERDIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 100 * UNIT; @@ -5925,11 +5850,7 @@ fn test_collator_assignment_tip_withdraw_min_tip() { (AccountId::from(EVE), 100 * UNIT), (AccountId::from(FERDIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 100 * UNIT; diff --git a/runtime/flashbox/src/tests/common/mod.rs b/runtime/flashbox/src/tests/common/mod.rs index b2a02e2bb..748dfdda2 100644 --- a/runtime/flashbox/src/tests/common/mod.rs +++ b/runtime/flashbox/src/tests/common/mod.rs @@ -290,21 +290,11 @@ pub fn set_parachain_inherent_data(mock_inherent_data: MockInherentData) { #[derive(Default, Clone)] pub struct ParaRegistrationParams { - para_id: u32, - genesis_data: ContainerChainGenesisData, - block_production_credits: u32, - collator_assignment_credits: u32, -} - -impl From<(u32, ContainerChainGenesisData, u32, u32)> for ParaRegistrationParams { - fn from(value: (u32, ContainerChainGenesisData, u32, u32)) -> Self { - Self { - para_id: value.0, - genesis_data: value.1, - block_production_credits: value.2, - collator_assignment_credits: value.3, - } - } + pub para_id: u32, + pub genesis_data: ContainerChainGenesisData, + pub block_production_credits: u32, + pub collator_assignment_credits: u32, + pub parathread_params: Option, } pub fn default_config() -> pallet_configuration::HostConfiguration { @@ -373,6 +363,22 @@ impl ExtBuilder { self } + /// Helper function like `with_para_ids` but registering parachains with an empty genesis data, + /// and max amount of credits. + pub fn with_empty_parachains(mut self, para_ids: Vec) -> Self { + self.para_ids = para_ids + .into_iter() + .map(|para_id| ParaRegistrationParams { + para_id, + genesis_data: empty_genesis_data(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + }) + .collect(); + self + } + pub fn with_config(mut self, config: pallet_configuration::HostConfiguration) -> Self { self.config = config; self @@ -398,7 +404,11 @@ impl ExtBuilder { .iter() .cloned() .map(|registered_para| { - (registered_para.para_id.into(), registered_para.genesis_data) + ( + registered_para.para_id.into(), + registered_para.genesis_data, + registered_para.parathread_params, + ) }) .collect(), phantom: Default::default(), diff --git a/runtime/flashbox/src/tests/integration_test.rs b/runtime/flashbox/src/tests/integration_test.rs index 4828830ae..84005af93 100644 --- a/runtime/flashbox/src/tests/integration_test.rs +++ b/runtime/flashbox/src/tests/integration_test.rs @@ -111,10 +111,7 @@ fn genesis_balances() { #[test] fn genesis_para_registrar() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -127,10 +124,7 @@ fn genesis_para_registrar() { #[test] fn genesis_para_registrar_deregister() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -166,10 +160,7 @@ fn genesis_para_registrar_deregister() { #[test] fn genesis_para_registrar_runtime_api() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -208,9 +199,19 @@ fn genesis_para_registrar_container_chain_genesis_data_runtime_api() { }; ExtBuilder::default() .with_para_ids(vec![ - (1001, genesis_data_1001.clone(), u32::MAX, u32::MAX).into(), - (1002, genesis_data_1002.clone(), u32::MAX, u32::MAX).into(), - ]) + ParaRegistrationParams { + para_id: 1001, + genesis_data: genesis_data_1001.clone(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + },ParaRegistrationParams { + para_id: 1002, + genesis_data: genesis_data_1002.clone(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + }, ]) .build() .execute_with(|| { assert_eq!( @@ -271,10 +272,7 @@ fn genesis_para_registrar_container_chain_genesis_data_runtime_api() { #[test] fn test_author_collation_aura() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(5); @@ -301,10 +299,7 @@ fn test_author_collation_aura_change_of_authorities_on_session() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -377,10 +372,7 @@ fn test_author_collation_aura_add_assigned_to_paras() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -893,10 +885,7 @@ fn test_parachains_deregister_collators_re_assigned() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -955,10 +944,7 @@ fn test_parachains_deregister_collators_config_change_reassigned() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1021,10 +1007,7 @@ fn test_orchestrator_collators_with_non_sufficient_collators() { (AccountId::from(ALICE), 210_000 * UNIT), ]) .with_collators(vec![(AccountId::from(ALICE), 210 * UNIT)]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1090,10 +1073,7 @@ fn test_author_collation_aura_add_assigned_to_paras_runtime_api() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1247,10 +1227,7 @@ fn test_consensus_runtime_api() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1338,10 +1315,7 @@ fn test_consensus_runtime_api_session_changes() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1450,10 +1424,7 @@ fn test_consensus_runtime_api_next_session() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1652,10 +1623,7 @@ fn test_author_noting_not_self_para() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let mut sproof = ParaHeaderSproofBuilder::default(); @@ -1712,10 +1680,7 @@ fn test_author_noting_set_author_and_kill_author_data() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let other_para: ParaId = 1001u32.into(); @@ -1759,10 +1724,7 @@ fn test_author_noting_set_author_and_kill_author_data_bad_origin() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let other_para: ParaId = 1001u32.into(); @@ -1801,10 +1763,7 @@ fn test_author_noting_runtime_api() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let mut sproof = ParaHeaderSproofBuilder::default(); @@ -1866,10 +1825,7 @@ fn test_session_keys_with_authority_mapping() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -1946,10 +1902,7 @@ fn test_session_keys_with_authority_assignment() { (AccountId::from(CHARLIE), 100_000 * UNIT), (AccountId::from(DAVE), 100_000 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2261,10 +2214,7 @@ fn test_reward_to_invulnerable() { (AccountId::from(BOB), 100 * UNIT), (AccountId::from(CHARLIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2314,10 +2264,7 @@ fn test_reward_to_invulnerable_with_key_change() { (AccountId::from(DAVE), 100_000 * UNIT), ]) .with_collators(vec![(AccountId::from(ALICE), 210 * UNIT)]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { run_to_block(2); @@ -2611,6 +2558,50 @@ fn test_register_parathread() { }); } +#[test] +fn test_register_parathread_genesis() { + let parathread_params = tp_traits::ParathreadParams { + slot_frequency: SlotFrequency { min: 1, max: 1 }, + }; + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 10k extra tokens for her mapping deposit + (AccountId::from(ALICE), 210_000 * UNIT), + (AccountId::from(BOB), 100_000 * UNIT), + (AccountId::from(CHARLIE), 100_000 * UNIT), + (AccountId::from(DAVE), 100_000 * UNIT), + ]) + .with_collators(vec![ + (AccountId::from(ALICE), 210 * UNIT), + (AccountId::from(BOB), 100 * UNIT), + (AccountId::from(CHARLIE), 100 * UNIT), + (AccountId::from(DAVE), 100 * UNIT), + ]) + .with_para_ids(vec![ParaRegistrationParams { + para_id: 3001, + genesis_data: empty_genesis_data(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: Some(parathread_params.clone()), + }]) + .build() + .execute_with(|| { + run_to_block(2); + + assert_eq!(Registrar::registered_para_ids(), vec![3001.into()]); + assert_eq!( + pallet_registrar::ParathreadParams::::get(ParaId::from(3001)), + Some(parathread_params) + ); + + let assignment = CollatorAssignment::collator_container_chain(); + assert_eq!( + assignment.container_chains[&ParaId::from(3001)], + vec![CHARLIE.into()] + ); + }); +} + #[test] fn test_ed_plus_block_credit_session_purchase_works() { ExtBuilder::default() @@ -3521,7 +3512,7 @@ fn test_max_collators_uses_pending_value() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![(1001, empty_genesis_data(), u32::MAX, u32::MAX).into()]) + .with_empty_parachains(vec![1001]) .with_config(pallet_configuration::HostConfiguration { max_collators: 100, min_orchestrator_collators: 1, @@ -3622,11 +3613,7 @@ fn test_collator_assignment_tip_priority_on_congestion() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let para_id = 1003u32; @@ -3677,11 +3664,7 @@ fn test_collator_assignment_tip_charged_on_congestion() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 100 * UNIT; @@ -3725,11 +3708,7 @@ fn test_collator_assignment_tip_not_assigned_on_insufficient_balance() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 1 * UNIT; @@ -3778,11 +3757,7 @@ fn test_collator_assignment_tip_only_charge_willing_paras() { (AccountId::from(EVE), 100 * UNIT), (AccountId::from(FERDIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 100 * UNIT; @@ -3850,11 +3825,7 @@ fn test_collator_assignment_tip_withdraw_min_tip() { (AccountId::from(EVE), 100 * UNIT), (AccountId::from(FERDIE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1003, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002, 1003]) .build() .execute_with(|| { let tank_funds = 100 * UNIT; diff --git a/solo-chains/runtime/starlight/src/tests/author_noting_tests.rs b/solo-chains/runtime/starlight/src/tests/author_noting_tests.rs index aad63e432..7bb071bf7 100644 --- a/solo-chains/runtime/starlight/src/tests/author_noting_tests.rs +++ b/solo-chains/runtime/starlight/src/tests/author_noting_tests.rs @@ -47,10 +47,7 @@ fn test_author_noting_not_self_para() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let mut sproof = ParaHeaderSproofBuilder::default(); @@ -108,10 +105,7 @@ fn test_author_noting_set_author_and_kill_author_data() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let other_para: ParaId = 1001u32.into(); @@ -155,10 +149,7 @@ fn test_author_noting_set_author_and_kill_author_data_bad_origin() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let other_para: ParaId = 1001u32.into(); @@ -197,10 +188,7 @@ fn test_author_noting_runtime_api() { (AccountId::from(CHARLIE), 100 * UNIT), (AccountId::from(DAVE), 100 * UNIT), ]) - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { let mut sproof = ParaHeaderSproofBuilder::default(); diff --git a/solo-chains/runtime/starlight/src/tests/collator_assignment_tests.rs b/solo-chains/runtime/starlight/src/tests/collator_assignment_tests.rs index d747fc143..024014a22 100644 --- a/solo-chains/runtime/starlight/src/tests/collator_assignment_tests.rs +++ b/solo-chains/runtime/starlight/src/tests/collator_assignment_tests.rs @@ -46,7 +46,7 @@ fn test_author_collation_aura_change_of_authorities_on_session() { collators_per_container: 2, ..Default::default() }) - .with_para_ids(vec![(1000, empty_genesis_data(), u32::MAX, u32::MAX).into()]) + .with_empty_parachains(vec![1000]) .build() .execute_with(|| { run_to_block(2); @@ -151,7 +151,7 @@ fn test_collators_per_container() { collators_per_container: 2, ..Default::default() }) - .with_para_ids(vec![(1000, empty_genesis_data(), u32::MAX, u32::MAX).into()]) + .with_empty_parachains(vec![1000]) .build() .execute_with(|| { run_to_block(2); @@ -232,7 +232,7 @@ fn test_session_keys_with_authority_assignment() { collators_per_container: 2, ..Default::default() }) - .with_para_ids(vec![(1000, empty_genesis_data(), u32::MAX, u32::MAX).into()]) + .with_empty_parachains(vec![1000]) .build() .execute_with(|| { run_to_block(2); diff --git a/solo-chains/runtime/starlight/src/tests/common/mod.rs b/solo-chains/runtime/starlight/src/tests/common/mod.rs index c0289ec42..19edf7e18 100644 --- a/solo-chains/runtime/starlight/src/tests/common/mod.rs +++ b/solo-chains/runtime/starlight/src/tests/common/mod.rs @@ -204,21 +204,11 @@ pub fn run_block() { #[derive(Default, Clone)] pub struct ParaRegistrationParams { - para_id: u32, - genesis_data: ContainerChainGenesisData, - block_production_credits: u32, - collator_assignment_credits: u32, -} - -impl From<(u32, ContainerChainGenesisData, u32, u32)> for ParaRegistrationParams { - fn from(value: (u32, ContainerChainGenesisData, u32, u32)) -> Self { - Self { - para_id: value.0, - genesis_data: value.1, - block_production_credits: value.2, - collator_assignment_credits: value.3, - } - } + pub para_id: u32, + pub genesis_data: ContainerChainGenesisData, + pub block_production_credits: u32, + pub collator_assignment_credits: u32, + pub parathread_params: Option, } pub fn default_config() -> pallet_configuration::HostConfiguration { @@ -297,6 +287,22 @@ impl ExtBuilder { self } + /// Helper function like `with_para_ids` but registering parachains with an empty genesis data, + /// and max amount of credits. + pub fn with_empty_parachains(mut self, para_ids: Vec) -> Self { + self.para_ids = para_ids + .into_iter() + .map(|para_id| ParaRegistrationParams { + para_id, + genesis_data: empty_genesis_data(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + }) + .collect(); + self + } + // Maybe change to with_collators_config? pub fn with_config(mut self, config: pallet_configuration::HostConfiguration) -> Self { self.config = config; @@ -335,7 +341,11 @@ impl ExtBuilder { .iter() .cloned() .map(|registered_para| { - (registered_para.para_id.into(), registered_para.genesis_data) + ( + registered_para.para_id.into(), + registered_para.genesis_data, + registered_para.parathread_params, + ) }) .collect(), phantom: Default::default(), diff --git a/solo-chains/runtime/starlight/src/tests/integration_test.rs b/solo-chains/runtime/starlight/src/tests/integration_test.rs index 81af15e26..9ae29f28d 100644 --- a/solo-chains/runtime/starlight/src/tests/integration_test.rs +++ b/solo-chains/runtime/starlight/src/tests/integration_test.rs @@ -53,10 +53,7 @@ fn genesis_balances() { #[test] fn genesis_para_registrar() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -69,10 +66,7 @@ fn genesis_para_registrar() { #[test] fn genesis_para_registrar_deregister() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -111,10 +105,7 @@ fn genesis_para_registrar_deregister() { #[test] fn genesis_para_registrar_runtime_api() { ExtBuilder::default() - .with_para_ids(vec![ - (1001, empty_genesis_data(), u32::MAX, u32::MAX).into(), - (1002, empty_genesis_data(), u32::MAX, u32::MAX).into(), - ]) + .with_empty_parachains(vec![1001, 1002]) .build() .execute_with(|| { assert_eq!( @@ -156,8 +147,19 @@ fn genesis_para_registrar_container_chain_genesis_data_runtime_api() { }; ExtBuilder::default() .with_para_ids(vec![ - (1001, genesis_data_1001.clone(), u32::MAX, u32::MAX).into(), - (1002, genesis_data_1002.clone(), u32::MAX, u32::MAX).into(), + ParaRegistrationParams { + para_id: 1001, + genesis_data: genesis_data_1001.clone(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + },ParaRegistrationParams { + para_id: 1002, + genesis_data: genesis_data_1002.clone(), + block_production_credits: u32::MAX, + collator_assignment_credits: u32::MAX, + parathread_params: None, + }, ]) .build() .execute_with(|| {