mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-16 02:35:44 +00:00
Try-state for Referenda pallet (#13949)
* Try-state for Referenda pallet * fix & more tests * checking more stuff * remove log * two more tests * Update frame/referenda/src/lib.rs Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> * fixes * new check * merge fixes * fix warning * remove check * Update frame/referenda/src/lib.rs Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> * separate into multiple functions * clean up * unnecessary return value specified * fix * Update frame/referenda/src/lib.rs * fmt * remove import * fmt * fix CI * Update frame/referenda/src/lib.rs Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> * last fixes * :P * fmt --------- Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
This commit is contained in:
@@ -225,23 +225,32 @@ impl Config for Test {
|
||||
type Tracks = TestTracksInfo;
|
||||
type Preimages = Preimage;
|
||||
}
|
||||
pub struct ExtBuilder {}
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100), (6, 100)];
|
||||
pallet_balances::GenesisConfig::<Test> { balances }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute the function two times, with `true` and with `false`.
|
||||
#[allow(dead_code)]
|
||||
pub fn new_test_ext_execute_with_cond(execute: impl FnOnce(bool) -> () + Clone) {
|
||||
new_test_ext().execute_with(|| (execute.clone())(false));
|
||||
new_test_ext().execute_with(|| execute(true));
|
||||
impl ExtBuilder {
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
let balances = vec![(1, 100), (2, 100), (3, 100), (4, 100), (5, 100), (6, 100)];
|
||||
pallet_balances::GenesisConfig::<Test> { balances }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
|
||||
pub fn build_and_execute(self, test: impl FnOnce() -> ()) {
|
||||
self.build().execute_with(|| {
|
||||
test();
|
||||
Referenda::do_try_state().unwrap();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encode, Debug, Decode, TypeInfo, Eq, PartialEq, Clone, MaxEncodedLen)]
|
||||
|
||||
Reference in New Issue
Block a user