Skip to content

Commit

Permalink
Add event testing example to pallet template (paritytech#12722)
Browse files Browse the repository at this point in the history
Add an example of how to test for events into the example pallet. Right now, the information is pretty hard to find without looking into pallet tests or finding some particular posts on the stackoverflow.
  • Loading branch information
elv-nate authored and ark0f committed Feb 27, 2023
1 parent ff58066 commit 0b970c1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/node-template/pallets/template/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::{mock::*, Error};
use crate::{mock::*, Error, Event};
use frame_support::{assert_noop, assert_ok};

#[test]
fn it_works_for_default_value() {
new_test_ext().execute_with(|| {
// Go past genesis block so events get deposited
System::set_block_number(1);
// Dispatch a signed extrinsic.
assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42));
// Read pallet storage and assert an expected result.
assert_eq!(TemplateModule::something(), Some(42));
// Assert that the correct event was deposited
System::assert_last_event(Event::SomethingStored { something: 42, who: 1 }.into());
});
}

Expand Down

0 comments on commit 0b970c1

Please sign in to comment.