Skip to content

Commit

Permalink
https://github.com/pendulum-chain/pendulum/pull/290#discussion_r12844…
Browse files Browse the repository at this point in the history
…75713,

#290 (comment)
  • Loading branch information
b-yap committed Aug 7, 2023
1 parent bd3bb4a commit d03e061
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 75 deletions.
20 changes: 10 additions & 10 deletions runtime/amplitude/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use xcm_executor::{
traits::{JustTry, ShouldExecute},
XcmExecutor,
};
use runtime_common::parachains::kusama::statemine;
use runtime_common::parachains::kusama::asset_hub;

const XCM_ASSET_RELAY_KSM: u8 = 0;
const XCM_ASSET_STATEMINE_USDT: u8 = 1;
const XCM_ASSET_ASSETHUB_USDT: u8 = 1;

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Expand Down Expand Up @@ -65,12 +65,12 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
match id {
CurrencyId::XCM(index) => match index {
XCM_ASSET_RELAY_KSM => Some(MultiLocation::parent()),
XCM_ASSET_STATEMINE_USDT => Some(MultiLocation::new(
XCM_ASSET_ASSETHUB_USDT => Some(MultiLocation::new(
1,
X3(
Parachain(statemine::PARA_ID),
PalletInstance(statemine::ASSET_PALLET_ID),
GeneralIndex(statemine::USDT_ASSET_ID),
Parachain(asset_hub::PARA_ID),
PalletInstance(asset_hub::ASSET_PALLET_ID),
GeneralIndex(asset_hub::USDT_ASSET_ID),
),
)),
_ => None,
Expand All @@ -88,11 +88,11 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
parents: 1,
interior:
X3(
Parachain(statemine::PARA_ID),
PalletInstance(statemine::ASSET_PALLET_ID),
GeneralIndex(statemine::USDT_ASSET_ID)
Parachain(asset_hub::PARA_ID),
PalletInstance(asset_hub::ASSET_PALLET_ID),
GeneralIndex(asset_hub::USDT_ASSET_ID)
)
} => Some(CurrencyId::XCM(XCM_ASSET_STATEMINE_USDT)),
} => Some(CurrencyId::XCM(XCM_ASSET_ASSETHUB_USDT)),
_ => None,
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub mod opaque {

pub mod parachains {
pub mod polkadot {
pub mod statemint {
pub mod asset_hub {
pub const PARA_ID: u32 = 1000;
pub const ASSET_PALLET_ID: u8 = 50;

Expand All @@ -78,7 +78,7 @@ pub mod parachains {
}

pub mod kusama {
pub mod statemine {
pub mod asset_hub {
pub const PARA_ID: u32 = 1000;
pub const ASSET_PALLET_ID: u8 = 50;

Expand Down
37 changes: 19 additions & 18 deletions runtime/integration-tests/src/amplitude_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use crate::{
transfer_10_relay_token_from_parachain_to_relay_chain,
transfer_20_relay_token_from_relay_chain_to_parachain,
},
AMPLITUDE_ID, STATEMINE_ID,
AMPLITUDE_ID, KUSAMA_ASSETHUB_ID,
};

use frame_support::assert_ok;
use statemine_runtime as kusama_asset_hub_runtime;
use xcm::latest::NetworkId;
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt};

Expand All @@ -34,20 +35,20 @@ decl_test_parachain! {
}

decl_test_parachain! {
pub struct StatemineParachain {
Runtime = statemine_runtime::Runtime,
RuntimeOrigin = statemine_runtime::RuntimeOrigin,
XcmpMessageHandler = statemine_runtime::XcmpQueue,
DmpMessageHandler = statemine_runtime::DmpQueue,
new_ext = para_ext(ParachainType::Statemine),
pub struct AssetHubParachain {
Runtime = kusama_asset_hub_runtime::Runtime,
RuntimeOrigin = kusama_asset_hub_runtime::RuntimeOrigin,
XcmpMessageHandler = kusama_asset_hub_runtime::XcmpQueue,
DmpMessageHandler = kusama_asset_hub_runtime::DmpQueue,
new_ext = para_ext(ParachainType::KusamaAssetHub),
}
}

decl_test_network! {
pub struct KusamaMockNet {
relay_chain = KusamaRelay,
parachains = vec![
(1000, StatemineParachain),
(1000, AssetHubParachain),
(2124, AmplitudeParachain),
],
}
Expand Down Expand Up @@ -78,21 +79,21 @@ fn transfer_ksm_from_amplitude_to_kusama() {
}

#[test]
fn statemine_transfer_incorrect_asset_to_amplitude_should_fail() {
fn assethub_transfer_incorrect_asset_to_amplitude_should_fail() {
parachain1_transfer_incorrect_asset_to_parachain2_should_fail!(
statemine_runtime,
StatemineParachain,
kusama_asset_hub_runtime,
AssetHubParachain,
amplitude_runtime,
AmplitudeParachain,
AMPLITUDE_ID
);
}

#[test]
fn statemine_transfer_asset_to_amplitude() {
fn assethub_transfer_asset_to_amplitude() {
parachain1_transfer_asset_to_parachain2!(
statemine_runtime,
StatemineParachain,
kusama_asset_hub_runtime,
AssetHubParachain,
USDT_ASSET_ID,
amplitude_runtime,
AmplitudeParachain,
Expand All @@ -101,13 +102,13 @@ fn statemine_transfer_asset_to_amplitude() {
}

#[test]
fn statemine_transfer_asset_to_amplitude_and_back() {
fn assethub_transfer_asset_to_amplitude_and_back() {
let network_id = NetworkId::Kusama;

parachain1_transfer_asset_to_parachain2_and_back!(
statemine_runtime,
StatemineParachain,
STATEMINE_ID,
kusama_asset_hub_runtime,
AssetHubParachain,
KUSAMA_ASSETHUB_ID,
USDT_ASSET_ID,
amplitude_runtime,
AmplitudeParachain,
Expand Down
4 changes: 2 additions & 2 deletions runtime/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod amplitude_tests;
mod test_macros;

pub const PENDULUM_ID: u32 = 2094;
pub const STATEMINT_ID: u32 = 1000;
pub const POLKADOT_ASSETHUB_ID: u32 = 1000;

pub const AMPLITUDE_ID: u32 = 2124;
pub const STATEMINE_ID: u32 = 1000;
pub const KUSAMA_ASSETHUB_ID: u32 = 1000;
39 changes: 21 additions & 18 deletions runtime/integration-tests/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AMPLITUDE_ID, PENDULUM_ID, STATEMINE_ID, STATEMINT_ID};
use crate::{AMPLITUDE_ID, PENDULUM_ID, KUSAMA_ASSETHUB_ID, POLKADOT_ASSETHUB_ID};
use frame_support::traits::GenesisBuild;
use pendulum_runtime::CurrencyId;
use polkadot_core_primitives::{AccountId, Balance, BlockNumber};
Expand All @@ -9,13 +9,16 @@ use sp_io::TestExternalities;
use sp_runtime::traits::AccountIdConversion;
use xcm_emulator::Weight;

use statemint_runtime as polkadot_asset_hub_runtime;
use statemine_runtime as kusama_asset_hub_runtime;

pub const ALICE: [u8; 32] = [4u8; 32];
pub const BOB: [u8; 32] = [5u8; 32];

pub const UNIT: Balance = 1_000_000_000_000;
pub const TEN_UNITS: Balance = 10_000_000_000_000;

pub const USDT_ASSET_ID: u32 = 1984; //Real USDT Asset ID both from Statemint and Statemine
pub const USDT_ASSET_ID: u32 = 1984; //Real USDT Asset ID of both Polkadot's and Kusama's Asset Hub
pub const INCORRECT_ASSET_ID: u32 = 0; //asset id that pendulum/amplitude does NOT SUPPORT

pub const INITIAL_BALANCE: Balance = 1_000_000_000;
Expand Down Expand Up @@ -103,8 +106,8 @@ pub trait Builder<Currency> {
}

pub enum ParachainType {
Statemint,
Statemine,
PolkadotAssetHub,
KusamaAssetHub,
Pendulum,
Amplitude,
}
Expand Down Expand Up @@ -172,10 +175,10 @@ fn default_parachains_host_configuration() -> HostConfiguration<BlockNumber> {

pub fn para_ext(chain: ParachainType) -> sp_io::TestExternalities {
match chain {
ParachainType::Statemint =>
ExtBuilderParachain::statemint_default().balances(vec![]).build(),
ParachainType::Statemine =>
ExtBuilderParachain::statemine_default().balances(vec![]).build(),
ParachainType::PolkadotAssetHub =>
ExtBuilderParachain::polkadot_asset_hub_default().balances(vec![]).build(),
ParachainType::KusamaAssetHub =>
ExtBuilderParachain::kusama_asset_hub_default().balances(vec![]).build(),
ParachainType::Pendulum => ExtBuilderParachain::pendulum_default().balances(vec![]).build(),
ParachainType::Amplitude =>
ExtBuilderParachain::amplitude_default().balances(vec![]).build(),
Expand All @@ -185,8 +188,8 @@ pub fn para_ext(chain: ParachainType) -> sp_io::TestExternalities {
impl<Currency> ExtBuilderParachain<Currency> {
fn get_parachain_id(&self) -> u32 {
match self.chain {
ParachainType::Statemint => STATEMINT_ID,
ParachainType::Statemine => STATEMINE_ID,
ParachainType::PolkadotAssetHub => POLKADOT_ASSETHUB_ID,
ParachainType::KusamaAssetHub => KUSAMA_ASSETHUB_ID,
ParachainType::Pendulum => PENDULUM_ID,
ParachainType::Amplitude => AMPLITUDE_ID,
}
Expand Down Expand Up @@ -239,12 +242,12 @@ impl Builder<CurrencyId> for ExtBuilderParachain<CurrencyId> {

// ------------------- for Statemint and Statemine -------------------
impl ExtBuilderParachain<u128> {
pub fn statemint_default() -> Self {
Self { balances: vec![], chain: ParachainType::Statemint }
pub fn polkadot_asset_hub_default() -> Self {
Self { balances: vec![], chain: ParachainType::PolkadotAssetHub }
}

pub fn statemine_default() -> Self {
Self { balances: vec![], chain: ParachainType::Statemine }
pub fn kusama_asset_hub_default() -> Self {
Self { balances: vec![], chain: ParachainType::KusamaAssetHub }
}
}

Expand All @@ -256,12 +259,12 @@ impl Builder<u128> for ExtBuilderParachain<u128> {

fn build(self) -> TestExternalities {
match self.chain {
ParachainType::Statemint => {
use statemint_runtime::{Runtime, System};
ParachainType::PolkadotAssetHub => {
use polkadot_asset_hub_runtime::{Runtime, System};
build_parachain!(self, Runtime, System)
},
ParachainType::Statemine => {
use statemine_runtime::{Runtime, System};
ParachainType::KusamaAssetHub => {
use kusama_asset_hub_runtime::{Runtime, System};
build_parachain!(self, Runtime, System)
},
_ => panic!("cannot use this chain to build"),
Expand Down
31 changes: 16 additions & 15 deletions runtime/integration-tests/src/pendulum_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use crate::{
transfer_10_relay_token_from_parachain_to_relay_chain,
transfer_20_relay_token_from_relay_chain_to_parachain,
},
PENDULUM_ID, STATEMINT_ID,
PENDULUM_ID, POLKADOT_ASSETHUB_ID,
};

use frame_support::assert_ok;
use statemint_runtime as polkadot_asset_hub_runtime;
use xcm::latest::NetworkId;
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt};

Expand All @@ -34,20 +35,20 @@ decl_test_parachain! {
}

decl_test_parachain! {
pub struct StatemintParachain {
Runtime = statemint_runtime::Runtime,
RuntimeOrigin = statemint_runtime::RuntimeOrigin,
XcmpMessageHandler = statemint_runtime::XcmpQueue,
DmpMessageHandler = statemint_runtime::DmpQueue,
new_ext = para_ext(ParachainType::Statemint),
pub struct AssetHubParachain {
Runtime = polkadot_asset_hub_runtime::Runtime,
RuntimeOrigin = polkadot_asset_hub_runtime::RuntimeOrigin,
XcmpMessageHandler = polkadot_asset_hub_runtime::XcmpQueue,
DmpMessageHandler = polkadot_asset_hub_runtime::DmpQueue,
new_ext = para_ext(ParachainType::PolkadotAssetHub),
}
}

decl_test_network! {
pub struct PolkadotMockNet {
relay_chain = PolkadotRelay,
parachains = vec![
(1000, StatemintParachain),
(1000, AssetHubParachain),
(2094, PendulumParachain),
],
}
Expand Down Expand Up @@ -78,21 +79,21 @@ fn transfer_dot_from_pendulum_to_polkadot() {
}

#[test]
fn statemint_transfer_incorrect_asset_to_pendulum_should_fail() {
fn assethub_transfer_incorrect_asset_to_pendulum_should_fail() {
parachain1_transfer_incorrect_asset_to_parachain2_should_fail!(
statemine_runtime,
StatemintParachain,
AssetHubParachain,
pendulum_runtime,
PendulumParachain,
PENDULUM_ID
);
}

#[test]
fn statemint_transfer_asset_to_pendulum() {
fn assethub_transfer_asset_to_pendulum() {
parachain1_transfer_asset_to_parachain2!(
statemine_runtime,
StatemintParachain,
AssetHubParachain,
USDT_ASSET_ID,
pendulum_runtime,
PendulumParachain,
Expand All @@ -101,13 +102,13 @@ fn statemint_transfer_asset_to_pendulum() {
}

#[test]
fn statemint_transfer_asset_to_pendulum_and_back() {
fn assethub_transfer_asset_to_pendulum_and_back() {
let network_id = NetworkId::Polkadot;

parachain1_transfer_asset_to_parachain2_and_back!(
statemine_runtime,
StatemintParachain,
STATEMINT_ID,
AssetHubParachain,
POLKADOT_ASSETHUB_ID,
USDT_ASSET_ID,
pendulum_runtime,
PendulumParachain,
Expand Down
20 changes: 10 additions & 10 deletions runtime/pendulum/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use orml_traits::{
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use runtime_common::parachains::polkadot::statemint;
use runtime_common::parachains::polkadot::asset_hub;
use sp_runtime::traits::Convert;
use xcm::latest::{prelude::*, Weight as XCMWeight};
use xcm_builder::{
Expand All @@ -30,7 +30,7 @@ use xcm_executor::{
};

const XCM_ASSET_RELAY_DOT: u8 = 0;
const XCM_ASSET_STATEMINT_USDT: u8 = 1;
const XCM_ASSET_ASSETHUB_USDT: u8 = 1;

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Expand Down Expand Up @@ -66,12 +66,12 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
// CurrencyId::KSM => Some(MultiLocation::parent()),
CurrencyId::XCM(f) => match f {
XCM_ASSET_RELAY_DOT => Some(MultiLocation::parent()),
XCM_ASSET_STATEMINT_USDT => Some(MultiLocation::new(
XCM_ASSET_ASSETHUB_USDT => Some(MultiLocation::new(
1,
X3(
Parachain(statemint::PARA_ID),
PalletInstance(statemint::ASSET_PALLET_ID),
GeneralIndex(statemint::USDT_ASSET_ID),
Parachain(asset_hub::PARA_ID),
PalletInstance(asset_hub::ASSET_PALLET_ID),
GeneralIndex(asset_hub::USDT_ASSET_ID),
),
)),
_ => None,
Expand All @@ -90,11 +90,11 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
parents: 1,
interior:
X3(
Parachain(statemint::PARA_ID),
PalletInstance(statemint::ASSET_PALLET_ID),
GeneralIndex(statemint::USDT_ASSET_ID),
Parachain(asset_hub::PARA_ID),
PalletInstance(asset_hub::ASSET_PALLET_ID),
GeneralIndex(asset_hub::USDT_ASSET_ID),
),
} => Some(CurrencyId::XCM(XCM_ASSET_STATEMINT_USDT)),
} => Some(CurrencyId::XCM(XCM_ASSET_ASSETHUB_USDT)),
_ => None,
}
}
Expand Down

0 comments on commit d03e061

Please sign in to comment.