Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration-tests/ahm/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ port RUNTIME SDK FOLDER:
export RUST_BACKTRACE=1
export RUST_LOG="warn"

cargo test -p polkadot-integration-tests-ahm --features "ahm-{{RUNTIME}}" --profile testnet pallet_migration_works -- --nocapture
cargo test -p polkadot-integration-tests-ahm --features "ahm-{{RUNTIME}}" --profile testnet -- --nocapture

code-substitute SDK RUNTIME:
just code-substitute-pallet pallet_proxy {{SDK}}
Expand Down
128 changes: 128 additions & 0 deletions integration-tests/ahm/src/call_filter_asset_hub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Asset Hub Migration tests.

use crate::porting_prelude::*;

use asset_hub_polkadot_runtime::{
AhMigrator, Block, BuildStorage, Runtime as T, RuntimeCall, RuntimeOrigin, System,
};
use cumulus_primitives_core::AggregateMessageOrigin;
use frame_support::{sp_runtime::traits::Dispatchable, traits::Contains};
use pallet_ah_migrator::*;
use polkadot_primitives::Id as ParaId;
use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities};
use sp_runtime::AccountId32;

/// Check that the call filtering mechanism works.
#[test]
#[cfg(not(feature = "ahm-westend"))] // FIXME make work on Westend
fn call_filter_works() {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::<T>::default().build_storage().unwrap().into();

// MQ calls are never filtered:
let mq_call = RuntimeCall::MessageQueue(pallet_message_queue::Call::<T>::reap_page {
message_origin: AggregateMessageOrigin::Here,
page_index: 0,
});
// Balances calls are filtered during the migration:
let balances_call = RuntimeCall::Balances(pallet_balances::Call::<T>::transfer_all {
dest: AccountId32::from([0; 32]).into(),
keep_alive: false,
});
// Indices calls are filtered during and after the migration:
let indices_call = RuntimeCall::Indices(pallet_indices::Call::<T>::claim { index: 0 });

let is_allowed = |call: &RuntimeCall| Pallet::<T>::contains(call);

// Try the BaseCallFilter
t.execute_with(|| {
// Before the migration starts
{
AhMigrationStage::<T>::put(MigrationStage::Pending);

assert!(is_allowed(&mq_call));
assert!(is_allowed(&balances_call));
assert!(is_allowed(&indices_call));
}

// During the migration
{
AhMigrationStage::<T>::put(MigrationStage::DataMigrationOngoing);

assert!(is_allowed(&mq_call));
assert!(!is_allowed(&balances_call));
assert!(!is_allowed(&indices_call));
}

// After the migration
{
AhMigrationStage::<T>::put(MigrationStage::MigrationDone);

assert!(is_allowed(&mq_call));
assert!(is_allowed(&balances_call));
assert!(is_allowed(&indices_call));
}
});

// Try to actually dispatch the calls
t.execute_with(|| {
let _ =
<pallet_balances::Pallet<T> as frame_support::traits::Currency<_>>::deposit_creating(
&AccountId32::from([0; 32]),
u64::MAX.into(),
);

// Before the migration starts
{
AhMigrationStage::<T>::put(MigrationStage::Pending);

assert!(!is_forbidden(&mq_call));
assert!(!is_forbidden(&balances_call));
assert!(!is_forbidden(&indices_call));
}

// During the migration
{
AhMigrationStage::<T>::put(MigrationStage::DataMigrationOngoing);

assert!(!is_forbidden(&mq_call));
assert!(is_forbidden(&balances_call));
assert!(is_forbidden(&indices_call));
}

// After the migration
{
AhMigrationStage::<T>::put(MigrationStage::MigrationDone);

assert!(!is_forbidden(&mq_call));
assert!(!is_forbidden(&balances_call));
assert!(!is_forbidden(&indices_call));
}
});
}

/// Whether a call is forbidden by the call filter.
fn is_forbidden(call: &RuntimeCall) -> bool {
let Err(err) = call.clone().dispatch(RuntimeOrigin::signed(AccountId32::from([0; 32]))) else {
return false;
};

let filtered_err: sp_runtime::DispatchError = frame_system::Error::<T>::CallFiltered.into();
err.error == filtered_err
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,41 @@

//! Asset Hub Migration tests.

mod accounts;
use crate::porting_prelude::*;

use frame_support::{sp_runtime::traits::Dispatchable, traits::Contains};
use pallet_rc_migrator::*;
use polkadot_primitives::Id as ParaId;
use polkadot_runtime::{Block, BuildStorage, RcMigrator, Runtime as T, RuntimeOrigin, System};
use polkadot_runtime::{
Block, BuildStorage, RcMigrator, Runtime as T, RuntimeCall, RuntimeOrigin, System,
};
use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities};
use runtime_parachains::inclusion::AggregateMessageOrigin;
use sp_runtime::AccountId32;

