Skip to content

Commit

Permalink
Update integration tests [breaking]
Browse files Browse the repository at this point in the history
  • Loading branch information
raynaudoe committed Nov 14, 2024
1 parent 2d81889 commit bc3a257
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ pub fn genesis() -> Storage {
assets: vec![
// Penpal's teleportable asset representation
(
PenpalATeleportableAssetLocation::get().try_into().unwrap(),
PenpalATeleportableAssetLocation::get(),
PenpalASiblingSovereignAccount::get(),
false,
ED,
),
(
PenpalBTeleportableAssetLocation::get().try_into().unwrap(),
PenpalBTeleportableAssetLocation::get(),
PenpalBSiblingSovereignAccount::get(),
false,
ED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubPaseo);
impl_assert_events_helpers_for_parachain!(AssetHubPaseo);
impl_assets_helpers_for_system_parachain!(AssetHubPaseo, Paseo);
impl_assets_helpers_for_parachain!(AssetHubPaseo);
impl_foreign_assets_helpers_for_parachain!(AssetHubPaseo, xcm::v3::Location);
impl_foreign_assets_helpers_for_parachain!(AssetHubPaseo, xcm::v4::Location);
impl_xcm_helpers_for_parachain!(AssetHubPaseo);
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use emulated_integration_tests_common::{
impls::Parachain, xcm_emulator::decl_test_parachains,
};

// CoretimePolkadot Parachain declaration
// CoretimePaseo Parachain declaration
decl_test_parachains! {
pub struct CoretimePaseo {
genesis = genesis::genesis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION,
};
use parachains_common::{AccountId, Balance};
use penpal_runtime::xcm_config::{LocalReservableFromAssetHub, RelayLocation};

// Penpal
pub const PARA_ID_A: u32 = 2000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@

mod genesis;
pub use genesis::{genesis, PenpalAssetOwner, ED, PARA_ID_A, PARA_ID_B};
pub use penpal_runtime::xcm_config::{
CustomizableAssetFromSystemAssetHub, LocalReservableFromAssetHub, LocalTeleportableToAssetHub,
XcmConfig, ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, TELEPORTABLE_ASSET_ID,
pub use penpal_runtime::{
self,
xcm_config::{
CustomizableAssetFromSystemAssetHub, LocalReservableFromAssetHub,
LocalTeleportableToAssetHub, RelayNetworkId as PenpalRelayNetworkId, XcmConfig,
ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, TELEPORTABLE_ASSET_ID,
},
};

// Substrate
use frame_support::traits::OnInitialize;
use sp_core::Encode;

// Cumulus
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impls::Parachain,
impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain,
impl_xcm_helpers_for_parachain,
impls::{NetworkId, Parachain},
xcm_emulator::decl_test_parachains,
};

Expand All @@ -36,6 +43,10 @@ decl_test_parachains! {
genesis = genesis(PARA_ID_A),
on_init = {
penpal_runtime::AuraExt::on_initialize(1);
frame_support::assert_ok!(penpal_runtime::System::set_storage(
penpal_runtime::RuntimeOrigin::root(),
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::Kusama.encode())],
));
},
runtime = penpal_runtime,
core = {
Expand All @@ -55,6 +66,10 @@ decl_test_parachains! {
genesis = genesis(PARA_ID_B),
on_init = {
penpal_runtime::AuraExt::on_initialize(1);
frame_support::assert_ok!(penpal_runtime::System::set_storage(
penpal_runtime::RuntimeOrigin::root(),
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::Polkadot.encode())],
));
},
runtime = penpal_runtime,
core = {
Expand All @@ -75,9 +90,11 @@ decl_test_parachains! {
// Penpal implementation
impl_accounts_helpers_for_parachain!(PenpalA);
impl_accounts_helpers_for_parachain!(PenpalB);
impl_assert_events_helpers_for_parachain!(PenpalA);
impl_assert_events_helpers_for_parachain!(PenpalB);
impl_assets_helpers_for_parachain!(PenpalA);
impl_assets_helpers_for_parachain!(PenpalB);
impl_foreign_assets_helpers_for_parachain!(PenpalA, xcm::latest::Location);
impl_foreign_assets_helpers_for_parachain!(PenpalB, xcm::latest::Location);
impl_assert_events_helpers_for_parachain!(PenpalA);
impl_assert_events_helpers_for_parachain!(PenpalB);
impl_xcm_helpers_for_parachain!(PenpalA);
impl_xcm_helpers_for_parachain!(PenpalB);
1 change: 0 additions & 1 deletion integration-tests/emulated/helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub use xcm_emulator::Chain;

/// TODO: when bumping to polkadot-sdk v1.8.0,
/// remove this crate altogether and get the macros from `emulated-integration-tests-common`.
/// remove this crate altogether and get the macros from `emulated-integration-tests-common`.
/// TODO: backport this macros to paseo-sdk
#[macro_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ pub use sp_runtime::DispatchError;
pub use xcm::{
latest::ParentThen,
prelude::{AccountId32 as AccountId32Junction, *},
v3::{
v4::{
self, Error,
NetworkId::{Kusama as KusamaId, Polkadot as PaseoId},
},
};
pub use xcm_executor::traits::TransferType;

// Bridges
pub use bp_messages::LaneId;
Expand All @@ -40,7 +41,7 @@ pub use emulated_integration_tests_common::{
RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
},
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
ASSETS_PALLET_ID, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V4,
};
pub use paseo_system_emulated_network::{
asset_hub_paseo_emulated_chain::{
Expand All @@ -67,7 +68,6 @@ pub use paseo_system_emulated_network::{

pub const ASSET_ID: u32 = 1;
pub const ASSET_MIN_BALANCE: u128 = 1000;
pub const ASSETS_PALLET_ID: u8 = 50;

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use crate::*;
use bridge_hub_paseo_runtime::ExistentialDeposit;
use integration_tests_helpers::test_chain_can_claim_assets;
use xcm_executor::traits::DropAssets;
use xcm::v3::NetworkId::Polkadot as PaseoId;


#[test]
fn assets_can_be_claimed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

use crate::*;


mod asset_transfers;
mod claim_assets;
mod register_bridged_assets;
mod send_xcm;
mod snowbridge;
mod teleport;
mod claim_assets;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::tests::{
snowbridge::{CHAIN_ID, WETH},
*,
};

const XCM_FEE: u128 = 40_000_000_000;

/// Tests the registering of a Polkadot Asset as a bridged asset on Kusama Asset Hub.
#[test]
fn register_polkadot_asset_on_kah_from_pah() {
// Polkadot Asset Hub asset when bridged to Kusama Asset Hub.
let bridged_asset_at_kah = v4::Location::new(
2,
[
v4::Junction::GlobalConsensus(v4::NetworkId::Polkadot),
v4::Junction::Parachain(AssetHubPolkadot::para_id().into()),
v4::Junction::PalletInstance(ASSETS_PALLET_ID),
v4::Junction::GeneralIndex(ASSET_ID.into()),
],
);
// Register above asset on Kusama AH from Polkadot AH.
register_asset_on_kah_from_pah(bridged_asset_at_kah);
}

/// Tests the registering of an Ethereum Asset as a bridged asset on Kusama Asset Hub.
#[test]
fn register_ethereum_asset_on_kah_from_pah() {
// Ethereum asset when bridged to Kusama Asset Hub.
let bridged_asset_at_kah = v4::Location::new(
2,
[
v4::Junction::GlobalConsensus(v4::NetworkId::Ethereum { chain_id: CHAIN_ID }),
v4::Junction::AccountKey20 { network: None, key: WETH },
],
);
// Register above asset on Kusama AH from Polkadot AH.
register_asset_on_kah_from_pah(bridged_asset_at_kah);
}

fn register_asset_on_kah_from_pah(bridged_asset_at_kah: v4::Location) {
let sa_of_pah_on_kah = AssetHubKusama::sovereign_account_of_parachain_on_other_global_consensus(
Polkadot,
AssetHubPolkadot::para_id(),
);

// Encoded `create_asset` call to be executed in Kusama Asset Hub ForeignAssets pallet.
let call = AssetHubKusama::create_foreign_asset_call(
bridged_asset_at_kah.clone(),
ASSET_MIN_BALANCE,
sa_of_pah_on_kah.clone(),
);

let origin_kind = OriginKind::Xcm;
let fee_amount = XCM_FEE;
let fees = (Parent, fee_amount).into();

let xcm = xcm_transact_paid_execution(call, origin_kind, fees, sa_of_pah_on_kah.clone());

// SA-of-PAH-on-KAH needs to have balance to pay for fees and asset creation deposit
AssetHubKusama::fund_accounts(vec![(
sa_of_pah_on_kah.clone(),
ASSET_HUB_KUSAMA_ED * 10000000000,
)]);

let destination = asset_hub_kusama_location();

// fund the PAH's SA on PBH for paying bridge transport fees
BridgeHubPolkadot::fund_para_sovereign(AssetHubPolkadot::para_id(), 10_000_000_000_000u128);

// set XCM versions
AssetHubPolkadot::force_xcm_version(destination.clone(), XCM_VERSION);
BridgeHubPolkadot::force_xcm_version(bridge_hub_kusama_location(), XCM_VERSION);

let root_origin = <AssetHubPolkadot as Chain>::RuntimeOrigin::root();
AssetHubPolkadot::execute_with(|| {
assert_ok!(<AssetHubPolkadot as AssetHubPolkadotPallet>::PolkadotXcm::send(
root_origin,
bx!(destination.into()),
bx!(xcm),
));

AssetHubPolkadot::assert_xcm_pallet_sent();
});

assert_bridge_hub_polkadot_message_accepted(true);
assert_bridge_hub_kusama_message_received();
AssetHubKusama::execute_with(|| {
type RuntimeEvent = <AssetHubKusama as Chain>::RuntimeEvent;
AssetHubKusama::assert_xcmp_queue_success(None);
assert_expected_events!(
AssetHubKusama,
vec![
// Burned the fee
RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount }) => {
who: *who == sa_of_pah_on_kah.clone(),
amount: *amount == fee_amount,
},
// Foreign Asset created
RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { asset_id, creator, owner }) => {
asset_id: *asset_id == bridged_asset_at_kah,
creator: *creator == sa_of_pah_on_kah.clone(),
owner: *owner == sa_of_pah_on_kah,
},
// Unspent fee minted to origin
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => {
who: *who == sa_of_pah_on_kah.clone(),
},
]
);
type ForeignAssets = <AssetHubKusama as AssetHubKusamaPallet>::ForeignAssets;
assert!(ForeignAssets::asset_exists(bridged_asset_at_kah));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use bridge_hub_paseo_runtime::bridge_to_kusama_config::BridgeHubPolkadot;
use crate::tests::*;

/*
#[test]
fn send_xcm_from_polkadot_relay_to_kusama_asset_hub_should_fail_on_not_applicable() {
// Init tests variables
Expand All @@ -29,7 +30,7 @@ fn send_xcm_from_polkadot_relay_to_kusama_asset_hub_should_fail_on_not_applicabl
let xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: KusamaId.into(),
network: KusamaId,
destination: [Parachain(AssetHubKusama::para_id().into())].into(),
xcm: remote_xcm,
},
Expand Down Expand Up @@ -135,3 +136,4 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
);
});
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn send_token_from_ethereum_to_penpal() {
let weth_asset_location: Location =
(Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into();
// Converts the Weth asset location into an asset ID
let weth_asset_id: v3::Location = weth_asset_location.clone().try_into().unwrap();
let weth_asset_id = weth_asset_location.clone();

// Fund ethereum sovereign on AssetHub
AssetHubPaseo::fund_accounts(vec![(ethereum_sovereign_account(), INITIAL_FUND)]);
Expand Down Expand Up @@ -312,7 +312,7 @@ fn send_token_from_ethereum_to_penpal() {
AssetHubPaseo::execute_with(|| {
assert_ok!(<AssetHubPaseo as AssetHubPaseoPallet>::ForeignAssets::force_create(
<AssetHubPaseo as Chain>::RuntimeOrigin::root(),
weth_asset_id,
weth_asset_id.clone(),
asset_hub_sovereign.clone().into(),
true,
1000,
Expand Down Expand Up @@ -733,7 +733,7 @@ fn asset_hub_foreign_assets_pallet_is_configured_correctly_in_bridge_hub() {
<AssetHubPaseo as Chain>::Runtime,
pallet_assets::Instance2,
>::create {
id: v3::Location::default(),
id: v4::Location::default(),
min_balance: ASSET_MIN_BALANCE,
admin: assethub_sovereign.into(),
})
Expand Down Expand Up @@ -852,14 +852,14 @@ fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], fee: u12

assert_ok!(<AssetHubPaseo as AssetHubPaseoPallet>::ForeignAssets::force_create(
RuntimeOrigin::root(),
weth_asset_location.clone().try_into().unwrap(),
weth_asset_location.clone(),
asset_hub_sovereign.into(),
false,
1,
));

assert!(<AssetHubPaseo as AssetHubPaseoPallet>::ForeignAssets::asset_exists(
weth_asset_location.clone().try_into().unwrap(),
weth_asset_location.clone(),
));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// limitations under the License.

use crate::*;
use coretime_paseo_runtime::xcm_config::XcmConfig;
use frame_support::{
dispatch::RawOrigin, sp_runtime::traits::Dispatchable, traits::fungible::Mutate,
};
Expand Down

0 comments on commit bc3a257

Please sign in to comment.