This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce18db0
commit af72f2e
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "simple-event" | ||
version = "3.0.0" | ||
edition = "2018" | ||
authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>'] | ||
repository = 'https://github.com/substrate-developer-hub/recipes' | ||
description = "A pallet that emits simple events that do not encapsulate generic data types" | ||
license = "GPL-3.0-or-later" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ['x86_64-unknown-linux-gnu'] | ||
|
||
[dependencies] | ||
frame-support = { default-features = false, version = '3.0.0' } | ||
frame-system = { default-features = false, version = '3.0.0' } | ||
|
||
# Substrate packages | ||
sp-runtime = { version = '3.0', default-features = false } | ||
|
||
[dependencies.codec] | ||
default-features = false | ||
features = ['derive'] | ||
package = 'parity-scale-codec' | ||
version = '2.0.0' | ||
|
||
[dev-dependencies] | ||
serde = { version = "1.0.119" } | ||
sp-core = { default-features = false, version = '3.0.0' } | ||
sp-io = { default-features = false, version = '3.0.0' } | ||
sp-runtime = { default-features = false, version = '3.0.0' } | ||
|
||
[features] | ||
default = ['std'] | ||
std = [ | ||
'frame-support/std', | ||
'frame-system/std', | ||
'sp-runtime/std', | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use crate as simple_event; | ||
use frame_support::{assert_ok, parameter_types}; | ||
use sp_core::H256; | ||
|
||
use sp_io::TestExternalities; | ||
|
||
use sp_runtime::{ | ||
testing::Header, | ||
traits::{BlakeTwo256, IdentityLookup}, | ||
}; | ||
|
||
use frame_system as system; | ||
use frame_system::{EventRecord, Phase}; | ||
|
||
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>}, | ||
SimpleEvent: simple_event::{Module, Call, Storage, Event<T>}, | ||
} | ||
); | ||
|
||
parameter_types! { | ||
pub const BlockHashCount: u64 = 250; | ||
pub const SS58Prefix: u8 = 42; | ||
} | ||
|
||
impl system::Config for Test { | ||
type BaseCallFilter = (); | ||
type BlockWeights = (); | ||
type BlockLength = (); | ||
type DbWeight = (); | ||
type Origin = Origin; | ||
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 = Event; | ||
type BlockHashCount = BlockHashCount; | ||
type Version = (); | ||
type PalletInfo = PalletInfo; | ||
type AccountData = (); | ||
type OnNewAccount = (); | ||
type OnKilledAccount = (); | ||
type SystemWeightInfo = (); | ||
type SS58Prefix = SS58Prefix; | ||
} | ||
|
||
impl simple_event::Config for Test { | ||
type Event = Event; | ||
} | ||
|
||
struct ExternalityBuilder; | ||
|
||
impl ExternalityBuilder { | ||
pub fn build() -> TestExternalities { | ||
let storage = frame_system::GenesisConfig::default() | ||
.build_storage::<Test>() | ||
.unwrap(); | ||
let mut ext = TestExternalities::from(storage); | ||
ext.execute_with(|| System::set_block_number(1)); | ||
ext | ||
} | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
ExternalityBuilder::build().execute_with(|| { | ||
assert_ok!(SimpleEvent::do_something(Origin::signed(1), 32)); | ||
|
||
assert_eq!( | ||
System::events(), | ||
vec![EventRecord { | ||
phase: Phase::Initialization, | ||
event: Event::simple_event(simple_event::Event::EmitInput(32)), | ||
topics: vec![], | ||
}] | ||
); | ||
}) | ||
} |