/// Create externalities that have their state initialized from a snapshot.
///
/// The path to the snapshot must be provided through the environment variable `SNAP`. If if is not
/// set, this function will return `None`.
///
/// You can create such a snapshot with the [`try-runtime-cli`](https://github.com/paritytech/try-runtime-cli). For example:
/// `try-runtime create-snapshot --uri wss://rpc.polkadot.io:443 polkadot.snap`.
async fn remote_ext_test_setup() -> Option<RemoteExternalities<Block>> {
sp_tracing::try_init_simple();
let snap = std::env::var("SNAP").ok()?;
let abs = std::path::absolute(snap.clone());

let ext = Builder::<Block>::default()
.mode(Mode::Offline(OfflineConfig { state_snapshot: snap.clone().into() }))
.build()
.await
.map_err(|e| {
eprintln!("Could not load from snapshot: {:?}: {:?}", abs, e);
})
.unwrap();

Some(ext)
}

/// Check that the call filtering mechanism works.
#[test]
#[cfg(not(feature = "ahm-westend"))] // FIXME make work on Westend
fn call_filter_works() {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::<T>::default().build_storage().unwrap().into();

// MQ calls are never filtered:
let mq_call =
polkadot_runtime::RuntimeCall::MessageQueue(pallet_message_queue::Call::<T>::reap_page {
message_origin: AggregateMessageOrigin::Ump(
runtime_parachains::inclusion::UmpQueueId::Para(ParaId::from(1000)),
),
page_index: 0,
});
let mq_call = RuntimeCall::MessageQueue(pallet_message_queue::Call::<T>::reap_page {
message_origin: AggregateMessageOrigin::Ump(
runtime_parachains::inclusion::UmpQueueId::Para(ParaId::from(1000)),
),
page_index: 0,
});
// Balances calls are filtered during the migration:
let balances_call =
polkadot_runtime::RuntimeCall::Balances(pallet_balances::Call::<T>::transfer_all {
dest: AccountId32::from([0; 32]).into(),
keep_alive: false,
});
let balances_call = RuntimeCall::Balances(pallet_balances::Call::<T>::transfer_all {
dest: AccountId32::from([0; 32]).into(),
keep_alive: false,
});
// Indices calls are filtered during and after the migration:
let indices_call =
polkadot_runtime::RuntimeCall::Indices(pallet_indices::Call::<T>::claim { index: 0 });
let indices_call = RuntimeCall::Indices(pallet_indices::Call::<T>::claim { index: 0 });

let is_allowed = |call: &polkadot_runtime::RuntimeCall| Pallet::<T>::contains(call);
let is_allowed = |call: &RuntimeCall| Pallet::<T>::contains(call);

// Try the BaseCallFilter
t.execute_with(|| {
Expand Down Expand Up @@ -108,10 +84,11 @@ fn call_filter_works() {

// Try to actually dispatch the calls
t.execute_with(|| {
<pallet_balances::Pallet<T> as frame_support::traits::Currency<_>>::deposit_creating(
&AccountId32::from([0; 32]),
u64::MAX.into(),
);
let _ =
<pallet_balances::Pallet<T> as frame_support::traits::Currency<_>>::deposit_creating(
&AccountId32::from([0; 32]),
u64::MAX.into(),
);

// Before the migration starts
{
Expand Down Expand Up @@ -143,7 +120,7 @@ fn call_filter_works() {
}

/// Whether a call is forbidden by the call filter.
fn is_forbidden(call: &polkadot_runtime::RuntimeCall) -> bool {
fn is_forbidden(call: &RuntimeCall) -> bool {
let Err(err) = call.clone().dispatch(RuntimeOrigin::signed(AccountId32::from([0; 32]))) else {
return false;
};
Expand Down
71 changes: 71 additions & 0 deletions integration-tests/ahm/src/checks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Generic checks for Relay and AH.

use crate::porting_prelude::*;

use frame_support::{
pallet_prelude::*,
traits::{Currency, Defensive},
};
use frame_system::pallet_prelude::*;
use pallet_ah_migrator::types::AhMigrationCheck;
use pallet_rc_migrator::types::{RcMigrationCheck, ToPolkadotSs58};
use sp_runtime::{
traits::{Dispatchable, TryConvert},
AccountId32,
};
use std::{collections::BTreeMap, str::FromStr};

pub struct SanityChecks;

impl RcMigrationCheck for SanityChecks {
type RcPrePayload = ();

fn pre_check() -> Self::RcPrePayload {
assert!(
pallet_rc_migrator::RcMigrationStage::<RcRuntime>::get() ==
pallet_rc_migrator::MigrationStage::Scheduled { block_number: 0 }
);
}

fn post_check(_: Self::RcPrePayload) {
assert!(
pallet_rc_migrator::RcMigrationStage::<RcRuntime>::get() ==
pallet_rc_migrator::MigrationStage::MigrationDone
);
}
}

impl AhMigrationCheck for SanityChecks {
type RcPrePayload = ();
type AhPrePayload = ();

fn pre_check(_: Self::RcPrePayload) -> Self::AhPrePayload {
assert!(
pallet_ah_migrator::AhMigrationStage::<AhRuntime>::get() ==
pallet_ah_migrator::MigrationStage::Pending
);
}

fn post_check(rc_pre_payload: Self::RcPrePayload, _: Self::AhPrePayload) {
assert!(
pallet_ah_migrator::AhMigrationStage::<AhRuntime>::get() ==
pallet_ah_migrator::MigrationStage::MigrationDone
);
}
}
3 changes: 3 additions & 0 deletions integration-tests/ahm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#![cfg(test)]

pub mod bench;
pub mod call_filter_asset_hub;
pub mod call_filter_relay;
pub mod checks;
pub mod mock;
pub mod proxy_test;
pub mod tests;
Expand Down
14 changes: 12 additions & 2 deletions integration-tests/ahm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

use crate::porting_prelude::*;

use super::{mock::*, proxy_test::ProxiesStillWork};
use super::{checks::SanityChecks, mock::*, proxy_test::ProxiesStillWork};
use asset_hub_polkadot_runtime::Runtime as AssetHub;
use cumulus_pallet_parachain_system::PendingUpwardMessages;
use cumulus_primitives_core::{BlockT, Junction, Location, ParaId};
Expand All @@ -58,6 +58,7 @@ use xcm::latest::*;
use xcm_emulator::{assert_ok, ConvertLocation, WeightMeter};

type RcChecks = (
SanityChecks,
pallet_rc_migrator::accounts::AccountsMigrator<Polkadot>,
pallet_rc_migrator::preimage::PreimageChunkMigrator<Polkadot>,
pallet_rc_migrator::preimage::PreimageRequestStatusMigrator<Polkadot>,
Expand Down Expand Up @@ -87,6 +88,7 @@ pub type RcPolkadotChecks = (
pub type RcPolkadotChecks = ();

type AhChecks = (
SanityChecks,
pallet_rc_migrator::accounts::AccountsMigrator<AssetHub>,
pallet_rc_migrator::preimage::PreimageChunkMigrator<AssetHub>,
pallet_rc_migrator::preimage::PreimageRequestStatusMigrator<AssetHub>,
Expand Down Expand Up @@ -118,7 +120,7 @@ pub type AhPolkadotChecks = ();

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn pallet_migration_works() {
let Some((mut rc, mut ah)) = load_externalities().await else { return };
let (mut rc, mut ah) = load_externalities().await.unwrap();

// Set the initial migration stage from env var if set.
set_initial_migration_stage(&mut rc);
Expand Down Expand Up @@ -148,6 +150,13 @@ async fn pallet_migration_works() {
// Migrate the Asset Hub
ah_migrate(&mut ah, dmp_messages);

ah.execute_with(|| {
assert!(
pallet_ah_migrator::AhMigrationStage::<AssetHub>::get() ==
pallet_ah_migrator::MigrationStage::MigrationDone
);
});

// Post-checks on the Asset Hub
run_check(|| AhChecks::post_check(rc_pre.unwrap(), ah_pre.unwrap()), &mut ah);
}
Expand Down Expand Up @@ -345,6 +354,7 @@ fn ah_account_migration_weight() {
}
}

#[ignore] // Slow
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muharem i disabled this by default since it ran very slowly for me.

#[tokio::test(flavor = "current_thread")]
async fn migration_works() {
let Some((mut rc, mut ah)) = load_externalities().await else { return };
Expand Down
Loading
Loading