From 01ffdc2b423d1f9e2373e7ae412b81e3ad4d4b27 Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 17 Oct 2024 16:27:26 +0300 Subject: [PATCH 01/11] added location conversion to relays and parachains --- relay/kusama/tests/location_conversion.rs | 132 ++++++++++++++++++ relay/polkadot/tests/location_conversion.rs | 132 ++++++++++++++++++ .../asset-hub-kusama/tests/tests.rs | 111 +++++++++++++++ .../asset-hub-polkadot/tests/tests.rs | 111 +++++++++++++++ .../bridge-hub-kusama/tests/tests.rs | 111 +++++++++++++++ .../bridge-hub-polkadot/tests/tests.rs | 111 +++++++++++++++ .../tests/location_conversion.rs | 132 ++++++++++++++++++ .../coretime/coretime-kusama/src/tests.rs | 116 ++++++++++++++- .../coretime/coretime-polkadot/src/tests.rs | 116 ++++++++++++++- .../people/people-kusama/src/lib.rs | 1 + .../people/people-kusama/src/tests.rs | 132 ++++++++++++++++++ .../people/people-polkadot/src/lib.rs | 1 + .../people/people-polkadot/src/tests.rs | 132 ++++++++++++++++++ 13 files changed, 1334 insertions(+), 4 deletions(-) create mode 100644 relay/kusama/tests/location_conversion.rs create mode 100644 relay/polkadot/tests/location_conversion.rs create mode 100644 system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs create mode 100644 system-parachains/people/people-kusama/src/tests.rs create mode 100644 system-parachains/people/people-polkadot/src/tests.rs diff --git a/relay/kusama/tests/location_conversion.rs b/relay/kusama/tests/location_conversion.rs new file mode 100644 index 0000000000..6aa6793783 --- /dev/null +++ b/relay/kusama/tests/location_conversion.rs @@ -0,0 +1,132 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use polkadot_primitives::AccountId; +use sp_core::crypto::Ss58Codec; +use xcm::prelude::*; +use xcm_runtime_apis::conversions::LocationToAccountHelper; +use staging_kusama_runtime::xcm_config::SovereignAccountOf; + +const ALICE: [u8; 32] = [1u8; 32]; + +#[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: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD", + }, + TestCase { + description: "DescribeTerminus Sibling", + location: Location::new(1, [Parachain(1111)]), + expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk", + }, + // 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::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/relay/polkadot/tests/location_conversion.rs b/relay/polkadot/tests/location_conversion.rs new file mode 100644 index 0000000000..d256ea1f52 --- /dev/null +++ b/relay/polkadot/tests/location_conversion.rs @@ -0,0 +1,132 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use polkadot_primitives::AccountId; +use polkadot_runtime::xcm_config::SovereignAccountOf; +use sp_core::crypto::Ss58Codec; +use xcm::prelude::*; +use xcm_runtime_apis::conversions::LocationToAccountHelper; + +const ALICE: [u8; 32] = [1u8; 32]; + +#[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: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD", + }, + TestCase { + description: "DescribeTerminus Sibling", + location: Location::new(1, [Parachain(1111)]), + expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk", + }, + // 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::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 9e3e2ded06..21becfd4aa 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -37,6 +37,7 @@ use frame_support::{assert_ok, traits::fungibles::InspectEnumerable}; use parachains_common::{AccountId, AssetIdForTrustBackedAssets, AuraId, Balance}; use parachains_runtimes_test_utils::SlotDurations; use sp_consensus_aura::SlotDuration; +use sp_core::crypto::Ss58Codec; use sp_runtime::traits::MaybeEquivalence; use sp_std::ops::Mul; use system_parachains_constants::kusama::{ @@ -45,6 +46,7 @@ use system_parachains_constants::kusama::{ use xcm::latest::prelude::{Assets as XcmAssets, *}; use xcm_builder::WithLatestLocationConverter; use xcm_executor::traits::{ConvertLocation, JustTry}; +use xcm_runtime_apis::conversions::LocationToAccountHelper; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; @@ -706,3 +708,112 @@ fn treasury_pallet_account_not_none() { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() ) } + +#[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: polkadot_core_primitives::AccountId::from(ALICE).into() }], + ), + expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", + }, + TestCase { + description: "DescribeAccountId32Terminal Sibling", + location: Location::new( + 1, + [ + Parachain(1111), + Junction::AccountId32 { network: None, id: polkadot_core_primitives::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 = + polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 7da4172102..a55287ff61 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -39,6 +39,7 @@ use parachains_common::{ }; use parachains_runtimes_test_utils::SlotDurations; use sp_consensus_aura::SlotDuration; +use sp_core::crypto::Ss58Codec; use sp_runtime::traits::MaybeEquivalence; use sp_std::ops::Mul; use system_parachains_constants::{ @@ -47,6 +48,7 @@ use system_parachains_constants::{ use xcm::latest::prelude::{Assets as XcmAssets, *}; use xcm_builder::WithLatestLocationConverter; use xcm_executor::traits::{ConvertLocation, JustTry}; +use xcm_runtime_apis::conversions::LocationToAccountHelper; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; @@ -730,3 +732,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![ + // 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: polkadot_core_primitives::AccountId::from(ALICE).into() }], + ), + expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", + }, + TestCase { + description: "DescribeAccountId32Terminal Sibling", + location: Location::new( + 1, + [ + Parachain(1111), + Junction::AccountId32 { network: None, id: polkadot_core_primitives::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 = + polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 805f8cb051..9ba9b0be29 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -36,6 +36,7 @@ use codec::{Decode, Encode}; use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8}; use parachains_common::{AccountId, AuraId, Balance}; use sp_consensus_aura::SlotDuration; +use sp_core::crypto::Ss58Codec; use sp_keyring::AccountKeyring::Alice; use sp_runtime::{ generic::{Era, SignedPayload}, @@ -46,6 +47,7 @@ use system_parachains_constants::kusama::{ }; use xcm::latest::prelude::*; use xcm_executor::traits::ConvertLocation; +use xcm_runtime_apis::conversions::LocationToAccountHelper; // Para id of sibling chain used in tests. pub const SIBLING_PARACHAIN_ID: u32 = 1000; @@ -367,3 +369,112 @@ fn treasury_pallet_account_not_none() { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() ) } + +#[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, + [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }], + ), + expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", + }, + TestCase { + description: "DescribeAccountId32Terminal Sibling", + location: Location::new( + 1, + [ + Parachain(1111), + Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }, + ], + ), + expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", + }, + // 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 = + polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index c3301047cd..8be231d526 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -37,6 +37,7 @@ use codec::{Decode, Encode}; use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8}; use parachains_common::{AccountId, AuraId, Balance}; use sp_consensus_aura::SlotDuration; +use sp_core::crypto::Ss58Codec; use sp_keyring::AccountKeyring::Alice; use sp_runtime::{ generic::{Era, SignedPayload}, @@ -47,6 +48,7 @@ use system_parachains_constants::polkadot::{ }; use xcm::latest::prelude::*; use xcm_executor::traits::ConvertLocation; +use xcm_runtime_apis::conversions::LocationToAccountHelper; // Para id of sibling chain used in tests. pub const SIBLING_PARACHAIN_ID: u32 = 1000; @@ -368,3 +370,112 @@ fn treasury_pallet_account_not_none() { LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap() ) } + +#[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, + [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }], + ), + expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", + }, + TestCase { + description: "DescribeAccountId32Terminal Sibling", + location: Location::new( + 1, + [ + Parachain(1111), + Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }, + ], + ), + expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", + }, + // 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 = + polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs new file mode 100644 index 0000000000..42ab6d314a --- /dev/null +++ b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs @@ -0,0 +1,132 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use polkadot_core_primitives::AccountId; +use sp_core::crypto::Ss58Codec; +use xcm::prelude::*; +use xcm_runtime_apis::conversions::LocationToAccountHelper; +use collectives_polkadot_runtime::xcm_config::LocationToAccountId; + +const ALICE: [u8; 32] = [1u8; 32]; + +#[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::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index 0253477c2e..23c892243b 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -29,7 +29,12 @@ use frame_support::{ use kusama_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; use parachains_runtimes_test_utils::ExtBuilder; +use sp_core::crypto::Ss58Codec; use sp_runtime::traits::AccountIdConversion; +use xcm_runtime_apis::conversions::LocationToAccountHelper; +use crate::xcm_config::LocationToAccountId; + +const ALICE: [u8; 32] = [1u8; 32]; fn advance_to(b: BlockNumber) { while System::block_number() < b { @@ -41,8 +46,6 @@ fn advance_to(b: BlockNumber) { #[test] fn bulk_revenue_is_burnt() { - const ALICE: [u8; 32] = [1u8; 32]; - ExtBuilder::::default() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( @@ -110,3 +113,112 @@ fn timeslice_period_is_sane() { #[cfg(not(feature = "fast-runtime"))] assert_eq!(TIMESLICE_PERIOD, 80); } + +#[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, + [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }], + ), + expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", + }, + TestCase { + description: "DescribeAccountId32Terminal Sibling", + location: Location::new( + 1, + [ + Parachain(1111), + Junction::AccountId32 { network: None, id: polkadot_core_primitives::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 = + polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index 3ec85da4b2..e9730c60d7 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -28,8 +28,13 @@ use frame_support::{ }; use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; use parachains_runtimes_test_utils::ExtBuilder; +use sp_core::crypto::Ss58Codec; use polkadot_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; use sp_runtime::traits::AccountIdConversion; +use xcm_runtime_apis::conversions::LocationToAccountHelper; +use crate::xcm_config::LocationToAccountId; + +const ALICE: [u8; 32] = [1u8; 32]; fn advance_to(b: BlockNumber) { while System::block_number() < b { @@ -41,8 +46,6 @@ fn advance_to(b: BlockNumber) { #[test] fn bulk_revenue_is_burnt() { - const ALICE: [u8; 32] = [1u8; 32]; - ExtBuilder::::default() .with_collators(vec![AccountId::from(ALICE)]) .with_session_keys(vec![( @@ -110,3 +113,112 @@ fn timeslice_period_is_sane() { #[cfg(not(feature = "fast-runtime"))] assert_eq!(TIMESLICE_PERIOD, 80); } + +#[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, + [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }], + ), + expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", + }, + TestCase { + description: "DescribeAccountId32Terminal Sibling", + location: Location::new( + 1, + [ + Parachain(1111), + Junction::AccountId32 { network: None, id: polkadot_core_primitives::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 = + polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/people/people-kusama/src/lib.rs b/system-parachains/people/people-kusama/src/lib.rs index 3cc6c85e53..d0fc682f69 100644 --- a/system-parachains/people/people-kusama/src/lib.rs +++ b/system-parachains/people/people-kusama/src/lib.rs @@ -23,6 +23,7 @@ pub mod genesis_config_presets; pub mod people; mod weights; pub mod xcm_config; +mod tests; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs new file mode 100644 index 0000000000..c433653482 --- /dev/null +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -0,0 +1,132 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use polkadot_primitives::AccountId; +use sp_core::crypto::Ss58Codec; +use xcm::prelude::*; +use xcm_runtime_apis::conversions::LocationToAccountHelper; +use crate::xcm_config::LocationToAccountId; + +const ALICE: [u8; 32] = [1u8; 32]; + +#[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, + [xcm::prelude::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::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} diff --git a/system-parachains/people/people-polkadot/src/lib.rs b/system-parachains/people/people-polkadot/src/lib.rs index 4dd70c027b..0c0ccd2722 100644 --- a/system-parachains/people/people-polkadot/src/lib.rs +++ b/system-parachains/people/people-polkadot/src/lib.rs @@ -23,6 +23,7 @@ pub mod genesis_config_presets; pub mod people; mod weights; pub mod xcm_config; +mod tests; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs new file mode 100644 index 0000000000..5d0dbd7a20 --- /dev/null +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -0,0 +1,132 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use cumulus_primitives_core::relay_chain::AccountId; +use sp_core::crypto::Ss58Codec; +use xcm::prelude::*; +use xcm_runtime_apis::conversions::LocationToAccountHelper; +use crate::xcm_config::LocationToAccountId; + +const ALICE: [u8; 32] = [1u8; 32]; + +#[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, + [xcm::prelude::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::::convert_location( + tc.location.into(), + ) + .unwrap(); + + assert_eq!(got, expected, "{}", tc.description); + } +} From 2e0bc1d731c4a16939a4b680669c8e1c9df55196 Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 17 Oct 2024 19:39:54 +0300 Subject: [PATCH 02/11] added test macro and formatted the crate --- .../people/people-polkadot/src/lib.rs | 3 +- .../people/people-polkadot/src/tests.rs | 204 +++++++++--------- 2 files changed, 104 insertions(+), 103 deletions(-) diff --git a/system-parachains/people/people-polkadot/src/lib.rs b/system-parachains/people/people-polkadot/src/lib.rs index 0c0ccd2722..a439971e5f 100644 --- a/system-parachains/people/people-polkadot/src/lib.rs +++ b/system-parachains/people/people-polkadot/src/lib.rs @@ -21,9 +21,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); // Genesis preset configurations. pub mod genesis_config_presets; pub mod people; +#[cfg(test)] +mod tests; mod weights; pub mod xcm_config; -mod tests; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index 5d0dbd7a20..12faa07e47 100644 --- a/system-parachains/people/people-polkadot/src/tests.rs +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -14,119 +14,119 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::xcm_config::LocationToAccountId; use cumulus_primitives_core::relay_chain::AccountId; use sp_core::crypto::Ss58Codec; use xcm::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; -use crate::xcm_config::LocationToAccountId; const ALICE: [u8; 32] = [1u8; 32]; #[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, - } + // 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, - [xcm::prelude::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", - }, - ]; + 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, + [xcm::prelude::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"); + for tc in test_cases { + let expected = + AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); - let got = LocationToAccountHelper::::convert_location( - tc.location.into(), - ) - .unwrap(); + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); - assert_eq!(got, expected, "{}", tc.description); - } + assert_eq!(got, expected, "{}", tc.description); + } } From aa53f0ed84d6dc184800e1d9586be2e6dab700b8 Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 17 Oct 2024 19:48:09 +0300 Subject: [PATCH 03/11] added missing test macro and formatted test files --- relay/kusama/src/lib.rs | 3 +- relay/kusama/tests/location_conversion.rs | 204 +++++++++--------- relay/polkadot/src/lib.rs | 3 +- .../asset-hubs/asset-hub-kusama/src/lib.rs | 3 +- .../asset-hub-kusama/src/xcm_config.rs | 3 +- .../asset-hub-kusama/tests/tests.rs | 14 +- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 3 +- .../asset-hub-polkadot/src/xcm_config.rs | 3 +- .../asset-hub-polkadot/tests/tests.rs | 14 +- .../bridge-hub-kusama/tests/tests.rs | 14 +- .../bridge-hub-polkadot/tests/tests.rs | 14 +- .../tests/location_conversion.rs | 2 +- .../coretime/coretime-kusama/src/tests.rs | 16 +- .../coretime/coretime-polkadot/src/tests.rs | 18 +- .../people/people-kusama/src/lib.rs | 3 +- .../people/people-kusama/src/tests.rs | 204 +++++++++--------- 16 files changed, 282 insertions(+), 239 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 13d0bfbbda..87d8620b13 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1213,7 +1213,8 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | + RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) diff --git a/relay/kusama/tests/location_conversion.rs b/relay/kusama/tests/location_conversion.rs index 6aa6793783..db9c37a0d0 100644 --- a/relay/kusama/tests/location_conversion.rs +++ b/relay/kusama/tests/location_conversion.rs @@ -16,117 +16,117 @@ use polkadot_primitives::AccountId; use sp_core::crypto::Ss58Codec; +use staging_kusama_runtime::xcm_config::SovereignAccountOf; use xcm::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; -use staging_kusama_runtime::xcm_config::SovereignAccountOf; const ALICE: [u8; 32] = [1u8; 32]; #[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, - } + // 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: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD", - }, - TestCase { - description: "DescribeTerminus Sibling", - location: Location::new(1, [Parachain(1111)]), - expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk", - }, - // 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", - }, - ]; + let test_cases = vec![ + // DescribeTerminus + TestCase { + description: "DescribeTerminus Parent", + location: Location::new(1, Here), + expected_account_id_str: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD", + }, + TestCase { + description: "DescribeTerminus Sibling", + location: Location::new(1, [Parachain(1111)]), + expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk", + }, + // 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"); + for tc in test_cases { + let expected = + AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); - let got = LocationToAccountHelper::::convert_location( - tc.location.into(), - ) - .unwrap(); + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); - assert_eq!(got, expected, "{}", tc.description); - } + assert_eq!(got, expected, "{}", tc.description); + } } diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 7431585f0d..bf0b10ddec 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1183,7 +1183,8 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | + RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 141b693afe..9f9e59addd 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -568,7 +568,8 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 2da556f7ce..1d3e46419c 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -603,7 +603,8 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair for RemoteAssetFromLocation + ContainsPair + for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 21becfd4aa..2d6a3bac62 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -746,7 +746,10 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }], + [AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -756,7 +759,10 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }, + Junction::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }, ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -806,8 +812,8 @@ fn location_conversion_works() { ]; for tc in test_cases { - let expected = - polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + let expected = polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str) + .expect("Invalid AccountId string"); let got = LocationToAccountHelper::::convert_location( tc.location.into(), diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 87bcd43d17..6eb282cf69 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -492,7 +492,8 @@ impl InstanceFilter for ProxyType { RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index c127a0f17c..11470ed800 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -671,7 +671,8 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair for RemoteAssetFromLocation + ContainsPair + for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index a55287ff61..4442966b83 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -770,7 +770,10 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }], + [AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -780,7 +783,10 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }, + Junction::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }, ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -830,8 +836,8 @@ fn location_conversion_works() { ]; for tc in test_cases { - let expected = - polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + let expected = polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str) + .expect("Invalid AccountId string"); let got = LocationToAccountHelper::::convert_location( tc.location.into(), diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 9ba9b0be29..d74f627f54 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -407,7 +407,10 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }], + [xcm::prelude::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(Alice).into(), + }], ), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, @@ -417,7 +420,10 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }, + Junction::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(Alice).into(), + }, ], ), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", @@ -467,8 +473,8 @@ fn location_conversion_works() { ]; for tc in test_cases { - let expected = - polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + let expected = polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str) + .expect("Invalid AccountId string"); let got = LocationToAccountHelper::::convert_location( tc.location.into(), diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 8be231d526..1526e9af27 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -408,7 +408,10 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }], + [xcm::prelude::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(Alice).into(), + }], ), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, @@ -418,7 +421,10 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(Alice).into() }, + Junction::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(Alice).into(), + }, ], ), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", @@ -468,8 +474,8 @@ fn location_conversion_works() { ]; for tc in test_cases { - let expected = - polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + let expected = polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str) + .expect("Invalid AccountId string"); let got = LocationToAccountHelper::::convert_location( tc.location.into(), diff --git a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs index 42ab6d314a..1f93e04d6f 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . +use collectives_polkadot_runtime::xcm_config::LocationToAccountId; use polkadot_core_primitives::AccountId; use sp_core::crypto::Ss58Codec; use xcm::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; -use collectives_polkadot_runtime::xcm_config::LocationToAccountId; const ALICE: [u8; 32] = [1u8; 32]; diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index 23c892243b..743659c48c 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -16,6 +16,7 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, + xcm_config::LocationToAccountId, *, }; use coretime::CoretimeAllocator; @@ -32,7 +33,6 @@ use parachains_runtimes_test_utils::ExtBuilder; use sp_core::crypto::Ss58Codec; use sp_runtime::traits::AccountIdConversion; use xcm_runtime_apis::conversions::LocationToAccountHelper; -use crate::xcm_config::LocationToAccountId; const ALICE: [u8; 32] = [1u8; 32]; @@ -151,7 +151,10 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }], + [xcm::prelude::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -161,7 +164,10 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }, + Junction::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }, ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -211,8 +217,8 @@ fn location_conversion_works() { ]; for tc in test_cases { - let expected = - polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + let expected = polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str) + .expect("Invalid AccountId string"); let got = LocationToAccountHelper::::convert_location( tc.location.into(), diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index e9730c60d7..67a1696a95 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -16,6 +16,7 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, + xcm_config::LocationToAccountId, *, }; use coretime::CoretimeAllocator; @@ -28,11 +29,10 @@ use frame_support::{ }; use pallet_broker::{ConfigRecordOf, RCBlockNumberOf, SaleInfo}; use parachains_runtimes_test_utils::ExtBuilder; -use sp_core::crypto::Ss58Codec; use polkadot_runtime_constants::system_parachain::coretime::TIMESLICE_PERIOD; +use sp_core::crypto::Ss58Codec; use sp_runtime::traits::AccountIdConversion; use xcm_runtime_apis::conversions::LocationToAccountHelper; -use crate::xcm_config::LocationToAccountId; const ALICE: [u8; 32] = [1u8; 32]; @@ -151,7 +151,10 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }], + [xcm::prelude::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -161,7 +164,10 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }, + Junction::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }, ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -211,8 +217,8 @@ fn location_conversion_works() { ]; for tc in test_cases { - let expected = - polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); + let expected = polkadot_core_primitives::AccountId::from_string(tc.expected_account_id_str) + .expect("Invalid AccountId string"); let got = LocationToAccountHelper::::convert_location( tc.location.into(), diff --git a/system-parachains/people/people-kusama/src/lib.rs b/system-parachains/people/people-kusama/src/lib.rs index d0fc682f69..314dbc581f 100644 --- a/system-parachains/people/people-kusama/src/lib.rs +++ b/system-parachains/people/people-kusama/src/lib.rs @@ -21,9 +21,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); // Genesis preset configurations. pub mod genesis_config_presets; pub mod people; +#[cfg(test)] +mod tests; mod weights; pub mod xcm_config; -mod tests; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index c433653482..dcd0045625 100644 --- a/system-parachains/people/people-kusama/src/tests.rs +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -14,119 +14,119 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::xcm_config::LocationToAccountId; use polkadot_primitives::AccountId; use sp_core::crypto::Ss58Codec; use xcm::prelude::*; use xcm_runtime_apis::conversions::LocationToAccountHelper; -use crate::xcm_config::LocationToAccountId; const ALICE: [u8; 32] = [1u8; 32]; #[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, - } + // 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, - [xcm::prelude::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", - }, - ]; + 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, + [xcm::prelude::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"); + for tc in test_cases { + let expected = + AccountId::from_string(tc.expected_account_id_str).expect("Invalid AccountId string"); - let got = LocationToAccountHelper::::convert_location( - tc.location.into(), - ) - .unwrap(); + let got = LocationToAccountHelper::::convert_location( + tc.location.into(), + ) + .unwrap(); - assert_eq!(got, expected, "{}", tc.description); - } + assert_eq!(got, expected, "{}", tc.description); + } } From 438c935450b4031dfe37dddceade6e51b54ebf72 Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 17 Oct 2024 20:25:46 +0300 Subject: [PATCH 04/11] reverted unintended fmt changes caused by wrong version of nighly formatter --- relay/kusama/src/lib.rs | 3 +-- relay/polkadot/src/lib.rs | 3 +-- system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs | 3 +-- .../asset-hubs/asset-hub-kusama/src/xcm_config.rs | 3 +-- system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 3 +-- .../asset-hubs/asset-hub-polkadot/src/xcm_config.rs | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 87d8620b13..13d0bfbbda 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -1213,8 +1213,7 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | - RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index bf0b10ddec..7431585f0d 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1183,8 +1183,7 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | - RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 9f9e59addd..141b693afe 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -568,8 +568,7 @@ impl InstanceFilter for ProxyType { RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | RuntimeCall::NftFractionalization { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 1d3e46419c..4e6e055104 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -603,8 +603,7 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair - for RemoteAssetFromLocation + ContainsPair for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 6eb282cf69..87bcd43d17 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -492,8 +492,7 @@ impl InstanceFilter for ProxyType { RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 11470ed800..c127a0f17c 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -671,8 +671,7 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair - for RemoteAssetFromLocation + ContainsPair for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) From b94f2a2c93b9cb4f2a5ba5c9a0d9f91b4a1919cc Mon Sep 17 00:00:00 2001 From: ndk Date: Thu, 17 Oct 2024 21:39:51 +0300 Subject: [PATCH 05/11] removed an extra space --- system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 4e6e055104..2da556f7ce 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -603,7 +603,7 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair for RemoteAssetFromLocation + ContainsPair for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) From 2c0661a4bf78c8dc8ec4ffe1d503f3fcd0331364 Mon Sep 17 00:00:00 2001 From: ndk Date: Fri, 18 Oct 2024 11:59:34 +0300 Subject: [PATCH 06/11] modified changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d9cbc5dfd..62e63e0467 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Change Polkadot inflation to 120M DOT per year ([polkadot-fellows/runtimes#471](https://github.com/polkadot-fellows/runtimes/pull/471)) +### Added + +- Location conversion tests for relays and parachains ([polkadot-fellows/runtimes#487](https://github.com/polkadot-fellows/runtimes/pull/487)) + ## [1.3.3] 01.10.2024 ### Changed From e3818206d4fc2ed296ca98877ecbf4c6d1975d23 Mon Sep 17 00:00:00 2001 From: ndk Date: Wed, 23 Oct 2024 11:54:02 +0300 Subject: [PATCH 07/11] changed relay conversion tests --- relay/kusama/tests/location_conversion.rs | 69 ++++++-------------- relay/polkadot/tests/location_conversion.rs | 71 ++++++--------------- 2 files changed, 37 insertions(+), 103 deletions(-) diff --git a/relay/kusama/tests/location_conversion.rs b/relay/kusama/tests/location_conversion.rs index db9c37a0d0..d5c3557c32 100644 --- a/relay/kusama/tests/location_conversion.rs +++ b/relay/kusama/tests/location_conversion.rs @@ -34,87 +34,54 @@ fn location_conversion_works() { let test_cases = vec![ // DescribeTerminus TestCase { - description: "DescribeTerminus Parent", - location: Location::new(1, Here), - expected_account_id_str: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD", - }, - TestCase { - description: "DescribeTerminus Sibling", - location: Location::new(1, [Parachain(1111)]), - expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk", + description: "DescribeTerminus Child", + location: Location::new(0, [Parachain(1111)]), + expected_account_id_str: "5Ec4AhP4h37t7TFsAZ4HhFq6k92usAAJDUC3ADSZ4H4Acru3", }, // 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", + description: "DescribePalletTerminal Child", + location: Location::new(0, [Parachain(1111), PalletInstance(50)]), + expected_account_id_str: "5FjEBrKn3STAFsZpQF4jzwxUYHNGnNgzdZqSQfTzeJ82XKp6", }, // 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", + description: "DescribeAccountId32Terminal Child", location: Location::new( - 1, + 0, [ Parachain(1111), Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() }, ], ), - expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", + expected_account_id_str: "5D6CDyPd9Mya81xFN3nChiKqLvUzd8zS9fwKhfCW6FtJKjS2", }, // 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] }], + 0, + [Parachain(1111), AccountKey20 { network: None, key: [123u8; 20] }], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5DEZsy7tsnNXB7ehLGkF8b4EUqfLQWqEzGiy2RrneC8uRNMK", }, // 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", + description: "DescribeTreasuryVoiceTerminal Child", location: Location::new( - 1, + 0, [Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }], ), - expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB", + expected_account_id_str: "5GenE4vJgHvwYVcD6b4nBvH5HNY4pzpVHWoqwFpNMFT7a2oX", }, // 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", + description: "DescribeBodyTerminal Child", location: Location::new( - 1, + 0, [Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }], ), - expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH", + expected_account_id_str: "5DPgGBFTTYm1dGbtB1VWHJ3T3ScvdrskGGx6vSJZNP1WNStV", }, ]; diff --git a/relay/polkadot/tests/location_conversion.rs b/relay/polkadot/tests/location_conversion.rs index d256ea1f52..bfa899bf5f 100644 --- a/relay/polkadot/tests/location_conversion.rs +++ b/relay/polkadot/tests/location_conversion.rs @@ -34,87 +34,54 @@ fn location_conversion_works() { let test_cases = vec![ // DescribeTerminus TestCase { - description: "DescribeTerminus Parent", - location: Location::new(1, Here), - expected_account_id_str: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD", - }, - TestCase { - description: "DescribeTerminus Sibling", - location: Location::new(1, [Parachain(1111)]), - expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk", + description: "DescribeTerminus Child", + location: Location::new(0, [Parachain(1111)]), + expected_account_id_str: "5Ec4AhP4h37t7TFsAZ4HhFq6k92usAAJDUC3ADSZ4H4Acru3", }, // 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", + description: "DescribePalletTerminal Child", + location: Location::new(0, [Parachain(1111), PalletInstance(50)]), + expected_account_id_str: "5FjEBrKn3STAFsZpQF4jzwxUYHNGnNgzdZqSQfTzeJ82XKp6", }, // 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", + description: "DescribeAccountId32Terminal Child", location: Location::new( - 1, + 0, [ Parachain(1111), Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() }, ], ), - expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", + expected_account_id_str: "5D6CDyPd9Mya81xFN3nChiKqLvUzd8zS9fwKhfCW6FtJKjS2", }, // DescribeAccountKey20Terminal TestCase { - description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", - }, - TestCase { - description: "DescribeAccountKey20Terminal Sibling", + description: "DescribeAccountKey20Terminal Child", location: Location::new( - 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + 0, + [Parachain(1111), AccountKey20 { network: None, key: [123u8; 20] }], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5DEZsy7tsnNXB7ehLGkF8b4EUqfLQWqEzGiy2RrneC8uRNMK", }, // 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", + description: "DescribeTreasuryVoiceTerminal Child", location: Location::new( - 1, + 0, [Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }], ), - expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB", + expected_account_id_str: "5GenE4vJgHvwYVcD6b4nBvH5HNY4pzpVHWoqwFpNMFT7a2oX", }, // 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", + description: "DescribeBodyTerminal Child", location: Location::new( - 1, + 0, [Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }], ), - expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH", + expected_account_id_str: "5DPgGBFTTYm1dGbtB1VWHJ3T3ScvdrskGGx6vSJZNP1WNStV", }, ]; From ce255ad25b85f51a6f3e74dc7c2b5ab9045d9563 Mon Sep 17 00:00:00 2001 From: ndk Date: Wed, 23 Oct 2024 13:39:39 +0300 Subject: [PATCH 08/11] refactored system-parachain tests --- .../asset-hub-kusama/tests/tests.rs | 24 +++++++++---------- .../asset-hub-polkadot/tests/tests.rs | 24 +++++++++---------- .../bridge-hub-kusama/tests/tests.rs | 24 +++++++++---------- .../bridge-hub-polkadot/tests/tests.rs | 24 +++++++++---------- .../tests/location_conversion.rs | 18 +++++++++----- .../coretime/coretime-kusama/src/tests.rs | 24 +++++++++---------- .../coretime/coretime-polkadot/src/tests.rs | 24 +++++++++---------- .../people/people-kusama/src/tests.rs | 18 +++++++++----- .../people/people-polkadot/src/tests.rs | 18 +++++++++----- 9 files changed, 108 insertions(+), 90 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 2d6a3bac62..4b6892d9a1 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -711,6 +711,12 @@ fn treasury_pallet_account_not_none() { #[test] fn location_conversion_works() { + let alice_32 = AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -746,10 +752,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }], + [alice_32.clone()], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -759,10 +762,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }, + alice_32.clone(), ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -770,16 +770,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 4442966b83..a7e603a02c 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -735,6 +735,12 @@ fn change_xcm_bridge_hub_ethereum_base_fee_by_governance_works() { #[test] fn location_conversion_works() { + let alice_32 = AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -770,10 +776,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }], + [alice_32.clone()], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -783,10 +786,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }, + alice_32.clone(), ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -794,16 +794,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index d74f627f54..05223ad35a 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -372,6 +372,12 @@ fn treasury_pallet_account_not_none() { #[test] fn location_conversion_works() { + let alice_32 = xcm::prelude::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(Alice).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -407,10 +413,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(Alice).into(), - }], + [alice_32.clone()], ), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, @@ -420,10 +423,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(Alice).into(), - }, + alice_32.clone(), ], ), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", @@ -431,16 +431,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 1526e9af27..18bd832422 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -373,6 +373,12 @@ fn treasury_pallet_account_not_none() { #[test] fn location_conversion_works() { + let alice_32 = xcm::prelude::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(Alice).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -408,10 +414,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(Alice).into(), - }], + [alice_32.clone()], ), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, @@ -421,10 +424,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(Alice).into(), - }, + alice_32.clone(), ], ), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", @@ -432,16 +432,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs index 1f93e04d6f..45feb648af 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs @@ -24,6 +24,12 @@ const ALICE: [u8; 32] = [1u8; 32]; #[test] fn location_conversion_works() { + let alice_32 = xcm::prelude::AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -59,7 +65,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [AccountId32 { network: None, id: AccountId::from(ALICE).into() }], + [alice_32.clone()], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -69,7 +75,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() }, + alice_32.clone(), ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -77,16 +83,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index 743659c48c..e03098006b 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -116,6 +116,12 @@ fn timeslice_period_is_sane() { #[test] fn location_conversion_works() { + let alice_32 = AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -151,10 +157,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }], + [alice_32.clone()], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -164,10 +167,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }, + alice_32.clone(), ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -175,16 +175,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index 67a1696a95..bfea18ef9b 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -116,6 +116,12 @@ fn timeslice_period_is_sane() { #[test] fn location_conversion_works() { + let alice_32 = AccountId32 { + network: None, + id: polkadot_core_primitives::AccountId::from(ALICE).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -151,10 +157,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }], + [alice_32.clone()], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -164,10 +167,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }, + alice_32.clone(), ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -175,16 +175,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index dcd0045625..a4849a28ed 100644 --- a/system-parachains/people/people-kusama/src/tests.rs +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -24,6 +24,12 @@ const ALICE: [u8; 32] = [1u8; 32]; #[test] fn location_conversion_works() { + let alice_32 = AccountId32 { + network: None, + id: AccountId::from(ALICE).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -59,7 +65,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { network: None, id: AccountId::from(ALICE).into() }], + [alice_32.clone()], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -69,7 +75,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() }, + alice_32.clone(), ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -77,16 +83,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index 12faa07e47..547f338ade 100644 --- a/system-parachains/people/people-polkadot/src/tests.rs +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -24,6 +24,12 @@ const ALICE: [u8; 32] = [1u8; 32]; #[test] fn location_conversion_works() { + let alice_32 = AccountId32 { + network: None, + id: AccountId::from(ALICE).into(), + }; + let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; + // the purpose of hardcoded values is to catch an unintended location conversion logic change. struct TestCase { description: &'static str, @@ -59,7 +65,7 @@ fn location_conversion_works() { description: "DescribeAccountId32Terminal Parent", location: Location::new( 1, - [xcm::prelude::AccountId32 { network: None, id: AccountId::from(ALICE).into() }], + [alice_32.clone()], ), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, @@ -69,7 +75,7 @@ fn location_conversion_works() { 1, [ Parachain(1111), - Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() }, + alice_32.clone(), ], ), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", @@ -77,16 +83,16 @@ fn location_conversion_works() { // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]), - expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg", + location: Location::new(1, [bob_20.clone()]), + expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", location: Location::new( 1, - [Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }], + [Parachain(1111), bob_20.clone()], ), - expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg", + expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal TestCase { From 331567a8d2ad45af3a2ffc4e48aacf57e22c4d7d Mon Sep 17 00:00:00 2001 From: ndk Date: Wed, 23 Oct 2024 13:48:16 +0300 Subject: [PATCH 09/11] removed extra namespace xcm::prelude:: --- .../collectives-polkadot/tests/location_conversion.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs index 45feb648af..1f3d7d3710 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs @@ -24,9 +24,9 @@ const ALICE: [u8; 32] = [1u8; 32]; #[test] fn location_conversion_works() { - let alice_32 = xcm::prelude::AccountId32 { + let alice_32 = AccountId32 { network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), + id: AccountId::from(ALICE).into(), }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; From ef05ebba4cb500f703a46f717ac9170ed7c62390 Mon Sep 17 00:00:00 2001 From: ndk Date: Wed, 23 Oct 2024 14:38:14 +0300 Subject: [PATCH 10/11] formatted the change --- .../asset-hub-kusama/tests/tests.rs | 24 ++++--------------- .../asset-hub-polkadot/tests/tests.rs | 24 ++++--------------- .../bridge-hub-kusama/tests/tests.rs | 18 +++----------- .../bridge-hub-polkadot/tests/tests.rs | 18 +++----------- .../tests/location_conversion.rs | 23 ++++-------------- .../coretime/coretime-kusama/src/tests.rs | 24 ++++--------------- .../coretime/coretime-polkadot/src/tests.rs | 24 ++++--------------- .../people/people-kusama/src/tests.rs | 23 ++++-------------- .../people/people-polkadot/src/tests.rs | 23 ++++-------------- 9 files changed, 38 insertions(+), 163 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 4b6892d9a1..2848a304f9 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -711,10 +711,8 @@ fn treasury_pallet_account_not_none() { #[test] fn location_conversion_works() { - let alice_32 = AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }; + let alice_32 = + AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; // the purpose of hardcoded values is to catch an unintended location conversion logic change. @@ -750,21 +748,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal @@ -775,10 +764,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index a7e603a02c..4367c81d75 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -735,10 +735,8 @@ fn change_xcm_bridge_hub_ethereum_base_fee_by_governance_works() { #[test] fn location_conversion_works() { - let alice_32 = AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }; + let alice_32 = + AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; // the purpose of hardcoded values is to catch an unintended location conversion logic change. @@ -774,21 +772,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal @@ -799,10 +788,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 05223ad35a..7fb41affa3 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -411,21 +411,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", }, // DescribeAccountKey20Terminal @@ -436,10 +427,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 18bd832422..291f31af51 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -412,21 +412,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", }, // DescribeAccountKey20Terminal @@ -437,10 +428,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs index 1f3d7d3710..cb8e63dbbb 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs @@ -24,10 +24,7 @@ const ALICE: [u8; 32] = [1u8; 32]; #[test] fn location_conversion_works() { - let alice_32 = AccountId32 { - network: None, - id: AccountId::from(ALICE).into(), - }; + let alice_32 = AccountId32 { network: None, id: AccountId::from(ALICE).into() }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; // the purpose of hardcoded values is to catch an unintended location conversion logic change. @@ -63,21 +60,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal @@ -88,10 +76,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index e03098006b..a0096c97f9 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -116,10 +116,8 @@ fn timeslice_period_is_sane() { #[test] fn location_conversion_works() { - let alice_32 = AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }; + let alice_32 = + AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; // the purpose of hardcoded values is to catch an unintended location conversion logic change. @@ -155,21 +153,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal @@ -180,10 +169,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index bfea18ef9b..e18581ae10 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -116,10 +116,8 @@ fn timeslice_period_is_sane() { #[test] fn location_conversion_works() { - let alice_32 = AccountId32 { - network: None, - id: polkadot_core_primitives::AccountId::from(ALICE).into(), - }; + let alice_32 = + AccountId32 { network: None, id: polkadot_core_primitives::AccountId::from(ALICE).into() }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; // the purpose of hardcoded values is to catch an unintended location conversion logic change. @@ -155,21 +153,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal @@ -180,10 +169,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index a4849a28ed..2ad2d9e2ad 100644 --- a/system-parachains/people/people-kusama/src/tests.rs +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -24,10 +24,7 @@ const ALICE: [u8; 32] = [1u8; 32]; #[test] fn location_conversion_works() { - let alice_32 = AccountId32 { - network: None, - id: AccountId::from(ALICE).into(), - }; + let alice_32 = AccountId32 { network: None, id: AccountId::from(ALICE).into() }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; // the purpose of hardcoded values is to catch an unintended location conversion logic change. @@ -63,21 +60,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal @@ -88,10 +76,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index 547f338ade..e060145dbe 100644 --- a/system-parachains/people/people-polkadot/src/tests.rs +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -24,10 +24,7 @@ const ALICE: [u8; 32] = [1u8; 32]; #[test] fn location_conversion_works() { - let alice_32 = AccountId32 { - network: None, - id: AccountId::from(ALICE).into(), - }; + let alice_32 = AccountId32 { network: None, id: AccountId::from(ALICE).into() }; let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }; // the purpose of hardcoded values is to catch an unintended location conversion logic change. @@ -63,21 +60,12 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new( - 1, - [alice_32.clone()], - ), + location: Location::new(1, [alice_32.clone()]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new( - 1, - [ - Parachain(1111), - alice_32.clone(), - ], - ), + location: Location::new(1, [Parachain(1111), alice_32.clone()]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal @@ -88,10 +76,7 @@ fn location_conversion_works() { }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new( - 1, - [Parachain(1111), bob_20.clone()], - ), + location: Location::new(1, [Parachain(1111), bob_20.clone()]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal From 61c44d62e63c10920b9829d07ea973ccd4494dec Mon Sep 17 00:00:00 2001 From: ndk Date: Wed, 23 Oct 2024 14:53:16 +0300 Subject: [PATCH 11/11] clippy: removed AccountId32 and AccountKey20 cloning since they both implement Copy trait --- .../asset-hubs/asset-hub-kusama/tests/tests.rs | 8 ++++---- .../asset-hubs/asset-hub-polkadot/tests/tests.rs | 8 ++++---- .../bridge-hubs/bridge-hub-kusama/tests/tests.rs | 8 ++++---- .../bridge-hubs/bridge-hub-polkadot/tests/tests.rs | 8 ++++---- .../collectives-polkadot/tests/location_conversion.rs | 8 ++++---- system-parachains/coretime/coretime-kusama/src/tests.rs | 8 ++++---- system-parachains/coretime/coretime-polkadot/src/tests.rs | 8 ++++---- system-parachains/people/people-kusama/src/tests.rs | 8 ++++---- system-parachains/people/people-polkadot/src/tests.rs | 8 ++++---- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 2848a304f9..c4e563f4e7 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -748,23 +748,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs index 4367c81d75..77564f36ac 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/tests/tests.rs @@ -772,23 +772,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 7fb41affa3..e2525e6d87 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -411,23 +411,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 291f31af51..956604c200 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -412,23 +412,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5EueAXd4h8u75nSbFdDJbC29cmi4Uo1YJssqEL9idvindxFL", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5Dmbuiq48fU4iW58FKYqoGbbfxFHjbAeGLMtjFg6NNCw3ssr", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs index cb8e63dbbb..21c3315916 100644 --- a/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs +++ b/system-parachains/collectives/collectives-polkadot/tests/location_conversion.rs @@ -60,23 +60,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index a0096c97f9..0ccccbdac4 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -153,23 +153,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/coretime/coretime-polkadot/src/tests.rs b/system-parachains/coretime/coretime-polkadot/src/tests.rs index e18581ae10..cb5a4217c6 100644 --- a/system-parachains/coretime/coretime-polkadot/src/tests.rs +++ b/system-parachains/coretime/coretime-polkadot/src/tests.rs @@ -153,23 +153,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index 2ad2d9e2ad..7b459977e6 100644 --- a/system-parachains/people/people-kusama/src/tests.rs +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -60,23 +60,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal diff --git a/system-parachains/people/people-polkadot/src/tests.rs b/system-parachains/people/people-polkadot/src/tests.rs index e060145dbe..7e0d7d61a7 100644 --- a/system-parachains/people/people-polkadot/src/tests.rs +++ b/system-parachains/people/people-polkadot/src/tests.rs @@ -60,23 +60,23 @@ fn location_conversion_works() { // DescribeAccountId32Terminal TestCase { description: "DescribeAccountId32Terminal Parent", - location: Location::new(1, [alice_32.clone()]), + location: Location::new(1, [alice_32]), expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4", }, TestCase { description: "DescribeAccountId32Terminal Sibling", - location: Location::new(1, [Parachain(1111), alice_32.clone()]), + location: Location::new(1, [Parachain(1111), alice_32]), expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg", }, // DescribeAccountKey20Terminal TestCase { description: "DescribeAccountKey20Terminal Parent", - location: Location::new(1, [bob_20.clone()]), + location: Location::new(1, [bob_20]), expected_account_id_str: "5CJeW9bdeos6EmaEofTUiNrvyVobMBfWbdQvhTe6UciGjH2n", }, TestCase { description: "DescribeAccountKey20Terminal Sibling", - location: Location::new(1, [Parachain(1111), bob_20.clone()]), + location: Location::new(1, [Parachain(1111), bob_20]), expected_account_id_str: "5CE6V5AKH8H4rg2aq5KMbvaVUDMumHKVPPQEEDMHPy3GmJQp", }, // DescribeTreasuryVoiceTerminal