Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Sep 3, 2024
1 parent 5992697 commit 73daab1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 63 deletions.
8 changes: 3 additions & 5 deletions solo-chains/runtime/starlight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,13 +1634,11 @@ where
None => return Err(ContainerRegistrarError::<Runtime>::HeadDataNecessary.into()),
};

let key_values: Vec<(Vec<u8>, Vec<u8>)> =
genesis_storage.into_iter().map(Into::into).collect();

// Check if the wasm code is present in storage
let validation_code = match key_values
let validation_code = match genesis_storage
.into_iter()
.find(|(key, _)| key == &StorageWellKnownKeys::CODE.to_vec())
.map(Into::into)
.find(|(key, _): &(Vec<u8>, Vec<u8>)| key == &StorageWellKnownKeys::CODE)
{
Some((_, code)) => ValidationCode(code),
None => return Err(ContainerRegistrarError::<Runtime>::WasmCodeNecessary.into()),
Expand Down
79 changes: 21 additions & 58 deletions solo-chains/runtime/starlight/src/tests/relay_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#![cfg(test)]

use {
crate::{tests::common::*, Configuration, ContainerRegistrar, Paras, Registrar, System},
crate::{tests::common::*, ContainerRegistrar, Paras, Registrar, System},
cumulus_primitives_core::relay_chain::HeadData,
frame_support::{assert_noop, assert_ok},
pallet_registrar::Event as ContainerRegistrarEvent,
Expand Down Expand Up @@ -116,14 +116,7 @@ fn register_para_via_container_registrar() {

assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
run_to_session(1u32);

// Change max_head_data_size config.
assert_ok!(
Configuration::set_max_head_data_size(root_origin(), 20500),
()
);
run_to_session(4u32);
run_to_session(2u32);
assert_eq!(
parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
20500
Expand Down Expand Up @@ -152,7 +145,7 @@ fn register_para_via_container_registrar() {

// Now let's check if the para was preoperly registered in the relay.
// Run to next session.
run_to_session(5);
run_to_session(3);
assert!(Paras::lifecycle(1003.into())
.expect("para should be onboarding")
.is_onboarding());
Expand All @@ -162,7 +155,7 @@ fn register_para_via_container_registrar() {
root_origin(),
validation_code.into()
));
run_to_session(7);
run_to_session(5);

// Now the para should be a parathread.
assert!(Paras::lifecycle(1003.into())
Expand All @@ -185,14 +178,7 @@ fn cannot_register_para_twice_in_relay() {

assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
run_to_session(1u32);

// Change max_head_data_size config.
assert_ok!(
Configuration::set_max_head_data_size(root_origin(), 20500),
()
);
run_to_session(4u32);
run_to_session(2u32);
assert_eq!(
parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
20500
Expand Down Expand Up @@ -221,7 +207,7 @@ fn cannot_register_para_twice_in_relay() {

// Now let's check if the para was preoperly registered in the relay.
// Run to next session.
run_to_session(5);
run_to_session(3);
assert!(Paras::lifecycle(1003.into())
.expect("para should be onboarding")
.is_onboarding());
Expand All @@ -231,7 +217,7 @@ fn cannot_register_para_twice_in_relay() {
root_origin(),
validation_code.clone().into()
));
run_to_session(7);
run_to_session(5);

// Now the para should be a parathread.
assert!(Paras::lifecycle(1003.into())
Expand Down Expand Up @@ -266,14 +252,7 @@ fn mark_valid_for_collating_converts_to_parachain() {

assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
run_to_session(1u32);

// Change max_head_data_size config.
assert_ok!(
Configuration::set_max_head_data_size(root_origin(), 20500),
()
);
run_to_session(4u32);
run_to_session(2u32);
assert_eq!(
parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
20500
Expand Down Expand Up @@ -302,7 +281,7 @@ fn mark_valid_for_collating_converts_to_parachain() {

// Now let's check if the para was preoperly registered in the relay.
// Run to next session.
run_to_session(5);
run_to_session(3);
assert!(Paras::lifecycle(1003.into())
.expect("para should be onboarding")
.is_onboarding());
Expand All @@ -312,7 +291,7 @@ fn mark_valid_for_collating_converts_to_parachain() {
root_origin(),
validation_code.into()
));
run_to_session(7);
run_to_session(5);

// Now the para should be a parathread.
assert!(Paras::lifecycle(1003.into())
Expand All @@ -328,7 +307,7 @@ fn mark_valid_for_collating_converts_to_parachain() {
);

// The change should be applied after 2 sessions.
run_to_session(9);
run_to_session(7);
assert!(Paras::lifecycle(1003.into())
.expect("para should be parachain")
.is_parachain());
Expand All @@ -349,15 +328,7 @@ fn deregister_calls_schedule_para_cleanup() {

assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
run_to_session(1u32);

// Change max_head_data_size config.
assert_ok!(
Configuration::set_max_head_data_size(root_origin(), 20500),
()
);

run_to_session(4u32);
run_to_session(2u32);
assert_eq!(
parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
20500
Expand Down Expand Up @@ -386,7 +357,7 @@ fn deregister_calls_schedule_para_cleanup() {

// Now let's check if the para was preoperly registered in the relay.
// Run to next session.
run_to_session(5);
run_to_session(3);
assert!(Paras::lifecycle(1003.into())
.expect("para should be onboarding")
.is_onboarding());
Expand All @@ -397,7 +368,7 @@ fn deregister_calls_schedule_para_cleanup() {
validation_code.into()
));

run_to_session(7);
run_to_session(5);

// Now the para should be a parathread.
assert!(Paras::lifecycle(1003.into())
Expand All @@ -413,7 +384,7 @@ fn deregister_calls_schedule_para_cleanup() {
);

// The change should be applied after 2 sessions.
run_to_session(9);
run_to_session(7);
assert!(Paras::lifecycle(1003.into())
.expect("para should be parachain")
.is_parachain());
Expand All @@ -433,7 +404,7 @@ fn deregister_calls_schedule_para_cleanup() {
.into(),
);

run_to_session(11);
run_to_session(9);
end_block();

assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
Expand All @@ -460,15 +431,7 @@ fn deregister_two_paras_in_the_same_block() {
assert_eq!(Runtime::registered_paras(), vec![1001.into(), 1002.into()]);
assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
assert_eq!(Runtime::genesis_data(1004.into()).as_ref(), None);
run_to_session(1u32);

// Change max_head_data_size config.
assert_ok!(
Configuration::set_max_head_data_size(root_origin(), 20500),
()
);

run_to_session(4u32);
run_to_session(2u32);
assert_eq!(
parachains_configuration::ActiveConfig::<Runtime>::get().max_head_data_size,
20500
Expand Down Expand Up @@ -509,7 +472,7 @@ fn deregister_two_paras_in_the_same_block() {

// Now let's check if the paras were preoperly registered in the relay.
// Run to next session.
run_to_session(5);
run_to_session(3);
assert!(Paras::lifecycle(1003.into())
.expect("para should be onboarding")
.is_onboarding());
Expand All @@ -524,7 +487,7 @@ fn deregister_two_paras_in_the_same_block() {
validation_code.into()
));

run_to_session(7);
run_to_session(5);

// Now paras should be parathreads.
assert!(Paras::lifecycle(1003.into())
Expand All @@ -549,7 +512,7 @@ fn deregister_two_paras_in_the_same_block() {
);

// The change should be applied after 2 sessions.
run_to_session(9);
run_to_session(7);
assert!(Paras::lifecycle(1003.into())
.expect("para should be parachain")
.is_parachain());
Expand Down Expand Up @@ -586,7 +549,7 @@ fn deregister_two_paras_in_the_same_block() {
.into(),
);

run_to_session(11);
run_to_session(9);
end_block();

assert_eq!(Runtime::genesis_data(1003.into()).as_ref(), None);
Expand Down

0 comments on commit 73daab1

Please sign in to comment.