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

Added foreign locations to local accounts converter to all the parachains #5765

Merged
merged 38 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ef70429
Added foreign locations to local accounts converter to all the parach…
x3c41a Sep 19, 2024
6b7e599
added PRdoc
x3c41a Sep 19, 2024
21ae897
Merge branch 'master' into location-converter
x3c41a Sep 19, 2024
25d58a9
".git/.scripts/commands/fmt/fmt.sh"
Sep 19, 2024
eb45a9f
PRDoc fixes and removed unused import
x3c41a Sep 19, 2024
1fc56b0
Update cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/…
x3c41a Sep 19, 2024
7a4d421
restored HashedDescription<AccountId, DescribeTerminus>,
x3c41a Sep 19, 2024
10da40b
added test and formatted affected files
x3c41a Sep 20, 2024
17ee7a7
fixed prdoc
x3c41a Sep 20, 2024
46ec07d
fixed prdoc[2]
x3c41a Sep 20, 2024
90259b5
keep fixing prdoc
x3c41a Sep 20, 2024
527e358
table driven tests for convert_location DescribeAllTerminal
x3c41a Sep 24, 2024
7304799
Added DescribeFamily tests
x3c41a Sep 24, 2024
cca8b20
fixed location_conversion_works tests
x3c41a Sep 24, 2024
18622e5
applied fmt
x3c41a Sep 24, 2024
8341fde
added parent and sibling location conversion tests for parachains
x3c41a Sep 25, 2024
7e32c63
added relay chain tests
x3c41a Sep 25, 2024
93b2162
merged with master
x3c41a Sep 25, 2024
ba7d0f8
fixed wrong merge
x3c41a Sep 25, 2024
f1809c6
fixed parachains Parent tests, added missing AccountId32 in relay tests
x3c41a Sep 26, 2024
450df34
removed a comment
x3c41a Sep 26, 2024
40c2fb3
formatted all the tests
x3c41a Sep 26, 2024
0ad9276
added location conversion tests for the remaining parachains
x3c41a Sep 26, 2024
381e85a
applied fmt
x3c41a Sep 26, 2024
7051ab8
reverted unintended change
x3c41a Sep 26, 2024
7f47fa9
Merge branch 'master' of github.com:paritytech/polkadot-sdk into loca…
acatangiu Sep 27, 2024
65538fe
".git/.scripts/commands/fmt/fmt.sh"
Sep 27, 2024
b60b6fd
moved location conversion test to test root
x3c41a Sep 30, 2024
a849317
added missing imports
x3c41a Sep 30, 2024
8c39253
remvoed unused imports
x3c41a Sep 30, 2024
ad91f4c
Merge branch 'master' into location-converter
x3c41a Sep 30, 2024
f9227a4
removed unused import
x3c41a Sep 30, 2024
434e233
removed open_and_close_bridge_works test
x3c41a Sep 30, 2024
789b8c1
Merge branch 'master' into location-converter
x3c41a Sep 30, 2024
9d630f1
Merge branch 'master' into location-converter
x3c41a Oct 1, 2024
f295ab3
fixed prdoc
x3c41a Oct 1, 2024
314732c
Merge branch 'master' into location-converter
acatangiu Oct 1, 2024
6ec06b3
Merge branch 'master' into location-converter
x3c41a Oct 2, 2024
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
111 changes: 111 additions & 0 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ use frame_support::{
};
use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance};
use sp_consensus_aura::SlotDuration;
use sp_core::crypto::Ss58Codec;
use sp_runtime::traits::MaybeEquivalence;
use std::convert::Into;
use testnet_parachains_constants::rococo::{consensus::*, currency::UNITS, fee::WeightToFee};
use xcm::latest::prelude::{Assets as XcmAssets, *};
use xcm_builder::WithLatestLocationConverter;
use xcm_executor::traits::{JustTry, WeightTrader};
use xcm_runtime_apis::conversions::LocationToAccountHelper;

const ALICE: [u8; 32] = [1u8; 32];
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
Expand Down Expand Up @@ -1355,3 +1357,112 @@ fn change_xcm_bridge_hub_ethereum_base_fee_by_governance_works() {
},
)
}

