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

Improve Penpal runtime/emulated tests + AssetHub TokenLocationAsNative #3339

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ decl_test_parachains! {
impl_accounts_helpers_for_parachain!(AssetHubRococo);
impl_assert_events_helpers_for_parachain!(AssetHubRococo);
impl_assets_helpers_for_parachain!(AssetHubRococo, Rococo);
impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, Rococo);
impl_foreign_assets_helpers_for_parachain!(AssetHubRococo);
impl_xcm_helpers_for_parachain!(AssetHubRococo);
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ decl_test_parachains! {
impl_accounts_helpers_for_parachain!(AssetHubWestend);
impl_assert_events_helpers_for_parachain!(AssetHubWestend);
impl_assets_helpers_for_parachain!(AssetHubWestend, Westend);
impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, Westend);
impl_foreign_assets_helpers_for_parachain!(AssetHubWestend);
impl_xcm_helpers_for_parachain!(AssetHubWestend);
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ workspace = true
sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false }
frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false }

# Polkadot
xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false }

# Cumulus
parachains-common = { path = "../../../../../../../parachains/common" }
cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ use sp_core::{sr25519, storage::Storage};
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION,
};
use parachains_common::Balance;

use parachains_common::{Balance, AccountId};
use penpal_runtime::xcm_config::{RelayLocationV3, SystemAssetHubLocationV3};
// Penpal
pub const PARA_ID_A: u32 = 2000;
pub const PARA_ID_B: u32 = 2001;
pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT;

pub fn asset_owner() -> AccountId {
get_account_id_from_seed::<sr25519::Public>("Alice")
}

