From a3cd8e00d235126ba04d75cf18d751b8a445c0f2 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Mon, 27 Nov 2023 19:15:48 -0500 Subject: [PATCH 1/4] init --- Cargo.lock | 1 + runtime/Cargo.toml | 4 ++++ runtime/tests/common/mod.rs | 15 +++++++++++++++ runtime/tests/fee.rs | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 runtime/tests/common/mod.rs create mode 100644 runtime/tests/fee.rs diff --git a/Cargo.lock b/Cargo.lock index 1b34d10..1379c12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7401,6 +7401,7 @@ dependencies = [ "sp-core", "sp-genesis-builder", "sp-inherents", + "sp-io", "sp-offchain", "sp-runtime", "sp-session", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index e165a39..6f33f25 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -81,6 +81,9 @@ cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false } parachain-info = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false } +[dev-dependencies] +sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0" } + [features] default = ["std"] std = [ @@ -99,6 +102,7 @@ std = [ "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", "frame-system/std", + "pallet-proxy/std", "frame-try-runtime?/std", "log/std", "pallet-aura/std", diff --git a/runtime/tests/common/mod.rs b/runtime/tests/common/mod.rs new file mode 100644 index 0000000..4a022bd --- /dev/null +++ b/runtime/tests/common/mod.rs @@ -0,0 +1,15 @@ +// ExtBuilder impl for all runtime integration tests +use frame_support::weights::Weight; +use parachain_template_runtime::{BuildStorage, Runtime, System}; + +pub fn run_with_system_weight(w: Weight, mut assertions: F) +where + F: FnMut() -> (), +{ + let mut t: sp_io::TestExternalities = + frame_system::GenesisConfig::::default().build_storage().unwrap().into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); +} \ No newline at end of file diff --git a/runtime/tests/fee.rs b/runtime/tests/fee.rs new file mode 100644 index 0000000..f6a0474 --- /dev/null +++ b/runtime/tests/fee.rs @@ -0,0 +1,22 @@ +// Integration transaction fee tests i.e. adjusts to block saturation +mod common; +use common::*; +use frame_support::pallet_prelude::*; +use parachain_template_runtime::{Runtime, RuntimeBlockWeights}; +use polkadot_runtime_common::MinimumMultiplier; +use sp_runtime::{traits::Convert, Perquintill}; + +#[test] +fn multiplier_can_grow_from_zero() { + let minimum_multiplier = MinimumMultiplier::get(); + let target = Perquintill::from_percent(25) + * RuntimeBlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target * 101 / 100, || { + let next = ::FeeMultiplierUpdate::convert( + minimum_multiplier, + ); + assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier); + }) +} From dec935addd279496cccf8553a24324f5f5ce725f Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Tue, 28 Nov 2023 15:55:29 -0500 Subject: [PATCH 2/4] minimal runtime integration tests --- runtime/tests/common/mod.rs | 2 +- runtime/tests/fee.rs | 22 ------------------ runtime/tests/multiplier.rs | 46 +++++++++++++++++++++++++++++++++++++ runtime/tests/storage.rs | 34 +++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 23 deletions(-) delete mode 100644 runtime/tests/fee.rs create mode 100644 runtime/tests/multiplier.rs create mode 100644 runtime/tests/storage.rs diff --git a/runtime/tests/common/mod.rs b/runtime/tests/common/mod.rs index 4a022bd..4fe99c3 100644 --- a/runtime/tests/common/mod.rs +++ b/runtime/tests/common/mod.rs @@ -12,4 +12,4 @@ where System::set_block_consumed_resources(w, 0); assertions() }); -} \ No newline at end of file +} diff --git a/runtime/tests/fee.rs b/runtime/tests/fee.rs deleted file mode 100644 index f6a0474..0000000 --- a/runtime/tests/fee.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Integration transaction fee tests i.e. adjusts to block saturation -mod common; -use common::*; -use frame_support::pallet_prelude::*; -use parachain_template_runtime::{Runtime, RuntimeBlockWeights}; -use polkadot_runtime_common::MinimumMultiplier; -use sp_runtime::{traits::Convert, Perquintill}; - -#[test] -fn multiplier_can_grow_from_zero() { - let minimum_multiplier = MinimumMultiplier::get(); - let target = Perquintill::from_percent(25) - * RuntimeBlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); - // if the min is too small, then this will not change, and we are doomed forever. - // the weight is 1/100th bigger than target. - run_with_system_weight(target * 101 / 100, || { - let next = ::FeeMultiplierUpdate::convert( - minimum_multiplier, - ); - assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier); - }) -} diff --git a/runtime/tests/multiplier.rs b/runtime/tests/multiplier.rs new file mode 100644 index 0000000..bd5e9a8 --- /dev/null +++ b/runtime/tests/multiplier.rs @@ -0,0 +1,46 @@ +// Integration transaction weight-fee tests +mod common; +use common::*; +use frame_support::pallet_prelude::*; +use pallet_transaction_payment::Multiplier; +use parachain_template_runtime::{Runtime, RuntimeBlockWeights}; +use polkadot_runtime_common::MinimumMultiplier; +use sp_runtime::{traits::Convert, Perquintill}; + +fn min_multiplier() -> Multiplier { + MinimumMultiplier::get() +} + +fn target() -> Weight { + Perquintill::from_percent(25) + * RuntimeBlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() +} + +fn runtime_multiplier_update(fm: Multiplier) -> Multiplier { + ::FeeMultiplierUpdate::convert(fm) +} + +#[test] +fn multiplier_can_grow_from_zero() { + // if the min is too small, then this will not change, and we are doomed forever. + // the block ref time is 1/100th bigger than target. + run_with_system_weight(target().set_ref_time(target().ref_time() * 101 / 100), || { + let next = runtime_multiplier_update(min_multiplier()); + assert!(next > min_multiplier(), "{:?} !> {:?}", next, min_multiplier()); + }); + + // the block proof size is 1/100th bigger than target. + run_with_system_weight(target().set_proof_size((target().proof_size() / 100) * 101), || { + let next = runtime_multiplier_update(min_multiplier()); + assert!(next > min_multiplier(), "{:?} !> {:?}", next, min_multiplier()); + }) +} + +#[test] +fn multiplier_cannot_go_below_limit() { + // will not go any further below even if block is empty. + run_with_system_weight(Weight::zero(), || { + let next = runtime_multiplier_update(min_multiplier()); + assert_eq!(next, min_multiplier()); + }) +} diff --git a/runtime/tests/storage.rs b/runtime/tests/storage.rs new file mode 100644 index 0000000..24ec4f5 --- /dev/null +++ b/runtime/tests/storage.rs @@ -0,0 +1,34 @@ +// Storage indices integration checks +use frame_support::traits::PalletInfo; +use parachain_template_runtime::{ + Aura, AuraExt, Authorship, Balances, CollatorSelection, CumulusXcm, DmpQueue, Multisig, + ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, Runtime, Session, Sudo, System, + TemplatePallet, Timestamp, TransactionPayment, XcmpQueue, +}; + +fn assert_pallet_prefix(name: &str) { + assert_eq!(::PalletInfo::name::

