git.delta.rocks / unique-network / refs/commits / 2ddc70da9e1d

difftreelog

source

pallets/template/src/mock.rs1.6 KiBsourcehistory
1// Creating mock runtime here23use crate::{Module, Trait};4use sp_core::H256;5use frame_support::{impl_outer_origin, parameter_types, weights::Weight};6use sp_runtime::{7	traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill,8};910impl_outer_origin! {11	pub enum Origin for Test {}12}1314// For testing the pallet, we construct most of a mock runtime. This means15// first constructing a configuration type (`Test`) which `impl`s each of the16// configuration traits of pallets we want to use.17#[derive(Clone, Eq, PartialEq)]18pub struct Test;19parameter_types! {20	pub const BlockHashCount: u64 = 250;21	pub const MaximumBlockWeight: Weight = 1024;22	pub const MaximumBlockLength: u32 = 2 * 1024;23	pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);24}25impl system::Trait for Test {26	type Origin = Origin;27	type Call = ();28	type Index = u64;29	type BlockNumber = u64;30	type Hash = H256;31	type Hashing = BlakeTwo256;32	type AccountId = u64;33	type Lookup = IdentityLookup<Self::AccountId>;34	type Header = Header;35	type Event = ();36	type BlockHashCount = BlockHashCount;37	type MaximumBlockWeight = MaximumBlockWeight;38	type MaximumBlockLength = MaximumBlockLength;39	type AvailableBlockRatio = AvailableBlockRatio;40	type Version = ();41	type ModuleToIndex = ();42	type AccountData = ();43	type OnNewAccount = ();44	type OnKilledAccount = ();45}46impl Trait for Test {47	type Event = ();48}49pub type TemplateModule = Module<Test>;5051// This function basically just builds a genesis storage key/value store according to52// our desired mockup.53pub fn new_test_ext() -> sp_io::TestExternalities {54	system::GenesisConfig::default().build_storage::<Test>().unwrap().into()55}