Skip to content
17 changes: 7 additions & 10 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,16 +1635,13 @@ fn location_conversion_works() {
},
];

for tc in test_cases {
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
parachain_info::GenesisConfig::<Runtime> {
parachain_id: 1000.into(),
..Default::default()
}
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
parachain_info::GenesisConfig::<Runtime> { parachain_id: 1000.into(), ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
for tc in test_cases {
let expected = AccountId::from_string(tc.expected_account_id_str)
.expect("Invalid AccountId string");

Expand All @@ -1654,8 +1651,8 @@ fn location_conversion_works() {
.unwrap();

assert_eq!(got, expected, "{}", tc.description);
});
}
}
});
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1605,16 +1605,13 @@ fn location_conversion_works() {
},
];

for tc in test_cases {
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
parachain_info::GenesisConfig::<Runtime> {
parachain_id: 1000.into(),
..Default::default()
}
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
parachain_info::GenesisConfig::<Runtime> { parachain_id: 1000.into(), ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
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(
Expand All @@ -1623,8 +1620,8 @@ fn location_conversion_works() {
.unwrap();

assert_eq!(got, expected, "{}", tc.description);
});
}
}
});
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
DenyRecursively, 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,
DescribeFamily, EnsureXcmOrigin, ExternalConsensusLocationsConverterFor,
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 @@ -82,6 +83,8 @@ pub type LocationToAccountId = (
AccountId32Aliases<RelayNetwork, AccountId>,
// Foreign locations alias into accounts according to a hash of their standard description.
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
// Different global consensus locations sovereign accounts.
ExternalConsensusLocationsConverterFor<UniversalLocation, AccountId>,
);

/// Means for transacting the native currency on this chain.
Expand Down
149 changes: 136 additions & 13 deletions cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ use bridge_hub_rococo_runtime::{
use bridge_hub_test_utils::{GovernanceOrigin, SlotDurations};
use codec::{Decode, Encode};
use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8};
use hex_literal::hex;
use parachains_common::{AccountId, AuraId, Balance};
use snowbridge_core::ChannelId;
use sp_consensus_aura::SlotDuration;
use sp_core::{crypto::Ss58Codec, H160};
use sp_keyring::Sr25519Keyring::Alice;
use sp_runtime::{
generic::{Era, SignedPayload},
AccountId32, Perbill,
AccountId32, BuildStorage, Perbill,
};
use testnet_parachains_constants::rococo::{consensus::*, fee::WeightToFee};
use xcm::latest::{prelude::*, ROCOCO_GENESIS_HASH};
use xcm::latest::{prelude::*, ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH};
use xcm_runtime_apis::conversions::LocationToAccountHelper;

parameter_types! {
Expand Down Expand Up @@ -851,20 +852,142 @@ fn location_conversion_works() {
),
expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH",
},
// ExternalConsensusLocationsConverterFor
TestCase {
description: "Describe Ethereum Location",
location: Location::new(2, [GlobalConsensus(Ethereum { chain_id: 11155111 })]),
expected_account_id_str: "5GjRnmh5o3usSYzVmsxBWzHEpvJyHK4tKNPhjpUR3ASrruBy",
},
TestCase {
description: "Describe Ethereum AccountKey",
location: Location::new(
2,
[
GlobalConsensus(Ethereum { chain_id: 11155111 }),
AccountKey20 {
network: None,
key: hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d"),
},
],
),
expected_account_id_str: "5HV4j4AsqT349oLRZmTjhGKDofPBWmWaPUfWGaRkuvzkjW9i",
},
TestCase {
description: "Describe Westend Location",
location: Location::new(2, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]),
expected_account_id_str: "5Fb4pyqFuYLZ43USEAcVUBhFTfTckG9zv9kUaVnmR79YgBCe",
},
TestCase {
description: "Describe Westend AccountID",
location: Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Junction::AccountId32 { network: None, id: AccountId::from(Alice).into() },
],
),
expected_account_id_str: "5EEB1syXCCSEFk26ZYjH47WMp1QjYHf3q5zcnqWWY9Tr6gUc",
},
TestCase {
description: "Describe Westend AccountKey",
location: Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
AccountKey20 { network: None, key: [0u8; 20] },
],
),
expected_account_id_str: "5FzaTcFwUMyX5Sfe7wRGuc3zw1cbpGAGZpmAsxS4tBX6x6U3",
},
TestCase {
description: "Describe Westend Treasury Plurality",
location: Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Plurality { id: BodyId::Treasury, part: BodyPart::Voice },
],
),
expected_account_id_str: "5CpdRCmCYwnxS1mifwEddYHDJR8ydDfTpi1gwAQKQvfAjjzu",
},
TestCase {
description: "Describe Westend Parachain Location",
location: Location::new(
2,
[GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), Parachain(1000)],
),
expected_account_id_str: "5CkWf1L181BiSbvoofnzfSg8ZLiBK3i1U4sknzETHk8QS2mA",
},
TestCase {
description: "Describe Westend Parachain AccountID",
location: Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(1000),
Junction::AccountId32 { network: None, id: AccountId::from(Alice).into() },
],
),
expected_account_id_str: "5HBG915qTKYWzqEs4VocHLCa7ftC7JfJCpvSxk6LmXWJvhbU",
},
TestCase {
description: "Describe Westend Parachain AccountKey",
location: Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(1000),
AccountKey20 { network: None, key: [0u8; 20] },
],
),
expected_account_id_str: "5EFpSvq8BUAjdjY4tuGhGXZ66P16iQnX7nxsNoHy7TM6NhMa",
},
TestCase {
description: "Describe Westend Parachain Treasury Plurality",
location: Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(1000),
Plurality { id: BodyId::Treasury, part: BodyPart::Voice },
],
),
expected_account_id_str: "5GfwA4qaz9wpQPPHmf5MSKqvsPyrfx1yYeeZB1SUkqDuRuZ1",
},
TestCase {
description: "Describe Westend USDT Location",
location: Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(1000),
PalletInstance(50),
GeneralIndex(1984),
],
),
expected_account_id_str: "5Hd77ZjbVRrYiRXER8qo9DRDB8ZzaKtRswZoypMnMLdixzMs",
},
];

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

let got = LocationToAccountHelper::<
AccountId,
bridge_hub_rococo_runtime::xcm_config::LocationToAccountId,
>::convert_location(tc.location.into())
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
parachain_info::GenesisConfig::<Runtime> { parachain_id: 1000.into(), ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

assert_eq!(got, expected, "{}", tc.description);
}
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
for tc in test_cases {
let expected = AccountId::from_string(tc.expected_account_id_str)
.expect("Invalid AccountId string");

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

assert_eq!(got, expected, "{}", tc.description);
}
});
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
DenyRecursively, 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,
DescribeFamily, EnsureXcmOrigin, ExternalConsensusLocationsConverterFor,
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 @@ -81,6 +82,8 @@ pub type LocationToAccountId = (
AccountId32Aliases<RelayNetwork, AccountId>,
// Foreign locations alias into accounts according to a hash of their standard description.
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
// Different global consensus locations sovereign accounts.
ExternalConsensusLocationsConverterFor<UniversalLocation, AccountId>,
);

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