From c5d8330e6ddcb8656448245205b0a30838c49f6a Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Wed, 13 Nov 2024 16:28:43 +0300 Subject: [PATCH] Properly run on_runtime_upgrade in tests --- Cargo.lock | 2 ++ .../Cargo.toml | 3 +++ .../src/mock/v1.rs | 15 +++++++++++++-- .../src/mock/v2.rs | 15 +++++++++++++-- .../src/tests.rs | 11 ++++------- crates/pallet-dummy-precompiles-code/Cargo.toml | 3 +++ .../pallet-dummy-precompiles-code/src/mock/v1.rs | 16 +++++++++++++--- .../pallet-dummy-precompiles-code/src/tests.rs | 8 +++----- 8 files changed, 54 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c68c9bc6..1788d73c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6333,6 +6333,7 @@ dependencies = [ name = "pallet-balanced-currency-swap-bridges-initializer" version = "0.1.0" dependencies = [ + "frame-executive", "frame-support", "frame-system", "pallet-balances", @@ -6437,6 +6438,7 @@ name = "pallet-dummy-precompiles-code" version = "0.1.0" dependencies = [ "fp-evm", + "frame-executive", "frame-support", "frame-system", "hex-literal", diff --git a/crates/pallet-balanced-currency-swap-bridges-initializer/Cargo.toml b/crates/pallet-balanced-currency-swap-bridges-initializer/Cargo.toml index 46ae19a2a..fcb1084c9 100644 --- a/crates/pallet-balanced-currency-swap-bridges-initializer/Cargo.toml +++ b/crates/pallet-balanced-currency-swap-bridges-initializer/Cargo.toml @@ -14,6 +14,7 @@ sp-std = { workspace = true } [dev-dependencies] pallet-pot = { path = "../pallet-pot", default-features = false } +frame-executive = { workspace = true } pallet-balances = { workspace = true } sp-core = { workspace = true } @@ -21,6 +22,7 @@ sp-core = { workspace = true } default = ["std"] std = [ "codec/std", + "frame-executive/std", "frame-support/std", "frame-system/std", "pallet-balances/std", @@ -30,6 +32,7 @@ std = [ "sp-std/std", ] try-runtime = [ + "frame-executive/try-runtime", "frame-support/try-runtime", "frame-system/try-runtime", "pallet-balances/try-runtime", diff --git a/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v1.rs b/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v1.rs index 86dda9d63..9f1585183 100644 --- a/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v1.rs +++ b/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v1.rs @@ -15,11 +15,13 @@ use frame_support::{ use sp_core::{ConstU16, H256}; use super::*; +use crate::UpgradeInit; pub(crate) const FORCE_REBALANCE_ASK_COUNTER: u16 = 0; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = + frame_support::sp_runtime::testing::TestXt>; +type Block = frame_support::sp_runtime::testing::Block; frame_support::construct_runtime!( pub struct Test @@ -144,3 +146,12 @@ impl pallet_balanced_currency_swap_bridges_initializer::Config for Test { type ForceRebalanceAskCounter = ConstU16; type WeightInfo = (); } + +pub(crate) type Executive = frame_executive::Executive< + Test, + Block, + frame_system::ChainContext, + Test, + AllPalletsWithSystem, + UpgradeInit, +>; diff --git a/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v2.rs b/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v2.rs index 439e0c67d..e6e0c4e50 100644 --- a/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v2.rs +++ b/crates/pallet-balanced-currency-swap-bridges-initializer/src/mock/v2.rs @@ -17,9 +17,11 @@ use sp_core::{ConstU16, H256}; pub(crate) const FORCE_REBALANCE_ASK_COUNTER: u16 = 1; use super::*; +use crate::UpgradeInit; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = + frame_support::sp_runtime::testing::TestXt>; +type Block = frame_support::sp_runtime::testing::Block; frame_support::construct_runtime!( pub struct Test @@ -144,3 +146,12 @@ impl pallet_balanced_currency_swap_bridges_initializer::Config for Test { type ForceRebalanceAskCounter = ConstU16; type WeightInfo = (); } + +pub(crate) type Executive = frame_executive::Executive< + Test, + Block, + frame_system::ChainContext, + Test, + AllPalletsWithSystem, + UpgradeInit, +>; diff --git a/crates/pallet-balanced-currency-swap-bridges-initializer/src/tests.rs b/crates/pallet-balanced-currency-swap-bridges-initializer/src/tests.rs index ce6be6787..d3640ffc7 100644 --- a/crates/pallet-balanced-currency-swap-bridges-initializer/src/tests.rs +++ b/crates/pallet-balanced-currency-swap-bridges-initializer/src/tests.rs @@ -1,11 +1,8 @@ -use frame_support::{ - assert_storage_noop, - traits::{Currency, OnRuntimeUpgrade}, -}; +use frame_support::{assert_storage_noop, traits::Currency}; use crate::{ mock::{new_test_ext_with, v0, v1, v2, with_runtime_lock, *}, - swappable_balance, LastForceRebalanceAskCounter, LastInitializerVersion, UpgradeInit, + swappable_balance, LastForceRebalanceAskCounter, LastInitializerVersion, }; /// This test verifies that balanced bridges initialization works in case bridge pot accounts @@ -411,7 +408,7 @@ fn runtime_upgrade() { assert_eq!(>::get(), 0); // Do runtime upgrade hook. - UpgradeInit::::on_runtime_upgrade(); + v1::Executive::execute_on_runtime_upgrade(); // Verify bridges initialization result. assert_eq!( @@ -457,7 +454,7 @@ fn runtime_upgrade() { v2::EvmBalances::total_balance(&v2::SwapBridgeEvmToNativePot::account_id()); // Do runtime upgrade hook. - UpgradeInit::::on_runtime_upgrade(); + v2::Executive::execute_on_runtime_upgrade(); // Verify result. assert_eq!( diff --git a/crates/pallet-dummy-precompiles-code/Cargo.toml b/crates/pallet-dummy-precompiles-code/Cargo.toml index dcc0163c5..2aefec4ea 100644 --- a/crates/pallet-dummy-precompiles-code/Cargo.toml +++ b/crates/pallet-dummy-precompiles-code/Cargo.toml @@ -14,6 +14,7 @@ sp-core = { workspace = true } [dev-dependencies] fp-evm = { workspace = true } +frame-executive = { workspace = true } hex-literal = { workspace = true } pallet-balances = { workspace = true, features = ["default"] } pallet-evm-balances = { workspace = true, features = ["default"] } @@ -25,6 +26,7 @@ default = ["std"] std = [ "codec/std", "fp-evm/std", + "frame-executive/std", "frame-support/std", "frame-system/std", "pallet-balances/std", @@ -36,6 +38,7 @@ std = [ "sp-core/std", ] try-runtime = [ + "frame-executive/try-runtime", "frame-support/try-runtime", "frame-system/try-runtime", "pallet-balances/try-runtime", diff --git a/crates/pallet-dummy-precompiles-code/src/mock/v1.rs b/crates/pallet-dummy-precompiles-code/src/mock/v1.rs index 4f4e069b7..3109b5cd9 100644 --- a/crates/pallet-dummy-precompiles-code/src/mock/v1.rs +++ b/crates/pallet-dummy-precompiles-code/src/mock/v1.rs @@ -15,10 +15,11 @@ use frame_support::{ use sp_core::{ConstU16, H256, U256}; use super::*; -use crate::{self as pallet_dummy_precompiles_code}; +use crate::{self as pallet_dummy_precompiles_code, UpgradeInit}; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = + frame_support::sp_runtime::testing::TestXt>; +type Block = frame_support::sp_runtime::testing::Block; pub(crate) type AccountId = u64; pub(crate) type EvmAccountId = H160; @@ -165,3 +166,12 @@ impl pallet_dummy_precompiles_code::Config for Test { type PrecompilesAddresses = PrecompilesAddresses; type ForceExecuteAskCounter = ConstU16<0>; } + +pub(crate) type Executive = frame_executive::Executive< + Test, + Block, + frame_system::ChainContext, + Test, + AllPalletsWithSystem, + UpgradeInit, +>; diff --git a/crates/pallet-dummy-precompiles-code/src/tests.rs b/crates/pallet-dummy-precompiles-code/src/tests.rs index 678a22ba7..4f565e3c8 100644 --- a/crates/pallet-dummy-precompiles-code/src/tests.rs +++ b/crates/pallet-dummy-precompiles-code/src/tests.rs @@ -1,6 +1,4 @@ -use frame_support::traits::OnRuntimeUpgrade; - -use crate::{mock::*, UpgradeInit, DUMMY_CODE}; +use crate::{mock::*, DUMMY_CODE}; /// This test verifies that genesis initialization properly assigns the state. #[test] @@ -46,8 +44,8 @@ fn runtime_upgrade() { 0 ); - // Do runtime upgrade hook. - UpgradeInit::::on_runtime_upgrade(); + // // Do runtime upgrade hook. + v1::Executive::execute_on_runtime_upgrade(); // Verify precompiles addresses creation. for precompile_address in &v1::PrecompilesAddresses::get() {