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

Remove xcm::v3 from assets-common nits #4037

Merged
merged 15 commits into from
Apr 12, 2024
Merged
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
2 changes: 2 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 @@ -23,3 +23,6 @@ emulated-integration-tests-common = { path = "../../../../common", default-featu
asset-hub-rococo-runtime = { path = "../../../../../../runtimes/assets/asset-hub-rococo" }
rococo-emulated-chain = { path = "../../../relays/rococo" }
testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["rococo"] }

# Polkadot
xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false }
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use frame_support::traits::OnInitialize;
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain,
impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
impl_foreign_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain,
xcm_emulator::decl_test_parachains,
};
use rococo_emulated_chain::Rococo;

Expand Down Expand Up @@ -56,4 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubRococo);
impl_assert_events_helpers_for_parachain!(AssetHubRococo);
impl_assets_helpers_for_system_parachain!(AssetHubRococo, Rococo);
impl_assets_helpers_for_parachain!(AssetHubRococo);
impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, xcm::v3::Location);
impl_xcm_helpers_for_parachain!(AssetHubRococo);
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ emulated-integration-tests-common = { path = "../../../../common", default-featu
asset-hub-westend-runtime = { path = "../../../../../../runtimes/assets/asset-hub-westend" }
westend-emulated-chain = { path = "../../../relays/westend" }
testnet-parachains-constants = { path = "../../../../../../runtimes/constants", features = ["westend"] }

# Polkadot
xcm = { package = "staging-xcm", path = "../../../../../../../../polkadot/xcm", default-features = false }
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use frame_support::traits::OnInitialize;
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_assets_helpers_for_system_parachain,
impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
impl_foreign_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain,
xcm_emulator::decl_test_parachains,
};
use westend_emulated_chain::Westend;

Expand Down Expand Up @@ -56,4 +57,5 @@ impl_accounts_helpers_for_parachain!(AssetHubWestend);
impl_assert_events_helpers_for_parachain!(AssetHubWestend);
impl_assets_helpers_for_system_parachain!(AssetHubWestend, Westend);
impl_assets_helpers_for_parachain!(AssetHubWestend);
impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, xcm::v3::Location);
impl_xcm_helpers_for_parachain!(AssetHubWestend);
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use frame_support::parameter_types;
use sp_core::{sr25519, storage::Storage};

