Skip to content

Commit

Permalink
fix compile
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Jul 17, 2024
1 parent 038dba3 commit 4b47d88
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
20 changes: 19 additions & 1 deletion pallets/propagation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use frame_election_provider_support::{
};
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, FindAuthor, OneSessionHandler},
traits::{ConstU32, FindAuthor, OneSessionHandler, Randomness},
};
use frame_system as system;
use pallet_session::historical as pallet_session_historical;
Expand All @@ -31,6 +31,7 @@ use sp_runtime::{
BuildStorage, Perbill,
};
use sp_staking::{EraIndex, SessionIndex};
use std::cell::RefCell;

use crate as pallet_propagation;

Expand Down Expand Up @@ -281,12 +282,29 @@ impl pallet_session::historical::Config for Test {
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
}

thread_local! {
pub static LAST_RANDOM: RefCell<Option<(H256, u64)>> = RefCell::new(None);
}

pub struct TestPastRandomness;
impl Randomness<H256, BlockNumber> for TestPastRandomness {
fn random(_subject: &[u8]) -> (H256, u64) {
LAST_RANDOM.with(|p| {
if let Some((output, known_since)) = &*p.borrow() {
(*output, *known_since)
} else {
(H256::zero(), frame_system::Pallet::<Test>::block_number())
}
})
}
}
parameter_types! {
pub const MaxEndpointLength: u32 = 3;
}
impl pallet_staking_extension::Config for Test {
type Currency = Balances;
type MaxEndpointLength = MaxEndpointLength;
type Randomness = TestPastRandomness;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
Expand Down
21 changes: 20 additions & 1 deletion pallets/registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use frame_election_provider_support::{
};
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, FindAuthor, OneSessionHandler},
traits::{ConstU32, FindAuthor, OneSessionHandler, Randomness},
};
use frame_system as system;
use pallet_session::historical as pallet_session_historical;
Expand All @@ -31,6 +31,7 @@ use sp_runtime::{
BuildStorage, Perbill,
};
use sp_staking::{EraIndex, SessionIndex};
use std::cell::RefCell;

use crate as pallet_registry;

Expand Down Expand Up @@ -277,12 +278,29 @@ impl pallet_session::historical::Config for Test {
type FullIdentificationOf = pallet_staking::ExposureOf<Test>;
}

thread_local! {
pub static LAST_RANDOM: RefCell<Option<(H256, u64)>> = RefCell::new(None);
}

pub struct TestPastRandomness;
impl Randomness<H256, BlockNumber> for TestPastRandomness {
fn random(_subject: &[u8]) -> (H256, u64) {
LAST_RANDOM.with(|p| {
if let Some((output, known_since)) = &*p.borrow() {
(*output, *known_since)
} else {
(H256::zero(), frame_system::Pallet::<Test>::block_number())
}
})
}
}
parameter_types! {
pub const MaxEndpointLength: u32 = 3;
}
impl pallet_staking_extension::Config for Test {
type Currency = Balances;
type MaxEndpointLength = MaxEndpointLength;
type Randomness = TestPastRandomness;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
Expand Down Expand Up @@ -347,6 +365,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(7, (4, NULL_ARR, vec![50])),
],
proactive_refresh_data: (vec![], vec![]),
inital_signers: vec![5, 6],
};

pallet_staking_extension.assimilate_storage(&mut t).unwrap();
Expand Down

0 comments on commit 4b47d88

Please sign in to comment.