mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 16:51:03 +00:00
Add execute_with to TestExternalities (#3793)
This function executes the given closure in a context where the test externalities are set. This makes the srml tests easier to write, as the test externalities need to be created anyway.
This commit is contained in:
@@ -24,11 +24,10 @@ use crate::mock::{
|
||||
offence_reports,
|
||||
};
|
||||
use system::{EventRecord, Phase};
|
||||
use sr_primitives::set_and_run_with_externalities;
|
||||
|
||||
#[test]
|
||||
fn should_report_an_authority_and_trigger_on_offence() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// given
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
@@ -51,7 +50,7 @@ fn should_report_an_authority_and_trigger_on_offence() {
|
||||
|
||||
#[test]
|
||||
fn should_calculate_the_fraction_correctly() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// given
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
@@ -83,7 +82,7 @@ fn should_calculate_the_fraction_correctly() {
|
||||
|
||||
#[test]
|
||||
fn should_not_report_the_same_authority_twice_in_the_same_slot() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// given
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
@@ -113,7 +112,7 @@ fn should_not_report_the_same_authority_twice_in_the_same_slot() {
|
||||
|
||||
#[test]
|
||||
fn should_report_in_different_time_slot() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// given
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
@@ -143,7 +142,7 @@ fn should_report_in_different_time_slot() {
|
||||
|
||||
#[test]
|
||||
fn should_deposit_event() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// given
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
@@ -171,7 +170,7 @@ fn should_deposit_event() {
|
||||
|
||||
#[test]
|
||||
fn doesnt_deposit_event_for_dups() {
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// given
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
@@ -208,7 +207,7 @@ fn doesnt_deposit_event_for_dups() {
|
||||
fn should_properly_count_offences() {
|
||||
// We report two different authorities for the same issue. Ultimately, the 1st authority
|
||||
// should have `count` equal 2 and the count of the 2nd one should be equal to 1.
|
||||
set_and_run_with_externalities(&mut new_test_ext(), || {
|
||||
new_test_ext().execute_with(|| {
|
||||
// given
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
Reference in New Issue
Block a user