Skip to content

Commit

Permalink
asset hub westend: add support for authorized aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
acatangiu committed Nov 6, 2024
1 parent e84293f commit 0332aca
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Runtime>;
type TransactionalProcessor = FrameTransactionalProcessor;
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use frame_support::{
fungibles::{
Create, Inspect as FungiblesInspect, InspectEnumerable, Mutate as FungiblesMutate,
},
ContainsPair,
},
weights::{Weight, WeightToFee as WeightToFeeT},
};
Expand Down Expand Up @@ -133,6 +134,7 @@ fn setup_pool_for_paying_fees_with_foreign_assets(
#[test]
fn test_buy_and_refund_weight_in_native() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -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::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -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::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -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::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -488,6 +493,7 @@ fn test_asset_xcm_take_first_trader() {
#[test]
fn test_foreign_asset_xcm_take_first_trader() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -569,6 +575,7 @@ fn test_foreign_asset_xcm_take_first_trader() {
#[test]
fn test_asset_xcm_take_first_trader_with_refund() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -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::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -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::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -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::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -825,6 +835,7 @@ fn test_assets_balances_api_works() {
use assets_common::runtime_api::runtime_decl_for_fungibles_api::FungiblesApi;

ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -939,6 +950,87 @@ fn test_assets_balances_api_works() {
});
}

#[test]
fn authorized_aliases_work() {
ExtBuilder::<Runtime>::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!(!<XcmConfig as xcm_executor::Config>::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!(<XcmConfig as xcm_executor::Config>::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!(!<XcmConfig as xcm_executor::Config>::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!(<XcmConfig as xcm_executor::Config>::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!(!<XcmConfig as xcm_executor::Config>::Aliasers::contains(
&alice_on_relay,
&local_alice
));

// `alice_on_sibling_para` still allowed to alias into `local_alice`
assert!(<XcmConfig as xcm_executor::Config>::Aliasers::contains(
&alice_on_sibling_para,
&local_alice
));
})
}

asset_test_utils::include_teleports_for_native_asset_works!(
Runtime,
AllPalletsWithoutSystem,
Expand Down

0 comments on commit 0332aca

Please sign in to comment.