diff --git a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs index de969d665e8fa..84f76333ab66b 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/macros.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/macros.rs @@ -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), + 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 { .. }) => {}, + ] + ); + }); + } + }; +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index c522b41fd81fe..74f6798b389dd 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -31,6 +31,7 @@ mod imports { // Cumulus pub use emulated_integration_tests_common::{ accounts::ALICE, + create_pool_with_native_on, impls::Inspect, test_dry_run_transfer_across_pk_bridge, test_parachain_is_trusted_teleporter, test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs index ef2e87d6c0dce..dcbbce5ee83a1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -13,10 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{ - create_pool_with_native_on, - tests::{snowbridge_common::snowbridge_sovereign, *}, -}; +use crate::tests::{snowbridge_common::snowbridge_sovereign, *}; use emulated_integration_tests_common::macros::Dmp; use xcm::latest::AssetTransferFilter; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs index 4b1c94e81510a..21ec376a8483b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs @@ -122,72 +122,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, assets: Assets, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs index 3663c2104bea7..47d8f63ea0eaf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_common.rs @@ -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::{ snowbridge::{SEPOLIA_ID, WETH}, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs index f1d69981691c6..96937a95a99b5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs @@ -13,10 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{ - create_pool_with_native_on, - tests::{snowbridge_common::snowbridge_sovereign, *}, -}; +use crate::tests::{snowbridge_common::snowbridge_sovereign, *}; use sp_core::Get; use xcm::latest::AssetTransferFilter; diff --git a/prdoc/pr_8289.prdoc b/prdoc/pr_8289.prdoc new file mode 100644 index 0000000000000..4459e05117f62 --- /dev/null +++ b/prdoc/pr_8289.prdoc @@ -0,0 +1,11 @@ +title: 'Extract create_pool_with_native_on macro to common crate' +doc: +- audience: Runtime Dev + description: |- + Extract the macro in the `bridge-hub-westend-integration-tests` crate to the `emulated-integration-tests-common` + crate, so that it can be used in the runtimes repository as well. +crates: +- name: bridge-hub-westend-integration-tests + bump: patch +- name: emulated-integration-tests-common + bump: minor