Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapts XCM remote account derivation to match Polkadot suggestions #2344

Merged
merged 11 commits into from
Jun 14, 2023
122 changes: 61 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub type LocationToAccountId = (
// If we receive a MultiLocation of type AccountKey20, just generate a native account
AccountKey20Aliases<RelayNetwork, AccountId>,
// Generate remote accounts according to polkadot standards
xcm_builder::ForeignChainAliasAccount<AccountId>,
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal<AccountId>,
);

/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`.
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,7 @@ fn test_xcm_utils_ml_tp_account() {
),
);
let expected_address_alice_in_parachain_2000: H160 =
xcm_builder::ForeignChainAliasAccount::<AccountId>::convert_ref(
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal::<AccountId>::convert_ref(
alice_in_parachain_2000_multilocation.clone(),
)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountKey20Aliases<RelayNetwork, AccountId>,
// The rest of multilocations convert via hashing it
xcm_builder::ForeignChainAliasAccount<AccountId>,
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal<AccountId>,
);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down
9 changes: 5 additions & 4 deletions runtime/moonbase/tests/xcm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use pallet_xcm_transactor::{
use sp_std::boxed::Box;
use xcm::latest::prelude::*;
use xcm::{VersionedMultiLocation, WrapVersion};
use xcm_builder::HashedDescriptionDescribeFamilyAllTerminal;
use xcm_executor::traits::Convert;
use xcm_mock::*;
use xcm_primitives::{UtilityEncodeCall, DEFAULT_PROOF_SIZE};
Expand Down Expand Up @@ -2734,7 +2735,7 @@ fn transact_through_signed_multilocation_para_to_para() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2843,7 +2844,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2969,7 +2970,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -3091,7 +3092,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub type LocationToAccountId = (
// If we receive a MultiLocation of type AccountKey20, just generate a native account
AccountKey20Aliases<RelayNetwork, AccountId>,
// Generate remote accounts according to polkadot standards
xcm_builder::ForeignChainAliasAccount<AccountId>,
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal<AccountId>,
);

/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`.
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2875,7 +2875,7 @@ fn test_xcm_utils_ml_tp_account() {
),
);
let expected_address_alice_in_parachain_2000: H160 =
xcm_builder::ForeignChainAliasAccount::<AccountId>::convert_ref(
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal::<AccountId>::convert_ref(
alice_in_parachain_2000_multilocation.clone(),
)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountKey20Aliases<RelayNetwork, AccountId>,
// Generate remote accounts according to polkadot standards
xcm_builder::ForeignChainAliasAccount<AccountId>,
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal<AccountId>,
);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down
9 changes: 5 additions & 4 deletions runtime/moonbeam/tests/xcm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use pallet_xcm_transactor::{
use sp_core::ConstU32;
use xcm::latest::prelude::*;
use xcm::{VersionedMultiLocation, WrapVersion};
use xcm_builder::HashedDescriptionDescribeFamilyAllTerminal;
use xcm_executor::traits::Convert;
use xcm_mock::parachain;
use xcm_mock::relay_chain;
Expand Down Expand Up @@ -2457,7 +2458,7 @@ fn transact_through_signed_multilocation_para_to_para() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2566,7 +2567,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2692,7 +2693,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2814,7 +2815,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub type LocationToAccountId = (
// If we receive a MultiLocation of type AccountKey20, just generate a native account
AccountKey20Aliases<RelayNetwork, AccountId>,
// Generate remote accounts according to polkadot standards
xcm_builder::ForeignChainAliasAccount<AccountId>,
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal<AccountId>,
);

/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`.
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2784,7 +2784,7 @@ fn test_xcm_utils_ml_tp_account() {
),
);
let expected_address_alice_in_parachain_2000: H160 =
xcm_builder::ForeignChainAliasAccount::<AccountId>::convert_ref(
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal::<AccountId>::convert_ref(
alice_in_parachain_2000_multilocation.clone(),
)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountKey20Aliases<RelayNetwork, AccountId>,
// Generate remote accounts according to polkadot standards
xcm_builder::ForeignChainAliasAccount<AccountId>,
xcm_builder::HashedDescriptionDescribeFamilyAllTerminal<AccountId>,
);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down
9 changes: 5 additions & 4 deletions runtime/moonriver/tests/xcm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use pallet_asset_manager::LocalAssetIdCreator;
use sp_core::ConstU32;
use xcm::latest::prelude::*;
use xcm::{VersionedMultiLocation, WrapVersion};
use xcm_builder::HashedDescriptionDescribeFamilyAllTerminal;
use xcm_executor::traits::Convert;
use xcm_mock::parachain;
use xcm_mock::relay_chain;
Expand Down Expand Up @@ -2769,7 +2770,7 @@ fn transact_through_signed_multilocation_para_to_para() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2878,7 +2879,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -3004,7 +3005,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -3126,7 +3127,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
let derived = HashedDescriptionDescribeFamilyAllTerminal::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down
22 changes: 2 additions & 20 deletions tests/util/xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,10 @@ export function descendOriginFromAddress20(
paraId: number = 1
) {
const toHash = new Uint8Array([
...new TextEncoder().encode("ForeignChainAliasAccountPrefix_Para20"),
...new TextEncoder().encode("SiblingChain"),
...context.polkadotApi.createType("u32", paraId).toU8a(),
...new TextEncoder().encode("AccountKey20"),
...context.polkadotApi.createType("AccountId", address).toU8a(),
...new Uint8Array([1]),
]);

return {
originAddress: address,
descendOriginAddress: u8aToHex(context.polkadotApi.registry.hash(toHash).slice(0, 20)),
};
}

export function descendOriginFromAddress32(
context: DevTestContext,
address: string,
paraId: number = 1
) {
const toHash = new Uint8Array([
...new TextEncoder().encode("ForeignChainAliasAccountPrefix_Para32"),
...context.polkadotApi.createType("u32", paraId).toU8a(),
...context.polkadotApi.createType("AccountId", address).toU8a(),
...new Uint8Array([1]),
]);

return {
Expand Down