mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Do not use Option to wrap GenesisConfig fields (#8275)
Currently we wrap every `GenesisConfig` field in an `Option`, while we require `Default` being implemented for all pallet genesisconfigs. Passing `None` also results in the genesis not being initialized, which is a bug as seen from the perspective of a pallet developer? This pr changes the fields of the `GenesisConfig` to non `Option` types.
This commit is contained in:
@@ -1054,15 +1054,15 @@ mod tests {
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig {
|
||||
collective_Instance1: Some(collective::GenesisConfig {
|
||||
collective_Instance1: collective::GenesisConfig {
|
||||
members: vec![1, 2, 3],
|
||||
phantom: Default::default(),
|
||||
}),
|
||||
collective_Instance2: Some(collective::GenesisConfig {
|
||||
},
|
||||
collective_Instance2: collective::GenesisConfig {
|
||||
members: vec![1, 2, 3, 4, 5],
|
||||
phantom: Default::default(),
|
||||
}),
|
||||
collective: None,
|
||||
},
|
||||
collective: Default::default(),
|
||||
}.build_storage().unwrap().into();
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
|
||||
@@ -1245,7 +1245,7 @@ mod tests {
|
||||
pub fn build_and_execute(self, test: impl FnOnce() -> ()) {
|
||||
MEMBERS.with(|m| *m.borrow_mut() = self.genesis_members.iter().map(|(m, _)| m.clone()).collect::<Vec<_>>());
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig {
|
||||
pallet_balances: Some(pallet_balances::GenesisConfig::<Test>{
|
||||
pallet_balances: pallet_balances::GenesisConfig::<Test>{
|
||||
balances: vec![
|
||||
(1, 10 * self.balance_factor),
|
||||
(2, 20 * self.balance_factor),
|
||||
@@ -1254,10 +1254,10 @@ mod tests {
|
||||
(5, 50 * self.balance_factor),
|
||||
(6, 60 * self.balance_factor)
|
||||
],
|
||||
}),
|
||||
elections_phragmen: Some(elections_phragmen::GenesisConfig::<Test> {
|
||||
},
|
||||
elections_phragmen: elections_phragmen::GenesisConfig::<Test> {
|
||||
members: self.genesis_members
|
||||
}),
|
||||
},
|
||||
}.build_storage().unwrap().into();
|
||||
ext.execute_with(pre_conditions);
|
||||
ext.execute_with(test);
|
||||
|
||||
@@ -194,7 +194,7 @@ impl ExtBuilder {
|
||||
PRESENT_SLASH_PER_VOTER.with(|v| *v.borrow_mut() = self.bad_presentation_punishment);
|
||||
DECAY_RATIO.with(|v| *v.borrow_mut() = self.decay_ratio);
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig {
|
||||
pallet_balances: Some(pallet_balances::GenesisConfig::<Test>{
|
||||
pallet_balances: pallet_balances::GenesisConfig::<Test>{
|
||||
balances: vec![
|
||||
(1, 10 * self.balance_factor),
|
||||
(2, 20 * self.balance_factor),
|
||||
@@ -203,13 +203,13 @@ impl ExtBuilder {
|
||||
(5, 50 * self.balance_factor),
|
||||
(6, 60 * self.balance_factor)
|
||||
],
|
||||
}),
|
||||
elections: Some(elections::GenesisConfig::<Test>{
|
||||
},
|
||||
elections: elections::GenesisConfig::<Test>{
|
||||
members: vec![],
|
||||
desired_seats: self.desired_seats,
|
||||
presentation_duration: 2,
|
||||
term_duration: 5,
|
||||
}),
|
||||
},
|
||||
}.build_storage().unwrap().into();
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
|
||||
@@ -814,14 +814,14 @@ mod tests {
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let t = GenesisConfig {
|
||||
// We use default for brevity, but you can configure as desired if needed.
|
||||
frame_system: Some(Default::default()),
|
||||
pallet_balances: Some(Default::default()),
|
||||
pallet_example: Some(pallet_example::GenesisConfig {
|
||||
frame_system: Default::default(),
|
||||
pallet_balances: Default::default(),
|
||||
pallet_example: pallet_example::GenesisConfig {
|
||||
dummy: 42,
|
||||
// we configure the map with (key, value) pairs.
|
||||
bar: vec![(1, 2), (2, 3)],
|
||||
foo: 24,
|
||||
}),
|
||||
},
|
||||
}.build_storage().unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ macro_rules! impl_outer_config {
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct $main {
|
||||
$(
|
||||
pub [< $snake $(_ $instance )? >]: Option<$config>,
|
||||
pub [< $snake $(_ $instance )? >]: $config,
|
||||
)*
|
||||
}
|
||||
#[cfg(any(feature = "std", test))]
|
||||
@@ -92,15 +92,13 @@ macro_rules! impl_outer_config {
|
||||
storage: &mut $crate::sp_runtime::Storage,
|
||||
) -> std::result::Result<(), String> {
|
||||
$(
|
||||
if let Some(ref extra) = self.[< $snake $(_ $instance )? >] {
|
||||
$crate::impl_outer_config! {
|
||||
@CALL_FN
|
||||
$concrete;
|
||||
$snake;
|
||||
$( $instance )?;
|
||||
extra;
|
||||
storage;
|
||||
}
|
||||
$crate::impl_outer_config! {
|
||||
@CALL_FN
|
||||
$concrete;
|
||||
$snake;
|
||||
$( $instance )?;
|
||||
&self.[< $snake $(_ $instance )? >];
|
||||
storage;
|
||||
}
|
||||
)*
|
||||
|
||||
@@ -117,7 +115,7 @@ macro_rules! impl_outer_config {
|
||||
$runtime:ident;
|
||||
$module:ident;
|
||||
$instance:ident;
|
||||
$extra:ident;
|
||||
$extra:expr;
|
||||
$storage:ident;
|
||||
) => {
|
||||
$crate::sp_runtime::BuildModuleGenesisStorage::<$runtime, $module::$instance>::build_module_genesis_storage(
|
||||
@@ -129,7 +127,7 @@ macro_rules! impl_outer_config {
|
||||
$runtime:ident;
|
||||
$module:ident;
|
||||
;
|
||||
$extra:ident;
|
||||
$extra:expr;
|
||||
$storage:ident;
|
||||
) => {
|
||||
$crate::sp_runtime::BuildModuleGenesisStorage::
|
||||
|
||||
@@ -291,26 +291,26 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature,
|
||||
|
||||
fn new_test_ext() -> sp_io::TestExternalities {
|
||||
GenesisConfig{
|
||||
module1_Instance1: Some(module1::GenesisConfig {
|
||||
module1_Instance1: module1::GenesisConfig {
|
||||
value: 3,
|
||||
test: 2,
|
||||
}),
|
||||
module1_Instance2: Some(module1::GenesisConfig {
|
||||
},
|
||||
module1_Instance2: module1::GenesisConfig {
|
||||
value: 4,
|
||||
test: 5,
|
||||
}),
|
||||
module2: Some(module2::GenesisConfig {
|
||||
},
|
||||
module2: module2::GenesisConfig {
|
||||
value: 4,
|
||||
map: vec![(0, 0)],
|
||||
double_map: vec![(0, 0, 0)],
|
||||
}),
|
||||
module2_Instance1: Some(module2::GenesisConfig {
|
||||
},
|
||||
module2_Instance1: module2::GenesisConfig {
|
||||
value: 4,
|
||||
map: vec![(0, 0)],
|
||||
double_map: vec![(0, 0, 0)],
|
||||
}),
|
||||
module2_Instance2: None,
|
||||
module2_Instance3: None,
|
||||
},
|
||||
module2_Instance2: Default::default(),
|
||||
module2_Instance3: Default::default(),
|
||||
}.build_storage().unwrap().into()
|
||||
}
|
||||
|
||||
|
||||
@@ -185,9 +185,9 @@ frame_support::construct_runtime!(
|
||||
#[test]
|
||||
fn create_genesis_config() {
|
||||
GenesisConfig {
|
||||
module: Some(module::GenesisConfig {
|
||||
module: module::GenesisConfig {
|
||||
request_life_time: 0,
|
||||
enable_storage_role: true,
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user