Skip to content

Commit

Permalink
Properly run on_runtime_upgrade in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Nov 20, 2024
1 parent 7e49225 commit c5d8330
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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 }

[features]
default = ["std"]
std = [
"codec/std",
"frame-executive/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic =
frame_support::sp_runtime::testing::TestXt<RuntimeCall, frame_system::CheckEra<Test>>;
type Block = frame_support::sp_runtime::testing::Block<UncheckedExtrinsic>;

frame_support::construct_runtime!(
pub struct Test
Expand Down Expand Up @@ -144,3 +146,12 @@ impl pallet_balanced_currency_swap_bridges_initializer::Config for Test {
type ForceRebalanceAskCounter = ConstU16<FORCE_REBALANCE_ASK_COUNTER>;
type WeightInfo = ();
}

pub(crate) type Executive = frame_executive::Executive<
Test,
Block,
frame_system::ChainContext<Test>,
Test,
AllPalletsWithSystem,
UpgradeInit<Test>,
>;
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic =
frame_support::sp_runtime::testing::TestXt<RuntimeCall, frame_system::CheckEra<Test>>;
type Block = frame_support::sp_runtime::testing::Block<UncheckedExtrinsic>;

frame_support::construct_runtime!(
pub struct Test
Expand Down Expand Up @@ -144,3 +146,12 @@ impl pallet_balanced_currency_swap_bridges_initializer::Config for Test {
type ForceRebalanceAskCounter = ConstU16<FORCE_REBALANCE_ASK_COUNTER>;
type WeightInfo = ();
}

pub(crate) type Executive = frame_executive::Executive<
Test,
Block,
frame_system::ChainContext<Test>,
Test,
AllPalletsWithSystem,
UpgradeInit<Test>,
>;
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -411,7 +408,7 @@ fn runtime_upgrade() {
assert_eq!(<LastForceRebalanceAskCounter<v1::Test>>::get(), 0);

// Do runtime upgrade hook.
UpgradeInit::<v1::Test>::on_runtime_upgrade();
v1::Executive::execute_on_runtime_upgrade();

// Verify bridges initialization result.
assert_eq!(
Expand Down Expand Up @@ -457,7 +454,7 @@ fn runtime_upgrade() {
v2::EvmBalances::total_balance(&v2::SwapBridgeEvmToNativePot::account_id());

// Do runtime upgrade hook.
UpgradeInit::<v2::Test>::on_runtime_upgrade();
v2::Executive::execute_on_runtime_upgrade();

// Verify result.
assert_eq!(
Expand Down
3 changes: 3 additions & 0 deletions crates/pallet-dummy-precompiles-code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -25,6 +26,7 @@ default = ["std"]
std = [
"codec/std",
"fp-evm/std",
"frame-executive/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
Expand All @@ -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",
Expand Down
16 changes: 13 additions & 3 deletions crates/pallet-dummy-precompiles-code/src/mock/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic =
frame_support::sp_runtime::testing::TestXt<RuntimeCall, frame_system::CheckEra<Test>>;
type Block = frame_support::sp_runtime::testing::Block<UncheckedExtrinsic>;

pub(crate) type AccountId = u64;
pub(crate) type EvmAccountId = H160;
Expand Down Expand Up @@ -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>,
Test,
AllPalletsWithSystem,
UpgradeInit<Test>,
>;
8 changes: 3 additions & 5 deletions crates/pallet-dummy-precompiles-code/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -46,8 +44,8 @@ fn runtime_upgrade() {
0
);

// Do runtime upgrade hook.
UpgradeInit::<v1::Test>::on_runtime_upgrade();
// // Do runtime upgrade hook.
v1::Executive::execute_on_runtime_upgrade();

// Verify precompiles addresses creation.
for precompile_address in &v1::PrecompilesAddresses::get() {
Expand Down

0 comments on commit c5d8330

Please sign in to comment.