#[test]
fn location_conversion_works() {
// the purpose of hardcoded values is to catch an unintended location conversion logic change.
struct TestCase {
description: &'static str,
location: Location,
expected_account_id_str: &'static str,
}

let test_cases = vec![
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
// DescribeTerminus
TestCase {
description: "DescribeTerminus Parent",
location: Location::new(1, Here),
expected_account_id_str: "5Dt6dpkWPwLaH4BBCKJwjiWrFVAGyYk3tLUabvyn4v7KtESG",
acatangiu marked this conversation as resolved.
Show resolved Hide resolved
},
TestCase {
description: "DescribeTerminus Sibling",
location: Location::new(1, [Parachain(1111)]),
expected_account_id_str: "5Eg2fnssmmJnF3z1iZ1NouAuzciDaaDQH7qURAy3w15jULDk",
},
// DescribePalletTerminal
TestCase {
description: "DescribePalletTerminal Parent",
location: Location::new(1, [PalletInstance(50)]),
expected_account_id_str: "5CnwemvaAXkWFVwibiCvf2EjqwiqBi29S5cLLydZLEaEw6jZ",
},
TestCase {
description: "DescribePalletTerminal Sibling",
location: Location::new(1, [Parachain(1111), PalletInstance(50)]),
expected_account_id_str: "5GFBgPjpEQPdaxEnFirUoa51u5erVx84twYxJVuBRAT2UP2g",
},
// DescribeAccountId32Terminal
TestCase {
description: "DescribeAccountId32Terminal Parent",
location: Location::new(
1,
[AccountId32 { network: None, id: AccountId::from(ALICE).into() }],
),
expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4",
},
TestCase {
description: "DescribeAccountId32Terminal Sibling",
location: Location::new(
1,
[
Parachain(1111),
Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() },
],
),
expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg",
},
// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg",
},
TestCase {
description: "DescribeAccountKey20Terminal Sibling",
location: Location::new(
1,
[Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }],
),
expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg",
},
// DescribeTreasuryVoiceTerminal
TestCase {
description: "DescribeTreasuryVoiceTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]),
expected_account_id_str: "5CUjnE2vgcUCuhxPwFoQ5r7p1DkhujgvMNDHaF2bLqRp4D5F",
},
TestCase {
description: "DescribeTreasuryVoiceTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }],
),
expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB",
},
// DescribeBodyTerminal
TestCase {
description: "DescribeBodyTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Unit, part: BodyPart::Voice }]),
expected_account_id_str: "5EBRMTBkDisEXsaN283SRbzx9Xf2PXwUxxFCJohSGo4jYe6B",
},
TestCase {
description: "DescribeBodyTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }],
),
expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH",
},
];

for tc in test_cases {
let expected =
AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string");

let got = LocationToAccountHelper::<AccountId, LocationToAccountId>::convert_location(
tc.location.into(),
)
.unwrap();

assert_eq!(got, expected, "{}", tc.description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
DenyReserveTransferToRelayChain, DenyThenTry, DescribeFamily, DescribePalletTerminal,
DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily,
EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter,
GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete, LocalMint,
MatchedConvertedConcreteId, NetworkExportTableItem, NoChecking, NonFungiblesAdapter,
Expand Down Expand Up @@ -93,9 +93,8 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RelayNetwork, AccountId>,
// Foreign chain account alias into local accounts according to a hash of their standard
// description.
HashedDescription<AccountId, DescribeFamily<DescribePalletTerminal>>,
// Foreign locations alias into accounts according to a hash of their standard description.
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
// Different global consensus parachain sovereign account.
// (Used for over-bridge transfers and reserve processing)
GlobalConsensusParachainConvertsFor<UniversalLocation, AccountId>,
Expand Down
111 changes: 111 additions & 0 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ use frame_support::{
};
use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance};
use sp_consensus_aura::SlotDuration;
use sp_core::crypto::Ss58Codec;
use sp_runtime::traits::MaybeEquivalence;
use std::{convert::Into, ops::Mul};
use testnet_parachains_constants::westend::{consensus::*, currency::UNITS, fee::WeightToFee};
use xcm::latest::prelude::{Assets as XcmAssets, *};
use xcm_builder::WithLatestLocationConverter;
use xcm_executor::traits::{ConvertLocation, JustTry, WeightTrader};
use xcm_runtime_apis::conversions::LocationToAccountHelper;

const ALICE: [u8; 32] = [1u8; 32];
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
Expand Down Expand Up @@ -1329,3 +1331,112 @@ fn reserve_transfer_native_asset_to_non_teleport_para_works() {
WeightLimit::Unlimited,
);
}

