Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

315 enable pendulum assets to be transferable via xcm #332

Merged
merged 20 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion runtime/integration-tests/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ macro_rules! build_parachain_with_orml {
.unwrap();

orml_tokens::GenesisConfig::<$runtime> {
balances: vec![(AccountId::from(BOB), CurrencyId::XCM(0), units($orml_balance))],
//Changed this temporarily in order to have PEN into BOB's account
balances: vec![(AccountId::from(BOB), CurrencyId::Native, units($orml_balance))],
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
14 changes: 14 additions & 0 deletions runtime/integration-tests/src/pendulum_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
parachain1_transfer_incorrect_asset_to_parachain2_should_fail,
transfer_10_relay_token_from_parachain_to_relay_chain,
transfer_20_relay_token_from_relay_chain_to_parachain,
transfer_native_token_from_pendulum_to_assethub,
},
PENDULUM_ID, POLKADOT_ASSETHUB_ID,
};
Expand Down Expand Up @@ -116,3 +117,16 @@ fn assethub_transfer_asset_to_pendulum_and_back() {
network_id
);
}

#[test]
fn transfer_native_token_to_assethub() {
transfer_native_token_from_pendulum_to_assethub!(
PolkadotMockNet,
pendulum_runtime,
PendulumParachain,
polkadot_asset_hub_runtime,
AssetHubParachain,
PENDULUM_ID,
POLKADOT_ASSETHUB_ID
);
}
88 changes: 88 additions & 0 deletions runtime/integration-tests/src/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,97 @@ macro_rules! parachain1_transfer_asset_to_parachain2_and_back {
}};
}

macro_rules! transfer_native_token_from_pendulum_to_assethub {
(
$mocknet:ident,
$pendulum_runtime:ident,
$pendulum_chain:ident,
$assethub_runtime:ident,
$assethub_chain:ident,
$pendulum_id:ident,
$assethub_id:ident
) => {{
use crate::mock::{units, BOB};
use frame_support::traits::fungibles::Inspect;
use polkadot_core_primitives::Balance;
use xcm::latest::{
Junction,
Junction::AccountId32,
Junctions::{X1, X2},
MultiLocation, WeightLimit,
};
use $pendulum_runtime::CurrencyId;

$mocknet::reset();

let transfer_amount: Balance = units(10);
let asset_location = MultiLocation::new(
1,
X2(Junction::Parachain($pendulum_id), Junction::PalletInstance(10)),
);

// Get BOB's balance before the transfer on Pendulum chain
let mut pendulum_tokens_before: Balance = units(100);
$pendulum_chain::execute_with(|| {
assert_eq!(
$pendulum_runtime::Tokens::balance(CurrencyId::Native, &BOB.into()),
pendulum_tokens_before
);
});

// Execute the transfer from Pendulum chain to AssetHub
$pendulum_chain::execute_with(|| {
use $pendulum_runtime::XTokens;

assert_ok!(XTokens::transfer_multiasset(
$pendulum_runtime::RuntimeOrigin::signed(BOB.into()),
Box::new((asset_location.clone(), transfer_amount).into()),
Box::new(
MultiLocation {
parents: 1,
interior: X1(AccountId32 { network: None, id: BOB })
}
.into()
),
WeightLimit::Unlimited
));
});

$pendulum_chain::execute_with(|| {
use $pendulum_runtime::{RuntimeEvent, System};

assert!(System::events().iter().any(|r| matches!(
r.event,
RuntimeEvent::XTokens(orml_xtokens::Event::TransferredMultiAssets { .. })
)));
});

// Can't get this to work though
// Verify the balance on the AssetHub chain after transfer
// $assethub_chain::execute_with(|| {
// // I need ForeignAssets here instead of Assets
// use $assethub_runtime::Assets;

// assert_eq!(
// Assets::balance(asset_location, &BOB.into()),
// transfer_amount
// );
// });
bogdanS98 marked this conversation as resolved.
Show resolved Hide resolved

// Verify the balance on the Pendulum chain after transfer
$pendulum_chain::execute_with(|| {
assert_eq!(
$pendulum_runtime::Tokens::balance(CurrencyId::Native, &BOB.into()),
pendulum_tokens_before - transfer_amount
);
});
}};
}

// macros defined at the bottom of this file to prevent unresolved imports
pub(super) use parachain1_transfer_asset_to_parachain2;
pub(super) use parachain1_transfer_asset_to_parachain2_and_back;
pub(super) use parachain1_transfer_incorrect_asset_to_parachain2_should_fail;
pub(super) use transfer_10_relay_token_from_parachain_to_relay_chain;
pub(super) use transfer_20_relay_token_from_relay_chain_to_parachain;
pub(super) use transfer_native_token_from_pendulum_to_assethub;
7 changes: 7 additions & 0 deletions runtime/pendulum/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl Convert<CurrencyId, Option<MultiLocation>> for CurrencyIdConvert {
)),
_ => None,
},
CurrencyId::Native => Some(MultiLocation::new(
1,
X2(Parachain(ParachainInfo::parachain_id().into()), PalletInstance(10)),
)),
_ => None,
}
}
Expand All @@ -95,6 +99,9 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
GeneralIndex(asset_hub::USDT_ASSET_ID),
),
} => Some(CurrencyId::XCM(XCM_ASSET_ASSETHUB_USDT)),
MultiLocation { parents: 1, interior: X2(Parachain(id), PalletInstance(10)) }
bogdanS98 marked this conversation as resolved.
Show resolved Hide resolved
if id == u32::from(ParachainInfo::parachain_id()) =>
Some(CurrencyId::Native),
_ => None,
}
}
Expand Down
Loading