Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
66 changes: 66 additions & 0 deletions cumulus/parachains/integration-tests/emulated/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,3 +822,69 @@ macro_rules! test_cross_chain_alias {
}
};
}

/// note: $asset needs to be prefunded outside this function
#[macro_export]
macro_rules! create_pool_with_native_on {
( $chain:ident, $asset:expr, $is_foreign:expr, $asset_owner:expr ) => {
emulated_integration_tests_common::impls::paste::paste! {
<$chain>::execute_with(|| {
type RuntimeEvent = <$chain as Chain>::RuntimeEvent;
let owner = $asset_owner;
let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone());
let native_asset: Location = Parent.into();

if $is_foreign {
assert_ok!(<$chain as [<$chain Pallet>]>::ForeignAssets::mint(
signed_owner.clone(),
$asset.clone().into(),
owner.clone().into(),
10_000_000_000_000, // For it to have more than enough.
));
} else {
let asset_id = match $asset.interior.last() {
Some(GeneralIndex(id)) => *id as u32,
_ => unreachable!(),
};
assert_ok!(<$chain as [<$chain Pallet>]>::Assets::mint(
signed_owner.clone(),
asset_id.into(),
owner.clone().into(),
10_000_000_000_000, // For it to have more than enough.
));
}

assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::create_pool(
signed_owner.clone(),
Box::new(native_asset.clone()),
Box::new($asset.clone()),
));

assert_expected_events!(
$chain,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {},
]
);

assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::add_liquidity(
signed_owner,
Box::new(native_asset),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claravanstaden I am afraid of native_asset's import Location - it works for polkadot-sdk where we use xcm::v5 for pallet_assets/pallet_asset_conversion, but will it work if those pallets are using older version (e.g. polkadot-fellows) and also the same for GeneralIndex? Would Box::new(native_asset.into()) do the trick?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkontur it doesn't seem to work. There are impls from v4 into v5, but not the other way around (from what I can see): https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/src/v5/location.rs#L748. I can change the method signature to pass in the native_asset? Not sure what to do about GeneralIndex though.

Box::new($asset),
1_000_000_000_000,
2_000_000_000_000, // $asset is worth half of native_asset
0,
0,
owner.into()
));

assert_expected_events!(
$chain,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded { .. }) => {},
]
);
});
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod imports {

// Cumulus
pub use emulated_integration_tests_common::{
create_pool_with_native_on,
accounts::ALICE,
impls::Inspect,
test_dry_run_transfer_across_pk_bridge, test_parachain_is_trusted_teleporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{create_pool_with_native_on, tests::*};
use crate::{tests::*};
use emulated_integration_tests_common::macros::Dmp;
use xcm::latest::AssetTransferFilter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,71 +121,6 @@ pub(crate) fn foreign_balance_on_ah_westend(id: v5::Location, who: &AccountId) -
})
}

/// note: $asset needs to be prefunded outside this function
#[macro_export]
macro_rules! create_pool_with_native_on {
( $chain:ident, $asset:expr, $is_foreign:expr, $asset_owner:expr ) => {
emulated_integration_tests_common::impls::paste::paste! {
<$chain>::execute_with(|| {
type RuntimeEvent = <$chain as Chain>::RuntimeEvent;
let owner = $asset_owner;
let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone());
let native_asset: Location = Parent.into();

if $is_foreign {
assert_ok!(<$chain as [<$chain Pallet>]>::ForeignAssets::mint(
signed_owner.clone(),
$asset.clone().into(),
owner.clone().into(),
10_000_000_000_000, // For it to have more than enough.
));
} else {
let asset_id = match $asset.interior.last() {
Some(GeneralIndex(id)) => *id as u32,
_ => unreachable!(),
};
assert_ok!(<$chain as [<$chain Pallet>]>::Assets::mint(
signed_owner.clone(),
asset_id.into(),
owner.clone().into(),
10_000_000_000_000, // For it to have more than enough.
));
}

assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::create_pool(
signed_owner.clone(),
Box::new(native_asset.clone()),
Box::new($asset.clone()),
));

assert_expected_events!(
$chain,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::PoolCreated { .. }) => {},
]
);

assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::add_liquidity(
signed_owner,
Box::new(native_asset),
Box::new($asset),
1_000_000_000_000,
2_000_000_000_000, // $asset is worth half of native_asset
0,
0,
owner.into()
));

assert_expected_events!(
$chain,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::LiquidityAdded { .. }) => {},
]
);
});
}
};
}

pub(crate) fn send_assets_from_asset_hub_westend(
destination: Location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{create_pool_with_native_on, imports::*};
use crate::{imports::*};
use asset_hub_westend_runtime::xcm_config::LocationToAccountId;
use emulated_integration_tests_common::PenpalBTeleportableAssetLocation;
use frame_support::traits::fungibles::Mutate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.

use crate::{
create_pool_with_native_on,
tests::{snowbridge::CHAIN_ID, *},
};
use sp_core::Get;
Expand Down
Loading