Skip to content

Commit

Permalink
Add test for transferring PEN to AssetHub through XCM
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanS98 committed Oct 27, 2023
1 parent 9d646f6 commit 11b1ab4
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
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
);
}
82 changes: 82 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,91 @@ 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::{BOB, units};
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::{System, RuntimeEvent};

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
// );
// });

// 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;

0 comments on commit 11b1ab4

Please sign in to comment.