Skip to content

Commit

Permalink
chore: move whitelist test to better place and add missing `Inactive …
Browse files Browse the repository at this point in the history
…Issuance` (paritytech#14130)

* chore: move whitelist test to better palace and add missing `Inactive Issuance`

* remove duplicated

---------

Co-authored-by: parity-processbot <>
  • Loading branch information
yjhmelody authored May 17, 2023
1 parent 6507a79 commit f4a2e84
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 76 deletions.
37 changes: 0 additions & 37 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,40 +573,3 @@ impl_runtime_apis! {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use frame_support::traits::WhitelistedStorageKeys;
use sp_core::hexdisplay::HexDisplay;
use std::collections::HashSet;

#[test]
fn check_whitelist() {
let whitelist: HashSet<String> = AllPalletsWithSystem::whitelisted_storage_keys()
.iter()
.map(|e| HexDisplay::from(&e.key).to_string())
.collect();

// Block Number
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac")
);
// Total Issuance
assert!(
whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80")
);
// Execution Phase
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a")
);
// Event Count
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850")
);
// System Events
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7")
);
}
}
36 changes: 0 additions & 36 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2486,44 +2486,8 @@ impl_runtime_apis! {
mod tests {
use super::*;
use frame_election_provider_support::NposSolution;
use frame_support::traits::WhitelistedStorageKeys;
use frame_system::offchain::CreateSignedTransaction;
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::UpperOf;
use std::collections::HashSet;

#[test]
fn check_whitelist() {
let whitelist: HashSet<String> = AllPalletsWithSystem::whitelisted_storage_keys()
.iter()
.map(|e| HexDisplay::from(&e.key).to_string())
.collect();

// Block Number
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac")
);
// Total Issuance
assert!(
whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80")
);
// Execution Phase
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a")
);
// Event Count
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850")
);
// System Events
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7")
);
// System BlockWeight
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef734abf5cb34d6244378cddbf18e849d96")
);
}

#[test]
fn validate_transaction_submitter_bounds() {
Expand Down
17 changes: 15 additions & 2 deletions frame/balances/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ use frame_support::{
parameter_types,
traits::{
tokens::fungible, ConstU32, ConstU64, ConstU8, Imbalance as ImbalanceT, OnUnbalanced,
StorageMapShim, StoredMap,
StorageMapShim, StoredMap, WhitelistedStorageKeys,
},
weights::{IdentityFee, Weight},
RuntimeDebug,
};
use frame_system::{self as system, RawOrigin};
use pallet_transaction_payment::{ChargeTransactionPayment, CurrencyAdapter, Multiplier};
use scale_info::TypeInfo;
use sp_core::H256;
use sp_core::{hexdisplay::HexDisplay, H256};
use sp_io;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, IdentityLookup, SignedExtension, Zero},
ArithmeticError, DispatchError, DispatchResult, FixedPointNumber, TokenError,
};
use std::collections::BTreeSet;

mod currency_tests;
mod dispatchable_tests;
Expand Down Expand Up @@ -304,3 +305,15 @@ fn weights_sane() {
let info = crate::Call::<Test>::force_unreserve { who: 10, amount: 4 }.get_dispatch_info();
assert_eq!(<() as crate::WeightInfo>::force_unreserve(), info.weight);
}

#[test]
fn check_whitelist() {
let whitelist: BTreeSet<String> = AllPalletsWithSystem::whitelisted_storage_keys()
.iter()
.map(|s| HexDisplay::from(&s.key).to_string())
.collect();
// Inactive Issuance
assert!(whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f1ccde6872881f893a21de93dfe970cd5"));
// Total Issuance
assert!(whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80"));
}
24 changes: 23 additions & 1 deletion frame/system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,36 @@ use crate::*;
use frame_support::{
assert_noop, assert_ok,
dispatch::{Pays, PostDispatchInfo, WithPostDispatchInfo},
traits::WhitelistedStorageKeys,
};
use std::collections::BTreeSet;

use mock::{RuntimeOrigin, *};
use sp_core::H256;
use sp_core::{hexdisplay::HexDisplay, H256};
use sp_runtime::{
traits::{BlakeTwo256, Header},
DispatchError, DispatchErrorWithPostInfo,
};

#[test]
fn check_whitelist() {
let whitelist: BTreeSet<String> = AllPalletsWithSystem::whitelisted_storage_keys()
.iter()
.map(|s| HexDisplay::from(&s.key).to_string())
.collect();

// Block Number
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac"));
// Execution Phase
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a"));
// Event Count
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850"));
// System Events
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"));
// System BlockWeight
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef734abf5cb34d6244378cddbf18e849d96"));
}

#[test]
fn origin_works() {
let o = RuntimeOrigin::from(RawOrigin::<u64>::Signed(1u64));
Expand Down

0 comments on commit f4a2e84

Please sign in to comment.