Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Let mock in pallet-template use construct_runtime #7991

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bin/node-template/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 19 additions & 14 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
@@ -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<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// 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! {
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 42;
Expand All @@ -25,31 +32,29 @@ 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;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
}

impl Config for Test {
type Event = ();
impl pallet_template::Config for Test {
type Event = Event;
}

pub type TemplateModule = Module<Test>;

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
Expand Down