Skip to content

Commit

Permalink
feat: Add Kusama xcm location converter
Browse files Browse the repository at this point in the history
  • Loading branch information
green-jay committed Jan 14, 2025
1 parent 02adadc commit 0adc925
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/hydradx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-runtime"
version = "280.0.0"
version = "281.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("hydradx"),
impl_name: create_runtime_str!("hydradx"),
authoring_version: 1,
spec_version: 280,
spec_version: 281,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
24 changes: 24 additions & 0 deletions runtime/hydradx/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::*;
use cumulus_primitives_core::{Junction::GlobalConsensus, Location, NetworkId::Kusama};
use primitives::constants::{
currency::{CENTS, DOLLARS, MILLICENTS},
time::{DAYS, HOURS},
Expand All @@ -16,6 +17,9 @@ use polkadot_xcm::opaque::VersionedXcm;
use polkadot_xcm::{VersionedAssets, VersionedLocation};
use sp_runtime::{BuildStorage, FixedU128};
use sp_std::sync::Arc;
use xcm_builder::GlobalConsensusConvertsFor;
use xcm_executor::traits::ConvertLocation;
use sp_core::crypto::Ss58Codec;

#[test]
#[ignore]
Expand Down Expand Up @@ -363,3 +367,23 @@ mod xcm_fee_payment_api_tests {
});
}
}

#[test]
fn assert_kusama_root_account() {
// Initialize the Externalities environment
sp_io::TestExternalities::new_empty().execute_with(|| {
let ksm_root_location = Location::new(2, [GlobalConsensus(Kusama)]);
let ksm_root_account = GlobalConsensusConvertsFor::<UniversalLocation, AccountId>::convert_location(&ksm_root_location)
.expect("Failed to convert location");

// // Example treasury account, replace with the actual expected value
let expected_account = AccountId::from_ss58check("5G4KKqSKDkiMGiPzCQY12dSB15aBikyNQJL9VDmbMH4SxiWD")
.expect("Invalid SS58 address format");
assert_eq!(ksm_root_account, expected_account);

// // Example of a wrong account
let wrong_account = AccountId::from_ss58check("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")
.expect("Invalid SS58 address format");
assert_ne!(ksm_root_account, wrong_account);
});
}
8 changes: 4 additions & 4 deletions runtime/hydradx/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ use polkadot_xcm::v4::{prelude::*, Asset, InteriorLocation, Weight as XcmWeight}
use scale_info::TypeInfo;
use sp_runtime::{traits::MaybeEquivalence, Perbill};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FixedWeightBounds, HashedDescription, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, WithComputedOrigin, WithUniqueTopic,
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FixedWeightBounds, GlobalConsensusConvertsFor, HashedDescription, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, WithComputedOrigin, WithUniqueTopic
};
use xcm_executor::{Config, XcmExecutor};

Expand Down Expand Up @@ -480,6 +477,9 @@ pub type LocationToAccountId = (
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
// Convert ETH to local substrate account
EvmAddressConversion<RelayNetwork>,
// Converts a location which is a top-level relay chain (which provides its own consensus) into a
// 32-byte `AccountId`.
GlobalConsensusConvertsFor<UniversalLocation, AccountId>,
);
use pallet_broadcast::types::ExecutionType;
use xcm_executor::traits::{ConvertLocation, XcmAssetTransfers};
Expand Down

0 comments on commit 0adc925

Please sign in to comment.