Let mock in pallet-template use construct_runtime (#7991)

This commit is contained in:
Gerben van de Wiel
2021-01-27 11:49:44 +01:00
committed by GitHub
parent 12fe61a965
commit 993b74c909
3 changed files with 23 additions and 14 deletions
+1
View File
@@ -5056,6 +5056,7 @@ dependencies = [
"frame-support", "frame-support",
"frame-system", "frame-system",
"parity-scale-codec", "parity-scale-codec",
"serde",
"sp-core", "sp-core",
"sp-io", "sp-io",
"sp-runtime", "sp-runtime",
@@ -15,6 +15,9 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies] [dependencies]
codec = { package = "parity-scale-codec", version = "1.3.6", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "1.3.6", default-features = false, features = ["derive"] }
[dev-dependencies]
serde = { version = "1.0.101" }
[dependencies.frame-support] [dependencies.frame-support]
default-features = false default-features = false
version = "2.0.0" version = "2.0.0"
@@ -1,19 +1,26 @@
use crate::{Module, Config}; use crate as pallet_template;
use sp_core::H256; use sp_core::H256;
use frame_support::{impl_outer_origin, parameter_types}; use frame_support::parameter_types;
use sp_runtime::{ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup}, testing::Header, traits::{BlakeTwo256, IdentityLookup}, testing::Header,
}; };
use frame_system as system; use frame_system as system;
impl_outer_origin! { type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
pub enum Origin for Test {} type Block = frame_system::mocking::MockBlock<Test>;
}
// Configure a mock runtime to test the pallet. // Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
TemplateModule: pallet_template::{Module, Call, Storage, Event<T>},
}
);
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! { parameter_types! {
pub const BlockHashCount: u64 = 250; pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 42; pub const SS58Prefix: u8 = 42;
@@ -25,7 +32,7 @@ impl system::Config for Test {
type BlockLength = (); type BlockLength = ();
type DbWeight = (); type DbWeight = ();
type Origin = Origin; type Origin = Origin;
type Call = (); type Call = Call;
type Index = u64; type Index = u64;
type BlockNumber = u64; type BlockNumber = u64;
type Hash = H256; type Hash = H256;
@@ -33,10 +40,10 @@ impl system::Config for Test {
type AccountId = u64; type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>; type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header; type Header = Header;
type Event = (); type Event = Event;
type BlockHashCount = BlockHashCount; type BlockHashCount = BlockHashCount;
type Version = (); type Version = ();
type PalletInfo = (); type PalletInfo = PalletInfo;
type AccountData = (); type AccountData = ();
type OnNewAccount = (); type OnNewAccount = ();
type OnKilledAccount = (); type OnKilledAccount = ();
@@ -44,12 +51,10 @@ impl system::Config for Test {
type SS58Prefix = SS58Prefix; type SS58Prefix = SS58Prefix;
} }
impl Config for Test { impl pallet_template::Config for Test {
type Event = (); type Event = Event;
} }
pub type TemplateModule = Module<Test>;
// Build genesis storage according to the mock runtime. // Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities { pub fn new_test_ext() -> sp_io::TestExternalities {
system::GenesisConfig::default().build_storage::<Test>().unwrap().into() system::GenesisConfig::default().build_storage::<Test>().unwrap().into()