From eba76e0265bd914b9e7852ba6dd1ab74d787ba6d Mon Sep 17 00:00:00 2001 From: Raymond Cheung <178801527+raymondkfcheung@users.noreply.github.com> Date: Wed, 19 Mar 2025 10:46:06 +0000 Subject: [PATCH 1/6] BACKPORT-CONFLICT --- .../people-westend/src/tests/governance.rs | 3 +- polkadot/xcm/xcm-builder/src/tests/origins.rs | 5 +- .../xcm/xcm-builder/src/tests/querying.rs | 5 +- .../src/tests/version_subscriptions.rs | 19 ++- polkadot/xcm/xcm-builder/tests/scenarios.rs | 108 ++++++++++++++++++ polkadot/xcm/xcm-executor/src/lib.rs | 6 +- prdoc/pr_7843.prdoc | 15 +++ 7 files changed, 151 insertions(+), 10 deletions(-) create mode 100644 prdoc/pr_7843.prdoc diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs index 1ba787aaec528..8c43f1234b807 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs @@ -14,7 +14,6 @@ // limitations under the License. use crate::imports::*; -use frame_support::traits::ProcessMessageError; use codec::Encode; use frame_support::sp_runtime::traits::Dispatchable; @@ -135,7 +134,7 @@ fn relay_commands_add_registrar_wrong_origin() { assert_expected_events!( PeopleWestend, vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { error: ProcessMessageError::Unsupported, .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: false, .. }) => {}, ] ); } else { diff --git a/polkadot/xcm/xcm-builder/src/tests/origins.rs b/polkadot/xcm/xcm-builder/src/tests/origins.rs index b6a1a9f1052a4..3cdc0a8eb36c2 100644 --- a/polkadot/xcm/xcm-builder/src/tests/origins.rs +++ b/polkadot/xcm/xcm-builder/src/tests/origins.rs @@ -139,7 +139,10 @@ fn unpaid_execution_should_work() { Weight::from_parts(50, 50), Weight::zero(), ); - assert_eq!(r, Outcome::Error { error: XcmError::Barrier }); + assert_eq!( + r, + Outcome::Incomplete { used: Weight::from_parts(10, 10), error: XcmError::Barrier } + ); let message = Xcm(vec![UnpaidExecution { weight_limit: Limited(Weight::from_parts(10, 10)), diff --git a/polkadot/xcm/xcm-builder/src/tests/querying.rs b/polkadot/xcm/xcm-builder/src/tests/querying.rs index 3b47073d53df1..062b508368f77 100644 --- a/polkadot/xcm/xcm-builder/src/tests/querying.rs +++ b/polkadot/xcm/xcm-builder/src/tests/querying.rs @@ -130,5 +130,8 @@ fn prepaid_result_of_query_should_get_free_execution() { weight_limit, Weight::zero(), ); - assert_eq!(r, Outcome::Error { error: XcmError::Barrier }); + assert_eq!( + r, + Outcome::Incomplete { used: Weight::from_parts(10, 10), error: XcmError::Barrier } + ); } diff --git a/polkadot/xcm/xcm-builder/src/tests/version_subscriptions.rs b/polkadot/xcm/xcm-builder/src/tests/version_subscriptions.rs index 01047fde989f9..df36b3c573106 100644 --- a/polkadot/xcm/xcm-builder/src/tests/version_subscriptions.rs +++ b/polkadot/xcm/xcm-builder/src/tests/version_subscriptions.rs @@ -37,7 +37,7 @@ fn simple_version_subscriptions_should_work() { weight_limit, Weight::zero(), ), - Outcome::Error { error: XcmError::Barrier } + Outcome::Incomplete { used: Weight::from_parts(20, 20), error: XcmError::Barrier } ); // this case fails because the additional `SetAppendix` instruction is not allowed in the @@ -50,7 +50,7 @@ fn simple_version_subscriptions_should_work() { weight_limit, Weight::zero(), ), - Outcome::Error { error: XcmError::Barrier } + Outcome::Incomplete { used: Weight::from_parts(20, 20), error: XcmError::Barrier } ); let message = Xcm::(vec![SubscribeVersion { @@ -66,7 +66,10 @@ fn simple_version_subscriptions_should_work() { weight_limit, Weight::zero(), ); - assert_eq!(r, Outcome::Error { error: XcmError::Barrier }); + assert_eq!( + r, + Outcome::Incomplete { used: Weight::from_parts(10, 10), error: XcmError::Barrier } + ); let r = XcmExecutor::::prepare_and_execute( Parent, @@ -139,7 +142,10 @@ fn simple_version_unsubscriptions_should_work() { weight_limit, Weight::zero(), ); - assert_eq!(r, Outcome::Error { error: XcmError::Barrier }); + assert_eq!( + r, + Outcome::Incomplete { used: Weight::from_parts(20, 20), error: XcmError::Barrier } + ); let origin = Parachain(1000); let message = Xcm::(vec![UnsubscribeVersion]); @@ -152,7 +158,10 @@ fn simple_version_unsubscriptions_should_work() { weight_limit, Weight::zero(), ); - assert_eq!(r, Outcome::Error { error: XcmError::Barrier }); + assert_eq!( + r, + Outcome::Incomplete { used: Weight::from_parts(10, 10), error: XcmError::Barrier } + ); let r = XcmExecutor::::prepare_and_execute( Parent, diff --git a/polkadot/xcm/xcm-builder/tests/scenarios.rs b/polkadot/xcm/xcm-builder/tests/scenarios.rs index 99c14f5bba1bc..a4205974c8fef 100644 --- a/polkadot/xcm/xcm-builder/tests/scenarios.rs +++ b/polkadot/xcm/xcm-builder/tests/scenarios.rs @@ -322,3 +322,111 @@ fn reserve_based_transfer_works() { ); }); } +<<<<<<< HEAD +======= + +/// Scenario: +/// A recursive XCM that triggers itself via `SetAppendix`. +/// The execution should fail due to inner filter. +#[test] +fn recursive_xcm_execution_fail() { + use crate::mock::*; + use frame_support::traits::{Everything, Nothing, ProcessMessageError}; + use staging_xcm_builder::*; + use std::ops::ControlFlow; + use xcm::opaque::latest::prelude::*; + use xcm_executor::traits::{DenyExecution, Properties, ShouldExecute}; + + // Dummy filter to allow all + struct AllowAll; + impl ShouldExecute for AllowAll { + fn should_execute( + _: &Location, + _: &mut [Instruction], + _: Weight, + _: &mut Properties, + ) -> Result<(), ProcessMessageError> { + Ok(()) + } + } + + // Dummy filter which denies `ClearOrigin` + struct DenyClearOrigin; + impl DenyExecution for DenyClearOrigin { + fn deny_execution( + _: &Location, + instructions: &mut [Instruction], + _: Weight, + _: &mut Properties, + ) -> Result<(), ProcessMessageError> { + instructions.matcher().match_next_inst_while( + |_| true, + |inst| match inst { + ClearOrigin => Err(ProcessMessageError::Unsupported), + _ => Ok(ControlFlow::Continue(())), + }, + )?; + Ok(()) + } + } + + struct XcmTestConfig; + impl xcm_executor::Config for XcmTestConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = TestXcmRouter; + type XcmEventEmitter = (); + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = (); + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = DenyThenTry, AllowAll>; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetLocker = (); + type AssetExchanger = (); + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = (); + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); + type XcmRecorder = XcmPallet; + } + + let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating(); + let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; + let origin = Parachain(PARA_ID); + let message = Xcm(vec![SetAppendix(Xcm(vec![SetAppendix(Xcm(vec![ClearOrigin]))]))]); + let mut hash = fake_message_hash(&message); + let weight = BaseXcmWeight::get() * 3; + + kusama_like_with_balances(balances).execute_with(|| { + let outcome = XcmExecutor::::prepare_and_execute( + origin, + message, + &mut hash, + weight, + Weight::zero(), + ); + + assert_eq!( + outcome, + Outcome::Incomplete { + used: Weight::from_parts(3000000000, 3072), + error: XcmError::Barrier + } + ); + }); +} +>>>>>>> 21927dd4 (Fix XCM Barrier Rejection Handling to Return Incomplete with Weight (#7843)) diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 366b702a41132..94877abbd2053 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -266,7 +266,11 @@ impl ExecuteXcm for XcmExecutor Date: Wed, 19 Mar 2025 14:33:14 +0000 Subject: [PATCH 2/6] Rename PRDoc --- prdoc/{pr_7843.prdoc => pr_7968.prdoc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename prdoc/{pr_7843.prdoc => pr_7968.prdoc} (100%) diff --git a/prdoc/pr_7843.prdoc b/prdoc/pr_7968.prdoc similarity index 100% rename from prdoc/pr_7843.prdoc rename to prdoc/pr_7968.prdoc From 724307495f91e4e46a0c54dd8991ead720689e51 Mon Sep 17 00:00:00 2001 From: Raymond Cheung <178801527+raymondkfcheung@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:35:48 +0000 Subject: [PATCH 3/6] Fix conflict --- polkadot/xcm/xcm-builder/tests/scenarios.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/polkadot/xcm/xcm-builder/tests/scenarios.rs b/polkadot/xcm/xcm-builder/tests/scenarios.rs index a4205974c8fef..e3a1924a19d7a 100644 --- a/polkadot/xcm/xcm-builder/tests/scenarios.rs +++ b/polkadot/xcm/xcm-builder/tests/scenarios.rs @@ -322,8 +322,6 @@ fn reserve_based_transfer_works() { ); }); } -<<<<<<< HEAD -======= /// Scenario: /// A recursive XCM that triggers itself via `SetAppendix`. @@ -429,4 +427,3 @@ fn recursive_xcm_execution_fail() { ); }); } ->>>>>>> 21927dd4 (Fix XCM Barrier Rejection Handling to Return Incomplete with Weight (#7843)) From 0bc55acda9f9e6f2d111b4c7d07d03caf3cc9543 Mon Sep 17 00:00:00 2001 From: Raymond Cheung <178801527+raymondkfcheung@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:59:14 +0000 Subject: [PATCH 4/6] Delete governance.rs --- .../people-westend/src/tests/governance.rs | 531 ------------------ 1 file changed, 531 deletions(-) delete mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs deleted file mode 100644 index 8c43f1234b807..0000000000000 --- a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs +++ /dev/null @@ -1,531 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::imports::*; - -use codec::Encode; -use frame_support::sp_runtime::traits::Dispatchable; -use parachains_common::AccountId; -use people_westend_runtime::people::IdentityInfo; -use westend_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; -use westend_system_emulated_network::people_westend_emulated_chain::people_westend_runtime; - -use pallet_identity::Data; - -use emulated_integration_tests_common::accounts::{ALICE, BOB}; - -#[test] -fn relay_commands_add_registrar() { - let (origin_kind, origin) = (OriginKind::Superuser, ::RuntimeOrigin::root()); - - let registrar: AccountId = [1; 32].into(); - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleCall = ::RuntimeCall; - type PeopleRuntime = ::Runtime; - - let add_registrar_call = - PeopleCall::Identity(pallet_identity::Call::::add_registrar { - account: registrar.into(), - }); - - let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - call: add_registrar_call.encode().into(), - fallback_max_weight: None - } - ]))), - }); - - assert_ok!(xcm_message.dispatch(origin)); - - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - PeopleWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - PeopleWestend, - vec![ - RuntimeEvent::Identity(pallet_identity::Event::RegistrarAdded { .. }) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, - ] - ); - }); -} - -#[test] -fn relay_commands_add_registrar_wrong_origin() { - let people_westend_alice = PeopleWestend::account_id_of(ALICE); - - let origins = vec![ - ( - OriginKind::SovereignAccount, - ::RuntimeOrigin::signed(people_westend_alice), - ), - (OriginKind::Xcm, GeneralAdminOrigin.into()), - ]; - - let mut signed_origin = true; - - for (origin_kind, origin) in origins { - let registrar: AccountId = [1; 32].into(); - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleCall = ::RuntimeCall; - type PeopleRuntime = ::Runtime; - - let add_registrar_call = - PeopleCall::Identity(pallet_identity::Call::::add_registrar { - account: registrar.into(), - }); - - let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - call: add_registrar_call.encode().into(), - fallback_max_weight: None - } - ]))), - }); - - assert_ok!(xcm_message.dispatch(origin)); - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - PeopleWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - if signed_origin { - assert_expected_events!( - PeopleWestend, - vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: false, .. }) => {}, - ] - ); - } else { - assert_expected_events!( - PeopleWestend, - vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, - ] - ); - } - }); - - signed_origin = false; - } -} - -#[test] -fn relay_commands_kill_identity() { - // To kill an identity, first one must be set - PeopleWestend::execute_with(|| { - type PeopleRuntime = ::Runtime; - type PeopleRuntimeEvent = ::RuntimeEvent; - - let people_westend_alice = - ::RuntimeOrigin::signed(PeopleWestend::account_id_of(ALICE)); - - let identity_info = IdentityInfo { - email: Data::Raw(b"test@test.io".to_vec().try_into().unwrap()), - ..Default::default() - }; - let identity: Box<::IdentityInformation> = - Box::new(identity_info); - - assert_ok!(::Identity::set_identity( - people_westend_alice, - identity - )); - - assert_expected_events!( - PeopleWestend, - vec![ - PeopleRuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, - ] - ); - }); - - let (origin_kind, origin) = (OriginKind::Superuser, ::RuntimeOrigin::root()); - - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type PeopleCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleRuntime = ::Runtime; - - let kill_identity_call = - PeopleCall::Identity(pallet_identity::Call::::kill_identity { - target: people_westend_runtime::MultiAddress::Id(PeopleWestend::account_id_of( - ALICE, - )), - }); - - let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - call: kill_identity_call.encode().into(), - fallback_max_weight: None - } - ]))), - }); - - assert_ok!(xcm_message.dispatch(origin)); - - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - PeopleWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - PeopleWestend, - vec![ - RuntimeEvent::Identity(pallet_identity::Event::IdentityKilled { .. }) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, - ] - ); - }); -} - -#[test] -fn relay_commands_kill_identity_wrong_origin() { - let people_westend_alice = PeopleWestend::account_id_of(BOB); - - let origins = vec![ - ( - OriginKind::SovereignAccount, - ::RuntimeOrigin::signed(people_westend_alice), - ), - (OriginKind::Xcm, GeneralAdminOrigin.into()), - ]; - - for (origin_kind, origin) in origins { - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type PeopleCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleRuntime = ::Runtime; - - let kill_identity_call = - PeopleCall::Identity(pallet_identity::Call::::kill_identity { - target: people_westend_runtime::MultiAddress::Id(PeopleWestend::account_id_of( - ALICE, - )), - }); - - let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - call: kill_identity_call.encode().into(), - fallback_max_weight: None - } - ]))), - }); - - assert_ok!(xcm_message.dispatch(origin)); - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - PeopleWestend::execute_with(|| { - assert_expected_events!(PeopleWestend, vec![]); - }); - } -} - -#[test] -fn relay_commands_add_remove_username_authority() { - let people_westend_alice = PeopleWestend::account_id_of(ALICE); - let people_westend_bob = PeopleWestend::account_id_of(BOB); - - let (origin_kind, origin, usr) = - (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername"); - - // First, add a username authority. - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleCall = ::RuntimeCall; - type PeopleRuntime = ::Runtime; - - let add_username_authority = - PeopleCall::Identity(pallet_identity::Call::::add_username_authority { - authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), - suffix: b"suffix1".into(), - allocation: 10, - }); - - let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - call: add_username_authority.encode().into(), - fallback_max_weight: None - } - ]))), - }); - - assert_ok!(add_authority_xcm_msg.dispatch(origin.clone())); - - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - // Check events system-parachain-side - PeopleWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - PeopleWestend, - vec![ - RuntimeEvent::Identity(pallet_identity::Event::AuthorityAdded { .. }) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, - ] - ); - }); - - // Now, use the previously added username authority to concede a username to an account. - PeopleWestend::execute_with(|| { - type PeopleRuntimeEvent = ::RuntimeEvent; - let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); - - assert_ok!(::Identity::set_username_for( - ::RuntimeOrigin::signed(people_westend_alice.clone()), - people_westend_runtime::MultiAddress::Id(people_westend_bob.clone()), - full_username, - None, - true - )); - - assert_expected_events!( - PeopleWestend, - vec![ - PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameQueued { .. }) => {}, - ] - ); - }); - - // Accept the given username - PeopleWestend::execute_with(|| { - type PeopleRuntimeEvent = ::RuntimeEvent; - let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); - - assert_ok!(::Identity::accept_username( - ::RuntimeOrigin::signed(people_westend_bob.clone()), - full_username.try_into().unwrap(), - )); - - assert_expected_events!( - PeopleWestend, - vec![ - PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameSet { .. }) => {}, - ] - ); - }); - - // Now, remove the username authority with another priviledged XCM call. - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleCall = ::RuntimeCall; - type PeopleRuntime = ::Runtime; - - let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< - PeopleRuntime, - >::remove_username_authority { - authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), - suffix: b"suffix1".into(), - }); - - let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - call: remove_username_authority.encode().into(), - fallback_max_weight: None - } - ]))), - }); - - assert_ok!(remove_authority_xcm_msg.dispatch(origin)); - - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - // Final event check. - PeopleWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - PeopleWestend, - vec![ - RuntimeEvent::Identity(pallet_identity::Event::AuthorityRemoved { .. }) => {}, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, - ] - ); - }); -} - -#[test] -fn relay_commands_add_remove_username_authority_wrong_origin() { - let people_westend_alice = PeopleWestend::account_id_of(ALICE); - - let origins = vec![ - ( - OriginKind::SovereignAccount, - ::RuntimeOrigin::signed(people_westend_alice.clone()), - ), - (OriginKind::Xcm, GeneralAdminOrigin.into()), - ]; - - for (origin_kind, origin) in origins { - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleCall = ::RuntimeCall; - type PeopleRuntime = ::Runtime; - - let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< - PeopleRuntime, - >::add_username_authority { - authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), - suffix: b"suffix1".into(), - allocation: 10, - }); - - let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind, - call: add_username_authority.encode().into(), - fallback_max_weight: None - } - ]))), - }); - - assert_ok!(add_authority_xcm_msg.dispatch(origin.clone())); - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - // Check events system-parachain-side - PeopleWestend::execute_with(|| { - assert_expected_events!(PeopleWestend, vec![]); - }); - - Westend::execute_with(|| { - type Runtime = ::Runtime; - type RuntimeCall = ::RuntimeCall; - type RuntimeEvent = ::RuntimeEvent; - type PeopleCall = ::RuntimeCall; - type PeopleRuntime = ::Runtime; - - let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< - PeopleRuntime, - >::remove_username_authority { - authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), - suffix: b"suffix1".into(), - }); - - let remove_authority_xcm_msg = - RuntimeCall::XcmPallet(pallet_xcm::Call::::send { - dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), - message: bx!(VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - Transact { - origin_kind: OriginKind::SovereignAccount, - call: remove_username_authority.encode().into(), - fallback_max_weight: None, - } - ]))), - }); - - assert_ok!(remove_authority_xcm_msg.dispatch(origin)); - assert_expected_events!( - Westend, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - - PeopleWestend::execute_with(|| { - assert_expected_events!(PeopleWestend, vec![]); - }); - } -} From 7bd88d5c992032fb8ec5be49622e31feb2f804bb Mon Sep 17 00:00:00 2001 From: Raymond Cheung <178801527+raymondkfcheung@users.noreply.github.com> Date: Wed, 19 Mar 2025 16:02:51 +0000 Subject: [PATCH 5/6] Revert "Delete governance.rs" This reverts commit 0bc55acda9f9e6f2d111b4c7d07d03caf3cc9543. --- .../people-westend/src/tests/governance.rs | 531 ++++++++++++++++++ 1 file changed, 531 insertions(+) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs diff --git a/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs new file mode 100644 index 0000000000000..8c43f1234b807 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/people/people-westend/src/tests/governance.rs @@ -0,0 +1,531 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::imports::*; + +use codec::Encode; +use frame_support::sp_runtime::traits::Dispatchable; +use parachains_common::AccountId; +use people_westend_runtime::people::IdentityInfo; +use westend_runtime::governance::pallet_custom_origins::Origin::GeneralAdmin as GeneralAdminOrigin; +use westend_system_emulated_network::people_westend_emulated_chain::people_westend_runtime; + +use pallet_identity::Data; + +use emulated_integration_tests_common::accounts::{ALICE, BOB}; + +#[test] +fn relay_commands_add_registrar() { + let (origin_kind, origin) = (OriginKind::Superuser, ::RuntimeOrigin::root()); + + let registrar: AccountId = [1; 32].into(); + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_registrar_call = + PeopleCall::Identity(pallet_identity::Call::::add_registrar { + account: registrar.into(), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + call: add_registrar_call.encode().into(), + fallback_max_weight: None + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleWestend, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::RegistrarAdded { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); +} + +#[test] +fn relay_commands_add_registrar_wrong_origin() { + let people_westend_alice = PeopleWestend::account_id_of(ALICE); + + let origins = vec![ + ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_westend_alice), + ), + (OriginKind::Xcm, GeneralAdminOrigin.into()), + ]; + + let mut signed_origin = true; + + for (origin_kind, origin) in origins { + let registrar: AccountId = [1; 32].into(); + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_registrar_call = + PeopleCall::Identity(pallet_identity::Call::::add_registrar { + account: registrar.into(), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + call: add_registrar_call.encode().into(), + fallback_max_weight: None + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + if signed_origin { + assert_expected_events!( + PeopleWestend, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: false, .. }) => {}, + ] + ); + } else { + assert_expected_events!( + PeopleWestend, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + } + }); + + signed_origin = false; + } +} + +#[test] +fn relay_commands_kill_identity() { + // To kill an identity, first one must be set + PeopleWestend::execute_with(|| { + type PeopleRuntime = ::Runtime; + type PeopleRuntimeEvent = ::RuntimeEvent; + + let people_westend_alice = + ::RuntimeOrigin::signed(PeopleWestend::account_id_of(ALICE)); + + let identity_info = IdentityInfo { + email: Data::Raw(b"test@test.io".to_vec().try_into().unwrap()), + ..Default::default() + }; + let identity: Box<::IdentityInformation> = + Box::new(identity_info); + + assert_ok!(::Identity::set_identity( + people_westend_alice, + identity + )); + + assert_expected_events!( + PeopleWestend, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::IdentitySet { .. }) => {}, + ] + ); + }); + + let (origin_kind, origin) = (OriginKind::Superuser, ::RuntimeOrigin::root()); + + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type PeopleCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleRuntime = ::Runtime; + + let kill_identity_call = + PeopleCall::Identity(pallet_identity::Call::::kill_identity { + target: people_westend_runtime::MultiAddress::Id(PeopleWestend::account_id_of( + ALICE, + )), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + call: kill_identity_call.encode().into(), + fallback_max_weight: None + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleWestend, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::IdentityKilled { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); +} + +#[test] +fn relay_commands_kill_identity_wrong_origin() { + let people_westend_alice = PeopleWestend::account_id_of(BOB); + + let origins = vec![ + ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_westend_alice), + ), + (OriginKind::Xcm, GeneralAdminOrigin.into()), + ]; + + for (origin_kind, origin) in origins { + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type PeopleCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleRuntime = ::Runtime; + + let kill_identity_call = + PeopleCall::Identity(pallet_identity::Call::::kill_identity { + target: people_westend_runtime::MultiAddress::Id(PeopleWestend::account_id_of( + ALICE, + )), + }); + + let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + call: kill_identity_call.encode().into(), + fallback_max_weight: None + } + ]))), + }); + + assert_ok!(xcm_message.dispatch(origin)); + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleWestend::execute_with(|| { + assert_expected_events!(PeopleWestend, vec![]); + }); + } +} + +#[test] +fn relay_commands_add_remove_username_authority() { + let people_westend_alice = PeopleWestend::account_id_of(ALICE); + let people_westend_bob = PeopleWestend::account_id_of(BOB); + + let (origin_kind, origin, usr) = + (OriginKind::Superuser, ::RuntimeOrigin::root(), "rootusername"); + + // First, add a username authority. + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_username_authority = + PeopleCall::Identity(pallet_identity::Call::::add_username_authority { + authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); + + let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + call: add_username_authority.encode().into(), + fallback_max_weight: None + } + ]))), + }); + + assert_ok!(add_authority_xcm_msg.dispatch(origin.clone())); + + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Check events system-parachain-side + PeopleWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleWestend, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::AuthorityAdded { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); + + // Now, use the previously added username authority to concede a username to an account. + PeopleWestend::execute_with(|| { + type PeopleRuntimeEvent = ::RuntimeEvent; + let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); + + assert_ok!(::Identity::set_username_for( + ::RuntimeOrigin::signed(people_westend_alice.clone()), + people_westend_runtime::MultiAddress::Id(people_westend_bob.clone()), + full_username, + None, + true + )); + + assert_expected_events!( + PeopleWestend, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameQueued { .. }) => {}, + ] + ); + }); + + // Accept the given username + PeopleWestend::execute_with(|| { + type PeopleRuntimeEvent = ::RuntimeEvent; + let full_username = [usr.to_owned(), ".suffix1".to_owned()].concat().into_bytes(); + + assert_ok!(::Identity::accept_username( + ::RuntimeOrigin::signed(people_westend_bob.clone()), + full_username.try_into().unwrap(), + )); + + assert_expected_events!( + PeopleWestend, + vec![ + PeopleRuntimeEvent::Identity(pallet_identity::Event::UsernameSet { .. }) => {}, + ] + ); + }); + + // Now, remove the username authority with another priviledged XCM call. + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::remove_username_authority { + authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), + suffix: b"suffix1".into(), + }); + + let remove_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + call: remove_username_authority.encode().into(), + fallback_max_weight: None + } + ]))), + }); + + assert_ok!(remove_authority_xcm_msg.dispatch(origin)); + + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Final event check. + PeopleWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + PeopleWestend, + vec![ + RuntimeEvent::Identity(pallet_identity::Event::AuthorityRemoved { .. }) => {}, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success: true, .. }) => {}, + ] + ); + }); +} + +#[test] +fn relay_commands_add_remove_username_authority_wrong_origin() { + let people_westend_alice = PeopleWestend::account_id_of(ALICE); + + let origins = vec![ + ( + OriginKind::SovereignAccount, + ::RuntimeOrigin::signed(people_westend_alice.clone()), + ), + (OriginKind::Xcm, GeneralAdminOrigin.into()), + ]; + + for (origin_kind, origin) in origins { + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let add_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::add_username_authority { + authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), + suffix: b"suffix1".into(), + allocation: 10, + }); + + let add_authority_xcm_msg = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind, + call: add_username_authority.encode().into(), + fallback_max_weight: None + } + ]))), + }); + + assert_ok!(add_authority_xcm_msg.dispatch(origin.clone())); + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + // Check events system-parachain-side + PeopleWestend::execute_with(|| { + assert_expected_events!(PeopleWestend, vec![]); + }); + + Westend::execute_with(|| { + type Runtime = ::Runtime; + type RuntimeCall = ::RuntimeCall; + type RuntimeEvent = ::RuntimeEvent; + type PeopleCall = ::RuntimeCall; + type PeopleRuntime = ::Runtime; + + let remove_username_authority = PeopleCall::Identity(pallet_identity::Call::< + PeopleRuntime, + >::remove_username_authority { + authority: people_westend_runtime::MultiAddress::Id(people_westend_alice.clone()), + suffix: b"suffix1".into(), + }); + + let remove_authority_xcm_msg = + RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::SovereignAccount, + call: remove_username_authority.encode().into(), + fallback_max_weight: None, + } + ]))), + }); + + assert_ok!(remove_authority_xcm_msg.dispatch(origin)); + assert_expected_events!( + Westend, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + + PeopleWestend::execute_with(|| { + assert_expected_events!(PeopleWestend, vec![]); + }); + } +} From 88e3e5b08bca68334973dfda184eae4673c25a8b Mon Sep 17 00:00:00 2001 From: Raymond Cheung <178801527+raymondkfcheung@users.noreply.github.com> Date: Wed, 19 Mar 2025 16:24:37 +0000 Subject: [PATCH 6/6] Update scenarios.rs --- polkadot/xcm/xcm-builder/tests/scenarios.rs | 105 -------------------- 1 file changed, 105 deletions(-) diff --git a/polkadot/xcm/xcm-builder/tests/scenarios.rs b/polkadot/xcm/xcm-builder/tests/scenarios.rs index e3a1924a19d7a..99c14f5bba1bc 100644 --- a/polkadot/xcm/xcm-builder/tests/scenarios.rs +++ b/polkadot/xcm/xcm-builder/tests/scenarios.rs @@ -322,108 +322,3 @@ fn reserve_based_transfer_works() { ); }); } - -/// Scenario: -/// A recursive XCM that triggers itself via `SetAppendix`. -/// The execution should fail due to inner filter. -#[test] -fn recursive_xcm_execution_fail() { - use crate::mock::*; - use frame_support::traits::{Everything, Nothing, ProcessMessageError}; - use staging_xcm_builder::*; - use std::ops::ControlFlow; - use xcm::opaque::latest::prelude::*; - use xcm_executor::traits::{DenyExecution, Properties, ShouldExecute}; - - // Dummy filter to allow all - struct AllowAll; - impl ShouldExecute for AllowAll { - fn should_execute( - _: &Location, - _: &mut [Instruction], - _: Weight, - _: &mut Properties, - ) -> Result<(), ProcessMessageError> { - Ok(()) - } - } - - // Dummy filter which denies `ClearOrigin` - struct DenyClearOrigin; - impl DenyExecution for DenyClearOrigin { - fn deny_execution( - _: &Location, - instructions: &mut [Instruction], - _: Weight, - _: &mut Properties, - ) -> Result<(), ProcessMessageError> { - instructions.matcher().match_next_inst_while( - |_| true, - |inst| match inst { - ClearOrigin => Err(ProcessMessageError::Unsupported), - _ => Ok(ControlFlow::Continue(())), - }, - )?; - Ok(()) - } - } - - struct XcmTestConfig; - impl xcm_executor::Config for XcmTestConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = TestXcmRouter; - type XcmEventEmitter = (); - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = (); - type IsReserve = (); - type IsTeleporter = TrustedTeleporters; - type UniversalLocation = UniversalLocation; - type Barrier = DenyThenTry, AllowAll>; - type Weigher = FixedWeightBounds; - type Trader = FixedRateOfFungible; - type ResponseHandler = XcmPallet; - type AssetTrap = XcmPallet; - type AssetLocker = (); - type AssetExchanger = (); - type AssetClaims = XcmPallet; - type SubscriptionService = XcmPallet; - type PalletInstancesInfo = AllPalletsWithSystem; - type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = RuntimeCall; - type SafeCallFilter = Everything; - type Aliasers = Nothing; - type TransactionalProcessor = (); - type HrmpNewChannelOpenRequestHandler = (); - type HrmpChannelAcceptedHandler = (); - type HrmpChannelClosingHandler = (); - type XcmRecorder = XcmPallet; - } - - let para_acc: AccountId = ParaId::from(PARA_ID).into_account_truncating(); - let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)]; - let origin = Parachain(PARA_ID); - let message = Xcm(vec![SetAppendix(Xcm(vec![SetAppendix(Xcm(vec![ClearOrigin]))]))]); - let mut hash = fake_message_hash(&message); - let weight = BaseXcmWeight::get() * 3; - - kusama_like_with_balances(balances).execute_with(|| { - let outcome = XcmExecutor::::prepare_and_execute( - origin, - message, - &mut hash, - weight, - Weight::zero(), - ); - - assert_eq!( - outcome, - Outcome::Incomplete { - used: Weight::from_parts(3000000000, 3072), - error: XcmError::Barrier - } - ); - }); -}