diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index b8f64da0228c7..82ce96ea03afb 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -28,11 +28,11 @@ use frame_support::{ parameter_types, traits::{ tokens::imbalance::{ResolveAssetTo, ResolveTo}, - ConstU32, Contains, Equals, Everything, Nothing, PalletInfoAccess, + ConstU32, Contains, Equals, Everything, PalletInfoAccess, }, }; use frame_system::EnsureRoot; -use pallet_xcm::XcmPassthrough; +use pallet_xcm::{AuthorizedAliases, XcmPassthrough}; use parachains_common::{ xcm_config::{ AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier, @@ -462,7 +462,7 @@ impl xcm_executor::Config for XcmConfig { (bridging::to_rococo::UniversalAliases, bridging::to_ethereum::UniversalAliases); type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; - type Aliasers = Nothing; + type Aliasers = AuthorizedAliases; type TransactionalProcessor = FrameTransactionalProcessor; type HrmpNewChannelOpenRequestHandler = (); type HrmpChannelAcceptedHandler = (); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 6a48b19ce9468..9ddc0cfa5f076 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -43,6 +43,7 @@ use frame_support::{ fungibles::{ Create, Inspect as FungiblesInspect, InspectEnumerable, Mutate as FungiblesMutate, }, + ContainsPair, }, weights::{Weight, WeightToFee as WeightToFeeT}, }; @@ -133,6 +134,7 @@ fn setup_pool_for_paying_fees_with_foreign_assets( #[test] fn test_buy_and_refund_weight_in_native() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -191,6 +193,7 @@ fn test_buy_and_refund_weight_in_native() { #[test] fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -300,6 +303,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { #[test] fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -410,6 +414,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { #[test] fn test_asset_xcm_take_first_trader() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -488,6 +493,7 @@ fn test_asset_xcm_take_first_trader() { #[test] fn test_foreign_asset_xcm_take_first_trader() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -569,6 +575,7 @@ fn test_foreign_asset_xcm_take_first_trader() { #[test] fn test_asset_xcm_take_first_trader_with_refund() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -648,6 +655,7 @@ fn test_asset_xcm_take_first_trader_with_refund() { #[test] fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_ed() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -700,6 +708,7 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e #[test] fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -764,6 +773,7 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() { #[test] fn test_asset_xcm_take_first_trader_not_possible_for_non_sufficient_assets() { ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -825,6 +835,7 @@ fn test_assets_balances_api_works() { use assets_common::runtime_api::runtime_decl_for_fungibles_api::FungiblesApi; ExtBuilder::::default() + .with_tracing() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( AccountId::from(ALICE), @@ -939,6 +950,87 @@ fn test_assets_balances_api_works() { }); } +#[test] +fn authorized_aliases_work() { + ExtBuilder::::default() + .with_tracing() + .with_collators(vec![AccountId::from(ALICE)]) + .with_session_keys(vec![( + AccountId::from(ALICE), + AccountId::from(ALICE), + SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) }, + )]) + .build() + .execute_with(|| { + let alice: AccountId = ALICE.into(); + let local_alice = Location::new(0, AccountId32 { network: Some(Westend), id: ALICE }); + let alice_on_sibling_para = + Location::new(1, [Parachain(42), AccountId32 { network: None, id: ALICE }]); + let alice_on_relay = Location::new(1, AccountId32 { network: None, id: ALICE }); + let bob_on_relay = Location::new(1, AccountId32 { network: None, id: [42_u8; 32] }); + + // neither `alice_on_sibling_para`, `alice_on_relay`, `bob_on_relay` are allowed to + // alias into `local_alice` + for aliaser in [&alice_on_sibling_para, &alice_on_relay, &bob_on_relay] { + assert!(!::Aliasers::contains( + aliaser, + &local_alice + )); + } + + // Alice explicitly authorizes `alice_on_sibling_para` to alias her local account + assert_ok!(PolkadotXcm::add_authorized_alias( + RuntimeHelper::origin_of(alice.clone()), + Box::new(alice_on_sibling_para.clone().into()) + )); + + // `alice_on_sibling_para` now explicitly allowed to alias into `local_alice` + assert!(::Aliasers::contains( + &alice_on_sibling_para, + &local_alice + )); + // as expected, `alice_on_relay` and `bob_on_relay` still can't alias into `local_alice` + for aliaser in [&alice_on_relay, &bob_on_relay] { + assert!(!::Aliasers::contains( + aliaser, + &local_alice + )); + } + + // Alice explicitly authorizes `alice_on_relay` to alias her local account + assert_ok!(PolkadotXcm::add_authorized_alias( + RuntimeHelper::origin_of(alice.clone()), + Box::new(alice_on_relay.clone().into()) + )); + // Now both `alice_on_relay` and `alice_on_sibling_para` can alias into her local + // account + for aliaser in [&alice_on_relay, &alice_on_sibling_para] { + assert!(::Aliasers::contains( + aliaser, + &local_alice + )); + } + + // Alice removes authorization for `alice_on_relay` to alias her local account + assert_ok!(PolkadotXcm::remove_authorized_alias( + RuntimeHelper::origin_of(alice.clone()), + Box::new(alice_on_relay.clone().into()) + )); + + // `alice_on_relay` no longer allowed to alias into `local_alice` + assert!(!::Aliasers::contains( + &alice_on_relay, + &local_alice + )); + + // `alice_on_sibling_para` still allowed to alias into `local_alice` + assert!(::Aliasers::contains( + &alice_on_sibling_para, + &local_alice + )); + }) +} + asset_test_utils::include_teleports_for_native_asset_works!( Runtime, AllPalletsWithoutSystem,