From a3cd8e00d235126ba04d75cf18d751b8a445c0f2 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Mon, 27 Nov 2023 19:15:48 -0500 Subject: [PATCH] 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); + }) +}