pub fn genesis(para_id: u32) -> Storage {
let genesis_config = penpal_runtime::RuntimeGenesisConfig {
system: penpal_runtime::SystemConfig::default(),
Expand Down Expand Up @@ -61,6 +65,15 @@ pub fn genesis(para_id: u32) -> Storage {
sudo: penpal_runtime::SudoConfig {
key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
},
foreign_assets: penpal_runtime::ForeignAssetsConfig {
assets: vec![
// AssetHub Native asset representation
(SystemAssetHubLocationV3::get(), get_account_id_from_seed::<sr25519::Public>("Alice"), true, ED),
// Relay Native asset representation
(RelayLocationV3::get(), get_account_id_from_seed::<sr25519::Public>("Alice"), true, ED)
],
..Default::default()
},
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
// limitations under the License.

mod genesis;
pub use genesis::{genesis, ED, PARA_ID_A, PARA_ID_B};
pub use penpal_runtime::xcm_config::{
LocalTeleportableToAssetHub, LocalTeleportableToAssetHubV3, XcmConfig,
};
pub use genesis::{genesis, asset_owner, ED, PARA_ID_A, PARA_ID_B};

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

// Cumulus
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain,
impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
};
use rococo_emulated_chain::Rococo;
Expand Down Expand Up @@ -79,3 +76,5 @@ impl_assets_helpers_for_parachain!(PenpalA, Rococo);
impl_assets_helpers_for_parachain!(PenpalB, Westend);
impl_assert_events_helpers_for_parachain!(PenpalA);
impl_assert_events_helpers_for_parachain!(PenpalB);
impl_foreign_assets_helpers_for_parachain!(PenpalA);
impl_foreign_assets_helpers_for_parachain!(PenpalB);
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ macro_rules! impl_assets_helpers_for_parachain {

#[macro_export]
macro_rules! impl_foreign_assets_helpers_for_parachain {
( $chain:ident, $relay_chain:ident ) => {
( $chain:ident) => {
$crate::impls::paste::paste! {
impl<N: $crate::impls::Network> $chain<N> {
/// Create foreign assets using sudo `ForeignAssets::force_create()`
Expand Down
27 changes: 22 additions & 5 deletions cumulus/parachains/integration-tests/emulated/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@ pub use paste;
pub use pallet_balances;
pub use pallet_message_queue;
pub use pallet_xcm;
pub use pallet_assets;
pub use frame_support::{pallet_prelude::Weight, weights::WeightToFee};

// Polkadot
pub use xcm::prelude::{AccountId32, WeightLimit};
pub use xcm::{
v3::Location as V3Location,
prelude::{
OriginKind, AccountId32, WeightLimit, Asset, AssetId, Fungible,
Location, Here, VersionedXcm, Xcm, Unlimited, WithdrawAsset, BuyExecution,
Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset,
All
},
};

// Cumulus
pub use asset_test_utils;
pub use cumulus_pallet_xcmp_queue;
pub use xcm_emulator::Chain;
pub use parachains_common::AccountId;

#[macro_export]
macro_rules! test_parachain_is_trusted_teleporter {
Expand Down Expand Up @@ -127,13 +138,19 @@ macro_rules! include_penpal_create_foreign_asset_on_asset_hub {
$crate::impls::paste::paste! {
pub fn penpal_create_foreign_asset_on_asset_hub(
asset_id_on_penpal: u32,
foreign_asset_at_asset_hub: v3::Location,
ah_as_seen_by_penpal: Location,
foreign_asset_at_asset_hub: $crate::macros::V3Location,
ah_as_seen_by_penpal: $crate::macros::Location,
is_sufficient: bool,
asset_owner: AccountId,
asset_owner: $crate::macros::AccountId,
prefund_amount: u128,
) {
use frame_support::weights::WeightToFee;
use $crate::macros::{
pallet_assets, pallet_xcm, Chain, Weight, OriginKind, Asset, AssetId, Fungible,
Location, Here, VersionedXcm, Xcm, Unlimited, WeightToFee, WithdrawAsset, BuyExecution,
Transact, ExpectTransactStatus, MaybeErrorCode, RefundSurplus, DepositAsset,
All
};

let ah_check_account = $asset_hub::execute_with(|| {
<$asset_hub as [<$asset_hub Pallet>]>::PolkadotXcm::check_account()
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ parachains-common = { path = "../../../../../../parachains/common" }
cumulus-pallet-parachain-system = { path = "../../../../../../pallets/parachain-system", default-features = false }
testnet-parachains-constants = { path = "../../../../../runtimes/constants", features = ["rococo"] }
asset-hub-rococo-runtime = { path = "../../../../../runtimes/assets/asset-hub-rococo" }
penpal-runtime = { path = "../../../../../runtimes/testing/penpal" }
emulated-integration-tests-common = { path = "../../../common", default-features = false }
rococo-system-emulated-network = { path = "../../../networks/rococo-system" }
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,82 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub use codec::Encode;
#[cfg(test)]
mod imports {
pub use codec::Encode;

// Substrate
pub use frame_support::{
assert_err, assert_ok,
pallet_prelude::Weight,
sp_runtime::{DispatchError, DispatchResult, ModuleError},
traits::fungibles::Inspect,
};

// Polkadot
pub use xcm::{
prelude::{AccountId32 as AccountId32Junction, *},
v3,
};

// Substrate
pub use frame_support::{
assert_err, assert_ok,
pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchError, DispatchResult},
traits::fungibles::Inspect,
};
// Cumulus
pub use asset_test_utils::xcm_helpers;
pub use emulated_integration_tests_common::{
test_parachain_is_trusted_teleporter,
xcm_emulator::{
assert_expected_events, bx, Chain, Parachain as Para,
RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
},
xcm_helpers::{xcm_transact_paid_execution, non_fee_asset},
XCM_V3,
};
pub use parachains_common::Balance;
pub use rococo_system_emulated_network::{
asset_hub_rococo_emulated_chain::{
genesis::{ED as ASSET_HUB_ROCOCO_ED, PARA_ID as ASSETHUB_PARA_ID}, AssetHubRococoParaPallet as AssetHubRococoPallet,
},
penpal_emulated_chain::{PenpalAParaPallet as PenpalAPallet, PenpalBParaPallet as PenpalBPallet, asset_owner as penpal_asset_owner},
rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet},
AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver,
AssetHubRococoParaSender as AssetHubRococoSender, BridgeHubRococoPara as BridgeHubRococo,
BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, PenpalAPara as PenpalA,
PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender,
PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, RococoRelay as Rococo,
RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender,
};

// Polkadot
pub use xcm::{
prelude::{AccountId32 as AccountId32Junction, *},
v3::{self, Error, NetworkId::Rococo as RococoId},
};
// Runtimes
pub use rococo_runtime::xcm_config::{XcmConfig as RococoXcmConfig, UniversalLocation as RococoUniversalLocation};
pub use asset_hub_rococo_runtime::xcm_config::{
XcmConfig as AssetHubRococoXcmConfig, UniversalLocation as AssetHubRococoUniversalLocation,
TokenLocationV3 as RelayLocationV3,
};
pub use penpal_runtime::xcm_config::{
LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3,
SystemAssetHubLocationV3,
UniversalLocation as PenpalUniversalLocation, XcmConfig as PenpalRococoXcmConfig
};

// Cumulus
pub use asset_test_utils::xcm_helpers;
pub use emulated_integration_tests_common::{
test_parachain_is_trusted_teleporter,
xcm_emulator::{
assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
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,
};
pub use parachains_common::{AccountId, Balance};
pub use rococo_system_emulated_network::{
asset_hub_rococo_emulated_chain::{
genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet,
},
penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet,
rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet},
AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver,
AssetHubRococoParaSender as AssetHubRococoSender, BridgeHubRococoPara as BridgeHubRococo,
BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, PenpalAPara as PenpalA,
PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender,
PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, RococoRelay as Rococo,
RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender,
};
pub const ASSET_ID: u32 = 1;
pub const ASSET_MIN_BALANCE: u128 = 1000;
// `Assets` pallet index
pub const ASSETS_PALLET_ID: u8 = 50;

pub const ASSET_ID: u32 = 1;
pub const ASSET_MIN_BALANCE: u128 = 1000;
// `Assets` pallet index
pub const ASSETS_PALLET_ID: u8 = 50;
pub type RelayToSystemParaTest = Test<Rococo, AssetHubRococo>;
pub type RelayToParaTest = Test<Rococo, PenpalA>;
pub type SystemParaToRelayTest = Test<AssetHubRococo, Rococo>;
pub type SystemParaToParaTest = Test<AssetHubRococo, PenpalA>;
pub type ParaToSystemParaTest = Test<PenpalA, AssetHubRococo>;
pub type ParaToParaThroughRelayTest = Test<PenpalA, PenpalB, Rococo>;
pub type ParaToParaThroughSystemParaTest = Test<PenpalA, PenpalB, AssetHubRococo>;

pub type RelayToSystemParaTest = Test<Rococo, AssetHubRococo>;
pub type RelayToParaTest = Test<Rococo, PenpalA>;
pub type SystemParaToRelayTest = Test<AssetHubRococo, Rococo>;
pub type SystemParaToParaTest = Test<AssetHubRococo, PenpalA>;
pub type ParaToSystemParaTest = Test<PenpalA, AssetHubRococo>;
pub type ParaToParaTest = Test<PenpalA, PenpalB, Rococo>;
emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!(
PenpalA,
AssetHubRococo,
ROCOCO_ED,
testnet_parachains_constants::rococo::fee::WeightToFee
);
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,3 @@ mod send;
mod set_xcm_versions;
mod swap;
mod teleport;

use crate::*;
emulated_integration_tests_common::include_penpal_create_foreign_asset_on_asset_hub!(
PenpalA,
AssetHubRococo,
ROCOCO_ED,
testnet_parachains_constants::rococo::fee::WeightToFee
);
Loading
Loading