emulated_integration_tests_common/
pools.rs1pub use paste;
17
18pub use pallet_asset_conversion;
19
20#[macro_export]
24macro_rules! create_pool_with_native_location_on {
25 ( $chain:ident, $native_location:expr, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => {
26 $crate::pools::paste::paste! {
27 <$chain>::execute_with(|| {
28 type RuntimeEvent = <$chain as Chain>::RuntimeEvent;
29 let owner = $asset_owner;
30 let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone());
31 let native_location: Location = $native_location;
32
33 assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::create_pool(
34 signed_owner.clone(),
35 Box::new(native_location.clone()),
36 Box::new($asset_id.clone()),
37 ));
38
39 assert_expected_events!(
40 $chain,
41 vec![
42 RuntimeEvent::AssetConversion($crate::pools::pallet_asset_conversion::Event::PoolCreated { .. }) => {},
43 ]
44 );
45
46 assert_ok!(<$chain as [<$chain Pallet>]>::AssetConversion::add_liquidity(
47 signed_owner,
48 Box::new(native_location),
49 Box::new($asset_id),
50 $wnd_amount,
51 $asset_amount,
52 0,
53 0,
54 owner.into()
55 ));
56
57 assert_expected_events!(
58 $chain,
59 vec![
60 RuntimeEvent::AssetConversion($crate::pools::pallet_asset_conversion::Event::LiquidityAdded { .. }) => {},
61 ]
62 );
63 });
64 }
65 };
66}
67
68#[macro_export]
69macro_rules! create_pool_with_relay_native_on {
70 ( $chain:ident, $asset_id:expr, $asset_owner:expr ) => {
72 $crate::create_pool_with_relay_native_on!(
73 $chain,
74 $asset_id,
75 $asset_owner,
76 1_000_000_000_000,
77 2_000_000_000_000
78 );
79 };
80
81 ( $chain:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => {
83 $crate::pools::paste::paste! {
84 <$chain>::execute_with(|| {
85 let owner = $asset_owner;
86 let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone());
87
88 let asset_id = match $asset_id.interior.last() {
89 Some(GeneralIndex(id)) => *id as u32,
90 _ => unreachable!(),
91 };
92 assert_ok!(<$chain as [<$chain Pallet>]>::Assets::mint(
93 signed_owner.clone(),
94 asset_id.into(),
95 owner.clone().into(),
96 10_000_000_000_000, ));
98 });
99
100 let parent_location: Location = Parent.into();
101 $crate::create_pool_with_native_location_on!($chain, parent_location, $asset_id, $asset_owner, $wnd_amount, $asset_amount);
102 }
103 };
104}
105
106#[macro_export]
107macro_rules! create_foreign_pool_with_parent_native_on {
108 ( $chain:ident, $asset_id:expr, $asset_owner:expr ) => {
110 $crate::create_foreign_pool_with_parent_native_on!(
111 $chain,
112 ForeignAssets,
113 $asset_id,
114 $asset_owner,
115 1_000_000_000_000,
116 2_000_000_000_000
117 );
118 };
119
120 ( $chain:ident, $foreign_pallet_assets:ident, $asset_id:expr, $asset_owner:expr ) => {
122 $crate::create_foreign_pool_with_parent_native_on!(
123 $chain,
124 $foreign_pallet_assets,
125 $asset_id,
126 $asset_owner,
127 1_000_000_000_000,
128 2_000_000_000_000
129 );
130 };
131
132 ( $chain:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => {
134 $crate::create_foreign_pool_with_parent_native_on!(
135 $chain,
136 ForeignAssets,
137 $asset_id,
138 $asset_owner,
139 $wnd_amount,
140 $asset_amount
141 );
142 };
143
144 ( $chain:ident, $foreign_pallet_assets:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => {
146 $crate::pools::paste::paste! {
147 <$chain>::execute_with(|| {
148 let owner = $asset_owner;
149 let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone());
150
151 assert_ok!(<$chain as [<$chain Pallet>]>::$foreign_pallet_assets::mint(
152 signed_owner.clone(),
153 $asset_id.clone().into(),
154 owner.clone().into(),
155 10_000_000_000_000, ));
157 });
158
159 let wnd_location: Location = Parent.into();
160 $crate::create_pool_with_native_location_on!($chain, wnd_location, $asset_id, $asset_owner, $wnd_amount, $asset_amount);
161 }
162 };
163}
164
165#[macro_export]
166macro_rules! create_foreign_pool_with_native_on {
167 ( $chain:ident, $asset_id:expr, $asset_owner:expr ) => {
169 $crate::create_foreign_pool_with_native_on!(
170 $chain,
171 Assets,
172 $asset_id,
173 $asset_owner,
174 1_000_000_000_000,
175 2_000_000_000_000
176 );
177 };
178
179 ( $chain:ident, $foreign_pallet_asset:ident, $asset_id:expr, $asset_owner:expr ) => {
181 $crate::create_foreign_pool_with_native_on!(
182 $chain,
183 $foreign_pallet_asset,
184 $asset_id,
185 $asset_owner,
186 1_000_000_000_000,
187 2_000_000_000_000
188 );
189 };
190
191 ( $chain:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => {
193 $crate::create_foreign_pool_with_native_on!(
194 $chain,
195 Assets,
196 $asset_id,
197 $asset_owner,
198 $wnd_amount,
199 $asset_amount
200 );
201 };
202
203 ( $chain:ident, $foreign_asset_pallet:ident, $asset_id:expr, $asset_owner:expr, $wnd_amount:expr, $asset_amount:expr ) => {
205 $crate::pools::paste::paste! {
206 <$chain>::execute_with(|| {
207 let owner = $asset_owner;
208 let signed_owner = <$chain as Chain>::RuntimeOrigin::signed(owner.clone());
209
210 assert_ok!(<$chain as [<$chain Pallet>]>::$foreign_asset_pallet::mint(
211 signed_owner.clone(),
212 $asset_id.clone().into(),
213 owner.clone().into(),
214 10_000_000_000_000, ));
216 });
217
218 let native_location: Location = Here.into();
219 $crate::create_pool_with_native_location_on!($chain, native_location, $asset_id, $asset_owner, $wnd_amount, $asset_amount);
220 }
221 };
222}