Skip to content
Snippets Groups Projects
mock.rs 2.08 KiB
Newer Older
  • Learn to ignore specific revisions
  • //! Mocks for the gradually-update module.
    
    #![cfg(test)]
    
    use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
    use frame_system as system;
    use sp_core::H256;
    use sp_runtime::{testing::Header, traits::IdentityLookup, Perbill};
    
    use super::*;
    
    impl_outer_origin! {
    	pub enum Origin for Runtime {}
    }
    
    mod gradually_update {
    	pub use crate::Event;
    }
    
    impl_outer_event! {
    	pub enum TestEvent for Runtime {
    		frame_system<T>,
    		gradually_update<T>,
    	}
    }
    
    // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
    #[derive(Clone, PartialEq, Eq, Debug)]
    pub struct Runtime;
    parameter_types! {
    	pub const BlockHashCount: u64 = 250;
    	pub const MaximumBlockWeight: u32 = 1024;
    	pub const MaximumBlockLength: u32 = 2 * 1024;
    	pub const AvailableBlockRatio: Perbill = Perbill::one();
    }
    
    pub type AccountId = u64;
    pub type BlockNumber = u64;
    
    impl frame_system::Trait for Runtime {
    	type Origin = Origin;
    	type Index = u64;
    	type BlockNumber = BlockNumber;
    	type Call = ();
    	type Hash = H256;
    	type Hashing = ::sp_runtime::traits::BlakeTwo256;
    	type AccountId = AccountId;
    	type Lookup = IdentityLookup<Self::AccountId>;
    	type Header = Header;
    	type Event = TestEvent;
    	type BlockHashCount = BlockHashCount;
    	type MaximumBlockWeight = MaximumBlockWeight;
    	type MaximumBlockLength = MaximumBlockLength;
    	type AvailableBlockRatio = AvailableBlockRatio;
    	type Version = ();
    	type ModuleToIndex = ();
    	type AccountData = ();
    	type OnNewAccount = ();
    	type OnKilledAccount = ();
    
    	type DbWeight = ();
    	type BlockExecutionWeight = ();
    	type ExtrinsicBaseWeight = ();
    
    }
    pub type System = system::Module<Runtime>;
    
    parameter_types! {
    	pub const UpdateFrequency: BlockNumber = 10;
    }
    
    impl Trait for Runtime {
    	type Event = TestEvent;
    	type UpdateFrequency = UpdateFrequency;
    }
    pub type GraduallyUpdateModule = Module<Runtime>;
    
    pub struct ExtBuilder;
    
    impl Default for ExtBuilder {
    	fn default() -> Self {
    		ExtBuilder
    	}
    }
    
    impl ExtBuilder {
    	pub fn build(self) -> sp_io::TestExternalities {
    		let t = frame_system::GenesisConfig::default()
    			.build_storage::<Runtime>()
    			.unwrap();
    
    		t.into()
    	}
    }