Change assert(is_err()) to assert_noop to check state consistency on errors (#8587)

* Change is_err() asserts in tests to assert_noop to check state consistency

fixes #8545

* Update frame/transaction-payment/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/contracts/src/exec.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update frame/democracy/src/benchmarking.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update frame/transaction-payment/src/lib.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Don't assert no-changing state.

see: https://github.com/paritytech/substrate/pull/8587#issuecomment-817137906

* fix expected error

* Fix non-extrinsic-call asserts

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Falco Hirschenberger
2021-04-13 12:44:27 +02:00
committed by GitHub
parent b9ed6e01b3
commit 24311eee3e
13 changed files with 142 additions and 115 deletions
+10 -8
View File
@@ -19,7 +19,9 @@ use crate::*;
use mock::{*, Origin};
use sp_core::H256;
use sp_runtime::{DispatchError, DispatchErrorWithPostInfo, traits::{Header, BlakeTwo256}};
use frame_support::{assert_noop, weights::WithPostDispatchInfo, dispatch::PostDispatchInfo};
use frame_support::{
assert_noop, assert_ok, weights::WithPostDispatchInfo, dispatch::PostDispatchInfo
};
#[test]
fn origin_works() {
@@ -31,7 +33,7 @@ fn origin_works() {
#[test]
fn stored_map_works() {
new_test_ext().execute_with(|| {
assert!(System::insert(&0, 42).is_ok());
assert_ok!(System::insert(&0, 42));
assert!(!System::is_provider_required(&0));
assert_eq!(Account::<Test>::get(0), AccountInfo {
@@ -42,17 +44,17 @@ fn stored_map_works() {
data: 42,
});
assert!(System::inc_consumers(&0).is_ok());
assert_ok!(System::inc_consumers(&0));
assert!(System::is_provider_required(&0));
assert!(System::insert(&0, 69).is_ok());
assert_ok!(System::insert(&0, 69));
assert!(System::is_provider_required(&0));
System::dec_consumers(&0);
assert!(!System::is_provider_required(&0));
assert!(KILLED.with(|r| r.borrow().is_empty()));
assert!(System::remove(&0).is_ok());
assert_ok!(System::remove(&0));
assert_eq!(KILLED.with(|r| r.borrow().clone()), vec![0u64]);
});
}
@@ -122,7 +124,7 @@ fn sufficient_cannot_support_consumer() {
assert_noop!(System::inc_consumers(&0), IncRefError::NoProviders);
assert_eq!(System::inc_providers(&0), IncRefStatus::Existed);
assert!(System::inc_consumers(&0).is_ok());
assert_ok!(System::inc_consumers(&0));
assert_noop!(System::dec_providers(&0), DecRefError::ConsumerRemaining);
});
}
@@ -140,7 +142,7 @@ fn provider_required_to_support_consumer() {
assert_eq!(System::dec_providers(&0).unwrap(), DecRefStatus::Exists);
assert_eq!(System::account_nonce(&0), 1);
assert!(System::inc_consumers(&0).is_ok());
assert_ok!(System::inc_consumers(&0));
assert_noop!(System::dec_providers(&0), DecRefError::ConsumerRemaining);
System::dec_consumers(&0);
@@ -516,7 +518,7 @@ fn ensure_one_of_works() {
assert_eq!(ensure_root_or_signed(RawOrigin::Root).unwrap(), Either::Left(()));
assert_eq!(ensure_root_or_signed(RawOrigin::Signed(0)).unwrap(), Either::Right(0));
assert!(ensure_root_or_signed(RawOrigin::None).is_err())
assert!(ensure_root_or_signed(RawOrigin::None).is_err());
}
#[test]