Skip to content

Commit

Permalink
Use correct Event type
Browse files Browse the repository at this point in the history
  • Loading branch information
sea212 committed Jan 27, 2023
1 parent 5f0faba commit e199ed9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
6 changes: 0 additions & 6 deletions tokens/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ pub const ID_3: LockIdentifier = *b"3 ";
pub const RID_1: ReserveIdentifier = [1u8; 8];
pub const RID_2: ReserveIdentifier = [2u8; 8];

pub(super) fn events() -> Vec<self::Event> {
let evt = System::events().into_iter().map(|evt| evt.event).collect::<Vec<_>>();
System::reset_events();
evt
}

use crate as tokens;

impl frame_system::Config for Runtime {
Expand Down
32 changes: 19 additions & 13 deletions tokens/src/tests_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ use super::*;
use frame_support::assert_ok;
use mock::*;

fn events() -> Vec<RuntimeEvent> {
let evt = System::events().into_iter().map(|evt| evt.event).collect::<Vec<_>>();
System::reset_events();
evt
}

#[test]
fn pallet_multicurrency_deposit_events() {
ExtBuilder::default()
Expand Down Expand Up @@ -310,23 +316,23 @@ fn pallet_change_locks_events() {

// Locks: [10/DOT]
assert_ok!(Tokens::set_lock(ID_1, DOT, &ALICE, 10));
assert!(events().contains(&Event::Tokens(crate::Event::Locked {
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked {
currency_id: DOT,
who: ALICE,
amount: 10
})));

// Locks: [15/DOT]
assert_ok!(Tokens::set_lock(ID_1, DOT, &ALICE, 15));
assert!(events().contains(&Event::Tokens(crate::Event::Locked {
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked {
currency_id: DOT,
who: ALICE,
amount: 5
})));

// Locks: [15/DOT, 20/BTC]
assert_ok!(Tokens::set_lock(ID_1, BTC, &ALICE, 20));
assert!(events().contains(&Event::Tokens(crate::Event::Locked {
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked {
currency_id: BTC,
who: ALICE,
amount: 20
Expand All @@ -336,8 +342,8 @@ fn pallet_change_locks_events() {
assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 10));
for event in events() {
match event {
Event::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"),
Event::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"),
RuntimeEvent::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"),
RuntimeEvent::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"),
_ => continue,
}
}
Expand All @@ -346,8 +352,8 @@ fn pallet_change_locks_events() {
assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 12));
for event in events() {
match event {
Event::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"),
Event::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"),
RuntimeEvent::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"),
RuntimeEvent::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"),
_ => continue,
}
}
Expand All @@ -356,39 +362,39 @@ fn pallet_change_locks_events() {
assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 10));
for event in events() {
match event {
Event::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"),
Event::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"),
RuntimeEvent::Tokens(crate::Event::Locked { .. }) => assert!(false, "unexpected lock event"),
RuntimeEvent::Tokens(crate::Event::Unlocked { .. }) => assert!(false, "unexpected unlock event"),
_ => continue,
}
}

// Locks: [15/DOT, 20/BTC, 20/DOT]
assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 20));
assert!(events().contains(&Event::Tokens(crate::Event::Locked {
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Locked {
currency_id: DOT,
who: ALICE,
amount: 5
})));

// Locks: [15/DOT, 20/BTC, 16/DOT]
assert_ok!(Tokens::set_lock(ID_2, DOT, &ALICE, 16));
assert!(events().contains(&Event::Tokens(crate::Event::Unlocked {
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Unlocked {
currency_id: DOT,
who: ALICE,
amount: 4
})));

// Locks: [15/DOT, 12/BTC, 16/DOT]
assert_ok!(Tokens::set_lock(ID_1, BTC, &ALICE, 12));
assert!(events().contains(&Event::Tokens(crate::Event::Unlocked {
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Unlocked {
currency_id: BTC,
who: ALICE,
amount: 8
})));

// Locks: [15/DOT, 12/BTC]
assert_ok!(Tokens::remove_lock(ID_2, DOT, &ALICE));
assert!(events().contains(&Event::Tokens(crate::Event::Unlocked {
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::Unlocked {
currency_id: DOT,
who: ALICE,
amount: 1
Expand Down

0 comments on commit e199ed9

Please sign in to comment.