#[test]
fn location_conversion_works() {
// the purpose of hardcoded values is to catch an unintended location conversion logic change.
struct TestCase {
description: &'static str,
location: Location,
expected_account_id_str: &'static str,
}

let test_cases = vec![
// DescribeTerminus
TestCase {
description: "DescribeTerminus Parent",
location: Location::new(1, Here),
expected_account_id_str: "5Dt6dpkWPwLaH4BBCKJwjiWrFVAGyYk3tLUabvyn4v7KtESG",
},
TestCase {
description: "DescribeTerminus Sibling",
location: Location::new(1, [Parachain(1111)]),
expected_account_id_str: "5Eg2fnssmmJnF3z1iZ1NouAuzciDaaDQH7qURAy3w15jULDk",
},
// DescribePalletTerminal
TestCase {
description: "DescribePalletTerminal Parent",
location: Location::new(1, [PalletInstance(50)]),
expected_account_id_str: "5CnwemvaAXkWFVwibiCvf2EjqwiqBi29S5cLLydZLEaEw6jZ",
},
TestCase {
description: "DescribePalletTerminal Sibling",
location: Location::new(1, [Parachain(1111), PalletInstance(50)]),
expected_account_id_str: "5GFBgPjpEQPdaxEnFirUoa51u5erVx84twYxJVuBRAT2UP2g",
},
// DescribeAccountId32Terminal
TestCase {
description: "DescribeAccountId32Terminal Parent",
location: Location::new(
1,
[AccountId32 { network: None, id: AccountId::from(ALICE).into() }],
),
expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4",
},
TestCase {
description: "DescribeAccountId32Terminal Sibling",
location: Location::new(
1,
[
Parachain(1111),
Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() },
],
),
expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg",
},
// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg",
},
TestCase {
description: "DescribeAccountKey20Terminal Sibling",
location: Location::new(
1,
[Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }],
),
expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg",
},
// DescribeTreasuryVoiceTerminal
TestCase {
description: "DescribeTreasuryVoiceTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]),
expected_account_id_str: "5CUjnE2vgcUCuhxPwFoQ5r7p1DkhujgvMNDHaF2bLqRp4D5F",
},
TestCase {
description: "DescribeTreasuryVoiceTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }],
),
expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB",
},
// DescribeBodyTerminal
TestCase {
description: "DescribeBodyTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Unit, part: BodyPart::Voice }]),
expected_account_id_str: "5EBRMTBkDisEXsaN283SRbzx9Xf2PXwUxxFCJohSGo4jYe6B",
},
TestCase {
description: "DescribeBodyTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }],
),
expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH",
},
];

for tc in test_cases {
let expected =
AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string");

let got = LocationToAccountHelper::<AccountId, LocationToAccountId>::convert_location(
tc.location.into(),
)
.unwrap();

assert_eq!(got, expected, "{}", tc.description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FrameTransactionalProcessor,
FungibleAdapter, HandleFee, IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily,
EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HandleFee, HashedDescription,
IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{
traits::{FeeManager, FeeReason, FeeReason::Export},
Expand Down Expand Up @@ -78,6 +79,8 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RelayNetwork, AccountId>,
// Foreign locations alias into accounts according to a hash of their standard description.
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
x3c41a marked this conversation as resolved.
Show resolved Hide resolved
);

/// Means for transacting the native currency on this chain.
Expand Down
Loading
Loading