solutions/pallets/template/src/mock.rs

63 lines
1.6 KiB
Rust
Raw Normal View History

2021-02-24 14:12:24 +00:00
use crate as pallet_template;
2020-03-05 16:53:25 +00:00
use sp_core::H256;
2021-02-24 14:12:24 +00:00
use frame_support::parameter_types;
2020-03-05 16:53:25 +00:00
use sp_runtime::{
2021-02-24 14:12:24 +00:00
traits::{BlakeTwo256, IdentityLookup}, testing::Header,
2020-03-05 16:53:25 +00:00
};
2020-04-15 11:33:19 +00:00
use frame_system as system;
2020-03-05 16:53:25 +00:00
2021-02-24 14:12:24 +00:00
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
2020-03-05 16:53:25 +00:00
2020-07-25 12:35:30 +00:00
// Configure a mock runtime to test the pallet.
2021-02-24 14:12:24 +00:00
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
TemplateModule: pallet_template::{Pallet, Call, Storage, Event<T>},
2021-02-24 14:12:24 +00:00
}
);
2020-07-25 12:35:30 +00:00
2020-03-05 16:53:25 +00:00
parameter_types! {
pub const BlockHashCount: u64 = 250;
2021-02-24 14:12:24 +00:00
pub const SS58Prefix: u8 = 42;
2020-03-05 16:53:25 +00:00
}
2020-07-25 12:35:30 +00:00
2021-02-24 14:12:24 +00:00
impl system::Config for Test {
type BaseCallFilter = ();
2021-02-24 14:12:24 +00:00
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
2020-03-05 16:53:25 +00:00
type Origin = Origin;
2021-02-24 14:12:24 +00:00
type Call = Call;
2020-03-05 16:53:25 +00:00
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
2021-02-24 14:12:24 +00:00
type Event = Event;
2020-03-05 16:53:25 +00:00
type BlockHashCount = BlockHashCount;
type Version = ();
2021-02-24 14:12:24 +00:00
type PalletInfo = PalletInfo;
2020-03-05 16:53:25 +00:00
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
2020-07-25 12:35:30 +00:00
type SystemWeightInfo = ();
2021-02-24 14:12:24 +00:00
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
2020-03-05 16:53:25 +00:00
}
2020-07-25 12:35:30 +00:00
2021-02-24 14:12:24 +00:00
impl pallet_template::Config for Test {
type Event = Event;
2020-03-05 16:53:25 +00:00
}
2020-07-25 12:35:30 +00:00
// Build genesis storage according to the mock runtime.
2020-03-05 16:53:25 +00:00
pub fn new_test_ext() -> sp_io::TestExternalities {
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
}