Skip to content

Commit

Permalink
Use FromNetwork and remove EthereumLocation (#1075)
Browse files Browse the repository at this point in the history
* wip

* use from network

* update polkadot-sdk
  • Loading branch information
alistair-singh authored Dec 20, 2023
1 parent a13e2a1 commit 3772fb0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 49 deletions.
17 changes: 1 addition & 16 deletions parachain/primitives/router/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ mod tests;

use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::{
traits::{tokens::Balance as BalanceT, ContainsPair},
weights::Weight,
PalletError,
};
use frame_support::{traits::tokens::Balance as BalanceT, weights::Weight, PalletError};
use scale_info::TypeInfo;
use sp_core::{Get, RuntimeDebug, H160};
use sp_io::hashing::blake2_256;
Expand Down Expand Up @@ -302,17 +298,6 @@ where
}
}

pub struct FromEthereumGlobalConsensus<EthereumBridgeLocation>(PhantomData<EthereumBridgeLocation>);
impl<EthereumBridgeLocation> ContainsPair<MultiLocation, MultiLocation>
for FromEthereumGlobalConsensus<EthereumBridgeLocation>
where
EthereumBridgeLocation: Get<MultiLocation>,
{
fn contains(asset: &MultiLocation, origin: &MultiLocation) -> bool {
origin == &EthereumBridgeLocation::get() && asset.starts_with(origin)
}
}

pub struct GlobalConsensusEthereumConvertsFor<AccountId>(PhantomData<AccountId>);
impl<AccountId> ConvertLocation<AccountId> for GlobalConsensusEthereumConvertsFor<AccountId>
where
Expand Down
34 changes: 2 additions & 32 deletions parachain/primitives/router/src/inbound/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{FromEthereumGlobalConsensus, GlobalConsensusEthereumConvertsFor};
use super::GlobalConsensusEthereumConvertsFor;
use crate::inbound::CallIndex;
use frame_support::{parameter_types, traits::ContainsPair};
use frame_support::parameter_types;
use hex_literal::hex;
use sp_core::crypto::Ss58Codec;
use xcm::v3::prelude::*;
Expand All @@ -14,7 +14,6 @@ const EXPECTED_SOVEREIGN_ADDRESS: &str = "HF3T62xRQvoCCowYamEQweEyWbD5yt4mkET8Uk

parameter_types! {
pub EthereumNetwork: NetworkId = NETWORK;
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

pub const CreateAssetCall: CallIndex = [1, 1];
pub const CreateAssetExecutionFee: u128 = 123;
Expand Down Expand Up @@ -63,32 +62,3 @@ fn test_contract_location_with_incorrect_location_fails_convert() {
None,
);
}

#[test]
fn test_from_ethereum_global_consensus_with_containing_asset_yields_true() {
let origin = MultiLocation { parents: 2, interior: X1(GlobalConsensus(NETWORK)) };
let asset = MultiLocation {
parents: 2,
interior: X2(GlobalConsensus(NETWORK), AccountKey20 { network: None, key: [0; 20] }),
};
assert!(FromEthereumGlobalConsensus::<EthereumLocation>::contains(&asset, &origin));
}

#[test]
fn test_from_ethereum_global_consensus_without_containing_asset_yields_false() {
let origin = MultiLocation { parents: 2, interior: X1(GlobalConsensus(NETWORK)) };
let asset =
MultiLocation { parents: 2, interior: X2(GlobalConsensus(Polkadot), Parachain(1000)) };
assert!(!FromEthereumGlobalConsensus::<EthereumLocation>::contains(&asset, &origin));
}

#[test]
fn test_from_ethereum_global_consensus_without_bridge_origin_yields_false() {
let origin =
MultiLocation { parents: 2, interior: X2(GlobalConsensus(Polkadot), Parachain(1000)) };
let asset = MultiLocation {
parents: 2,
interior: X2(GlobalConsensus(NETWORK), AccountKey20 { network: None, key: [0; 20] }),
};
assert!(!FromEthereumGlobalConsensus::<EthereumLocation>::contains(&asset, &origin));
}

0 comments on commit 3772fb0

Please sign in to comment.