mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 19:17:58 +00:00
970354cecc
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.
28 lines
859 B
Rust
28 lines
859 B
Rust
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());
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn correct_error_for_none_value() {
|
|
new_test_ext().execute_with(|| {
|
|
// Ensure the expected error is thrown when no value is present.
|
|
assert_noop!(
|
|
TemplateModule::cause_error(RuntimeOrigin::signed(1)),
|
|
Error::<Test>::NoneValue
|
|
);
|
|
});
|
|
}
|