// Polkadot
use xcm::v3::Location;
// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, get_account_id_from_seed, SAFE_XCM_VERSION,
Expand Down Expand Up @@ -79,19 +77,9 @@ pub fn genesis(para_id: u32) -> Storage {
foreign_assets: penpal_runtime::ForeignAssetsConfig {
assets: vec![
// Relay Native asset representation
(
Location::try_from(RelayLocation::get()).unwrap(),
PenpalAssetOwner::get(),
true,
ED,
),
(RelayLocation::get(), PenpalAssetOwner::get(), true, ED),
// Sufficient AssetHub asset representation
(
Location::try_from(LocalReservableFromAssetHub::get()).unwrap(),
PenpalAssetOwner::get(),
true,
ED,
),
(LocalReservableFromAssetHub::get(), PenpalAssetOwner::get(), true, ED),
],
..Default::default()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ 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_xcm_helpers_for_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 Down Expand Up @@ -87,6 +88,8 @@ 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_foreign_assets_helpers_for_parachain!(PenpalA, xcm::latest::Location);
impl_assets_helpers_for_parachain!(PenpalB);
impl_foreign_assets_helpers_for_parachain!(PenpalB, xcm::latest::Location);
impl_xcm_helpers_for_parachain!(PenpalA);
impl_xcm_helpers_for_parachain!(PenpalB);
110 changes: 59 additions & 51 deletions cumulus/parachains/integration-tests/emulated/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ pub use polkadot_runtime_parachains::{
inclusion::{AggregateMessageOrigin, UmpQueueId},
};
pub use xcm::{
prelude::{Location, OriginKind, Outcome, VersionedXcm, XcmVersion},
v3,
v4::Error as XcmError,
prelude::{Location, OriginKind, Outcome, VersionedXcm, XcmError, XcmVersion},
DoubleEncoded,
};

Expand Down Expand Up @@ -696,12 +694,12 @@ macro_rules! impl_assets_helpers_for_system_parachain {

#[macro_export]
macro_rules! impl_assets_helpers_for_parachain {
( $chain:ident) => {
($chain:ident) => {
$crate::impls::paste::paste! {
impl<N: $crate::impls::Network> $chain<N> {
/// Create foreign assets using sudo `ForeignAssets::force_create()`
pub fn force_create_foreign_asset(
id: $crate::impls::v3::Location,
/// Create assets using sudo `Assets::force_create()`
pub fn force_create_asset(
id: u32,
owner: $crate::impls::AccountId,
is_sufficient: bool,
min_balance: u128,
Expand All @@ -711,20 +709,20 @@ macro_rules! impl_assets_helpers_for_parachain {
let sudo_origin = <$chain<N> as $crate::impls::Chain>::RuntimeOrigin::root();
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(
<Self as [<$chain ParaPallet>]>::ForeignAssets::force_create(
<Self as [<$chain ParaPallet>]>::Assets::force_create(
sudo_origin,
id.clone(),
id.clone().into(),
owner.clone().into(),
is_sufficient,
min_balance,
)
);
assert!(<Self as [<$chain ParaPallet>]>::ForeignAssets::asset_exists(id.clone()));
assert!(<Self as [<$chain ParaPallet>]>::Assets::asset_exists(id.clone()));
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::ForeignAssets(
RuntimeEvent::<N>::Assets(
$crate::impls::pallet_assets::Event::ForceCreated {
asset_id,
..
Expand All @@ -736,19 +734,19 @@ macro_rules! impl_assets_helpers_for_parachain {
for (beneficiary, amount) in prefund_accounts.into_iter() {
let signed_origin =
<$chain<N> as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone());
Self::mint_foreign_asset(signed_origin, id.clone(), beneficiary, amount);
Self::mint_asset(signed_origin, id.clone(), beneficiary, amount);
}
}

/// Mint assets making use of the ForeignAssets pallet-assets instance
pub fn mint_foreign_asset(
/// Mint assets making use of the assets pallet
pub fn mint_asset(
signed_origin: <Self as $crate::impls::Chain>::RuntimeOrigin,
id: $crate::impls::v3::Location,
id: u32,
beneficiary: $crate::impls::AccountId,
amount_to_mint: u128,
) {
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::ForeignAssets::mint(
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::Assets::mint(
signed_origin,
id.clone().into(),
beneficiary.clone().into(),
Expand All @@ -760,7 +758,7 @@ macro_rules! impl_assets_helpers_for_parachain {
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::ForeignAssets(
RuntimeEvent::<N>::Assets(
$crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }
) => {
asset_id: *asset_id == id,
Expand All @@ -771,9 +769,39 @@ macro_rules! impl_assets_helpers_for_parachain {
);
});
}
/// Create assets using sudo `Assets::force_create()`
pub fn force_create_asset(
id: u32,

/// Returns the encoded call for `create` from the assets pallet
pub fn create_asset_call(
asset_id: u32,
min_balance: $crate::impls::Balance,
admin: $crate::impls::AccountId,
) -> $crate::impls::DoubleEncoded<()> {
use $crate::impls::{Chain, Encode};

<Self as Chain>::RuntimeCall::Assets($crate::impls::pallet_assets::Call::<
<Self as Chain>::Runtime,
$crate::impls::pallet_assets::Instance1,
>::create {
id: asset_id.into(),
min_balance,
admin: admin.into(),
})
.encode()
.into()
}
}
}
};
}

#[macro_export]
macro_rules! impl_foreign_assets_helpers_for_parachain {
($chain:ident, $asset_id_type:ty) => {
$crate::impls::paste::paste! {
impl<N: $crate::impls::Network> $chain<N> {
/// Create foreign assets using sudo `ForeignAssets::force_create()`
pub fn force_create_foreign_asset(
id: $asset_id_type,
owner: $crate::impls::AccountId,
is_sufficient: bool,
min_balance: u128,
Expand All @@ -783,20 +811,20 @@ macro_rules! impl_assets_helpers_for_parachain {
let sudo_origin = <$chain<N> as $crate::impls::Chain>::RuntimeOrigin::root();
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(
<Self as [<$chain ParaPallet>]>::Assets::force_create(
<Self as [<$chain ParaPallet>]>::ForeignAssets::force_create(
sudo_origin,
id.clone().into(),
id.clone(),
owner.clone().into(),
is_sufficient,
min_balance,
)
);
assert!(<Self as [<$chain ParaPallet>]>::Assets::asset_exists(id.clone()));
assert!(<Self as [<$chain ParaPallet>]>::ForeignAssets::asset_exists(id.clone()));
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::Assets(
RuntimeEvent::<N>::ForeignAssets(
$crate::impls::pallet_assets::Event::ForceCreated {
asset_id,
..
Expand All @@ -808,19 +836,19 @@ macro_rules! impl_assets_helpers_for_parachain {
for (beneficiary, amount) in prefund_accounts.into_iter() {
let signed_origin =
<$chain<N> as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone());
Self::mint_asset(signed_origin, id.clone(), beneficiary, amount);
Self::mint_foreign_asset(signed_origin, id.clone(), beneficiary, amount);
}
}

/// Mint assets making use of the assets pallet
pub fn mint_asset(
/// Mint assets making use of the ForeignAssets pallet-assets instance
pub fn mint_foreign_asset(
signed_origin: <Self as $crate::impls::Chain>::RuntimeOrigin,
id: u32,
id: $asset_id_type,
beneficiary: $crate::impls::AccountId,
amount_to_mint: u128,
) {
<Self as $crate::impls::TestExt>::execute_with(|| {
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::Assets::mint(
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::ForeignAssets::mint(
signed_origin,
id.clone().into(),
beneficiary.clone().into(),
Expand All @@ -832,7 +860,7 @@ macro_rules! impl_assets_helpers_for_parachain {
$crate::impls::assert_expected_events!(
Self,
vec![
RuntimeEvent::<N>::Assets(
RuntimeEvent::<N>::ForeignAssets(
$crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }
) => {
asset_id: *asset_id == id,
Expand All @@ -844,29 +872,9 @@ macro_rules! impl_assets_helpers_for_parachain {
});
}

/// Returns the encoded call for `create` from the assets pallet
pub fn create_asset_call(
asset_id: u32,
min_balance: $crate::impls::Balance,
admin: $crate::impls::AccountId,
) -> $crate::impls::DoubleEncoded<()> {
use $crate::impls::{Chain, Encode};

<Self as Chain>::RuntimeCall::Assets($crate::impls::pallet_assets::Call::<
<Self as Chain>::Runtime,
$crate::impls::pallet_assets::Instance1,
>::create {
id: asset_id.into(),
min_balance,
admin: admin.into(),
})
.encode()
.into()
}

/// Returns the encoded call for `create` from the foreign assets pallet
pub fn create_foreign_asset_call(
asset_id: $crate::impls::v3::Location,
asset_id: $asset_id_type,
min_balance: $crate::impls::Balance,
admin: $crate::impls::AccountId,
) -> $crate::impls::DoubleEncoded<()> {
Expand Down
Loading
Loading