solutions/pallets/template/src/mock.rs

60 lines
1.6 KiB
Rust
Raw Normal View History

2021-02-24 14:12:24 +00:00
use crate as pallet_template;
2022-02-24 18:09:06 +00:00
use frame_support::traits::{ConstU16, ConstU64};
use frame_system as system;
use sp_core::H256;
2020-03-05 16:53:25 +00:00
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
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
2021-02-24 14:12:24 +00:00
impl system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
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;
2022-02-24 18:09:06 +00:00
type BlockHashCount = ConstU64<250>;
2020-03-05 16:53:25 +00:00
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 = ();
2022-02-24 18:09:06 +00:00
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
2022-02-24 18:09:06 +00:00
type MaxConsumers = frame_support::traits::ConstU32<16>;
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()
}