Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FRAME] Test for sane genesis default #3412

Merged
merged 10 commits into from
Feb 22, 2024
6 changes: 2 additions & 4 deletions substrate/frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub mod pallet {
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
pub epoch_config: Option<BabeEpochConfiguration>,
pub epoch_config: BabeEpochConfiguration,
#[serde(skip)]
pub _config: sp_std::marker::PhantomData<T>,
}
Expand All @@ -333,9 +333,7 @@ pub mod pallet {
fn build(&self) {
SegmentIndex::<T>::put(0);
Pallet::<T>::initialize_genesis_authorities(&self.authorities);
EpochConfig::<T>::put(
self.epoch_config.clone().expect("epoch_config must not be None"),
);
EpochConfig::<T>::put(&self.epoch_config);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ pub fn expand_outer_config(
<AllPalletsWithSystem as #scrate::traits::OnGenesis>::on_genesis();
}
}

/// Test the `Default` derive impl of the `RuntimeGenesisConfig`.
#[cfg(test)]
#[test]
fn test_genesis_config_builds() {
#scrate::__private::sp_io::TestExternalities::default().execute_with(|| {
<RuntimeGenesisConfig as #scrate::traits::BuildGenesisConfig>::build(
&RuntimeGenesisConfig::default()
);
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ macro_rules! assert_err_with_weight {
$crate::assert_err!($call.map(|_| ()).map_err(|e| e.error), $err);
assert_eq!(dispatch_err_with_post.post_info.actual_weight, $weight);
} else {
panic!("expected Err(_), got Ok(_).")
::core::panic!("expected Err(_), got Ok(_).")
}
};
}
Expand Down
6 changes: 6 additions & 0 deletions substrate/primitives/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ pub struct BabeEpochConfiguration {
pub allowed_slots: AllowedSlots,
}

impl Default for BabeEpochConfiguration {
fn default() -> Self {
Self { c: (1, 4), allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots }
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Verifies the equivocation proof by making sure that: both headers have
/// different hashes, are targetting the same slot, and have valid signatures by
/// the same authority.
Expand Down
Loading