From 80f37f5640219d570fb87f4c92e2cc5be2972446 Mon Sep 17 00:00:00 2001 From: g2udevelopment Date: Tue, 26 Jan 2021 22:16:00 +0100 Subject: [PATCH 1/2] Let tests use construct_runtime --- bin/node-template/pallets/template/Cargo.toml | 3 ++ .../pallets/template/src/mock.rs | 33 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/bin/node-template/pallets/template/Cargo.toml b/bin/node-template/pallets/template/Cargo.toml index f6d69206209e8..d4e6636c64f54 100644 --- a/bin/node-template/pallets/template/Cargo.toml +++ b/bin/node-template/pallets/template/Cargo.toml @@ -15,6 +15,9 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "1.3.6", default-features = false, features = ["derive"] } +[dev-dependencies] +serde = { version = "1.0.101" } + [dependencies.frame-support] default-features = false version = "2.0.0" diff --git a/bin/node-template/pallets/template/src/mock.rs b/bin/node-template/pallets/template/src/mock.rs index 60d22aad7bc66..62be981622223 100644 --- a/bin/node-template/pallets/template/src/mock.rs +++ b/bin/node-template/pallets/template/src/mock.rs @@ -1,19 +1,26 @@ -use crate::{Module, Config}; +use crate as pallet_template; use sp_core::H256; -use frame_support::{impl_outer_origin, parameter_types}; +use frame_support::{parameter_types}; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, testing::Header, }; use frame_system as system; -impl_outer_origin! { - pub enum Origin for Test {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; // 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}, + TemplateModule: pallet_template::{Module, Call, Storage, Event}, + } +); -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; @@ -25,7 +32,7 @@ impl system::Config for Test { type BlockLength = (); type DbWeight = (); type Origin = Origin; - type Call = (); + type Call = Call; type Index = u64; type BlockNumber = u64; type Hash = H256; @@ -33,10 +40,10 @@ impl system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); @@ -44,12 +51,10 @@ impl system::Config for Test { type SS58Prefix = SS58Prefix; } -impl Config for Test { - type Event = (); +impl pallet_template::Config for Test { + type Event = Event; } -pub type TemplateModule = Module; - // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { system::GenesisConfig::default().build_storage::().unwrap().into() From 20f21cad034b01abf37475093c218e023ef9600f Mon Sep 17 00:00:00 2001 From: g2udevelopment Date: Tue, 26 Jan 2021 22:21:16 +0100 Subject: [PATCH 2/2] Fix use --- Cargo.lock | 1 + bin/node-template/pallets/template/src/mock.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c938978802df5..19bb14e0df48f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5056,6 +5056,7 @@ dependencies = [ "frame-support", "frame-system", "parity-scale-codec", + "serde", "sp-core", "sp-io", "sp-runtime", diff --git a/bin/node-template/pallets/template/src/mock.rs b/bin/node-template/pallets/template/src/mock.rs index 62be981622223..d33670f2e9cb0 100644 --- a/bin/node-template/pallets/template/src/mock.rs +++ b/bin/node-template/pallets/template/src/mock.rs @@ -1,6 +1,6 @@ use crate as pallet_template; use sp_core::H256; -use frame_support::{parameter_types}; +use frame_support::parameter_types; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, testing::Header, };