Skip to content

Commit 52159e3

Browse files
committed
move default impl of genesis into tests
1 parent 051cece commit 52159e3

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

pallets/dapp-staking-v3/src/lib.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ pub mod pallet {
503503
pub type Safeguard<T: Config> = StorageValue<_, bool, ValueQuery, DefaultSafeguard<T>>;
504504

505505
#[pallet::genesis_config]
506+
#[cfg_attr(not(test), derive(frame_support::DefaultNoBound))]
506507
pub struct GenesisConfig<T> {
507508
pub reward_portion: Vec<Permill>,
508509
pub slot_distribution: Vec<Permill>,
@@ -512,26 +513,6 @@ pub mod pallet {
512513
pub _config: PhantomData<T>,
513514
}
514515

515-
/// TODO: default valid config?
516-
impl<T: Config> Default for GenesisConfig<T> {
517-
fn default() -> Self {
518-
use sp_std::vec;
519-
let num_tiers = T::NumberOfTiers::get();
520-
Self {
521-
reward_portion: vec![Permill::from_percent(100 / num_tiers); num_tiers as usize],
522-
slot_distribution: vec![Permill::from_percent(100 / num_tiers); num_tiers as usize],
523-
tier_thresholds: (0..num_tiers)
524-
.map(|i| TierThreshold::FixedTvlAmount {
525-
amount: (10 * i).into(),
526-
})
527-
.collect(),
528-
slots_per_tier: vec![100; num_tiers as usize],
529-
safeguard: Some(false),
530-
_config: ::core::default::Default::default(),
531-
}
532-
}
533-
}
534-
535516
#[pallet::genesis_build]
536517
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
537518
fn build(&self) {

pallets/dapp-staking-v3/src/test/mock.rs

+20
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,26 @@ impl ExtBuilder {
360360
}
361361
}
362362

363+
// Default implementation of GenesisConfig used for testing
364+
impl Default for GenesisConfig<Test> {
365+
fn default() -> Self {
366+
use sp_std::vec;
367+
let num_tiers = <<Test as Config>::NumberOfTiers as Get<u32>>::get();
368+
Self {
369+
reward_portion: vec![Permill::from_percent(100 / num_tiers); num_tiers as usize],
370+
slot_distribution: vec![Permill::from_percent(100 / num_tiers); num_tiers as usize],
371+
tier_thresholds: (0..num_tiers)
372+
.map(|i| TierThreshold::FixedTvlAmount {
373+
amount: (10 * i).into(),
374+
})
375+
.collect(),
376+
slots_per_tier: vec![100; num_tiers as usize],
377+
safeguard: Some(false),
378+
_config: ::core::default::Default::default(),
379+
}
380+
}
381+
}
382+
363383
/// Run to the specified block number.
364384
/// Function assumes first block has been initialized.
365385
pub(crate) fn run_to_block(n: BlockNumber) {

0 commit comments

Comments
 (0)