(), Some(name)); +} + +#[test] +fn verify_pallet_prefixes() { + assert_pallet_prefix::("System"); + assert_pallet_prefix::("ParachainSystem"); + assert_pallet_prefix::("Timestamp"); + assert_pallet_prefix::("ParachainInfo"); + assert_pallet_prefix::("Proxy"); + assert_pallet_prefix::("Balances"); + assert_pallet_prefix::("TransactionPayment"); + assert_pallet_prefix::("Sudo"); + assert_pallet_prefix::("Multisig"); + assert_pallet_prefix::("Authorship"); + assert_pallet_prefix::("CollatorSelection"); + assert_pallet_prefix::("Session"); + assert_pallet_prefix::("Aura"); + assert_pallet_prefix::("AuraExt"); + assert_pallet_prefix::("XcmpQueue"); + assert_pallet_prefix::("PolkadotXcm"); + assert_pallet_prefix::("CumulusXcm"); + assert_pallet_prefix::("DmpQueue"); + assert_pallet_prefix::("TemplatePallet"); +} From 40da7151381d877beaa683880e08c8ecd73c0ea6 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Tue, 28 Nov 2023 16:17:27 -0500 Subject: [PATCH 3/4] clippy fmt --- runtime/tests/common/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/runtime/tests/common/mod.rs b/runtime/tests/common/mod.rs index 4fe99c3..a5f4fe8 100644 --- a/runtime/tests/common/mod.rs +++ b/runtime/tests/common/mod.rs @@ -2,10 +2,7 @@ use frame_support::weights::Weight; use parachain_template_runtime::{BuildStorage, Runtime, System}; -pub fn run_with_system_weight(w: Weight, mut assertions: F) -where - F: FnMut() -> (), -{ +pub fn run_with_system_weight(w: Weight, mut assertions: F) { let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default().build_storage().unwrap().into(); t.execute_with(|| { From 162ffc38149c62aee6cb8ae341d3268324ac8c2f Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 30 Nov 2023 19:45:47 -0500 Subject: [PATCH 4/4] removing fix for pallet proxy bug to not confuse reviewers --- runtime/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 6f33f25..2bd839f 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -102,7 +102,6 @@ std = [ "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", "frame-system/std", - "pallet-proxy/std", "frame-try-runtime?/std", "log/std", "pallet-aura/std",