@@ -7,7 +7,7 @@ use crate::{
7
7
init_tracing,
8
8
relay_chain:: { self , RuntimeOrigin } ,
9
9
runtime,
10
- runtime:: { Test , ALICE , BOB , Assets } ,
10
+ runtime:: { Test , ALICE , BOB , Assets , PalletXcm } ,
11
11
xcm:: { MockNet , ParaA , ParaB , Relay } ,
12
12
} ;
13
13
use alloy_sol_types:: SolValue ;
@@ -34,14 +34,18 @@ use polkadot_sdk::{
34
34
use sp_core:: { crypto:: AccountId32 , ByteArray , H160 , H256 } ;
35
35
use staging_xcm:: v5:: { Junction , Junctions , Location , NetworkId , WeightLimit } ;
36
36
use xcm_simulator:: TestExt ;
37
+ use pallet_xcm_gateway:: xcm_utilities:: ASSET_HUB_PARA_ID ;
37
38
use crate :: runtime:: ReputationAssetId ;
38
39
39
40
const SEND_AMOUNT : u128 = 1000_000_000_0000 ;
40
41
const PARA_ID : u32 = crate :: xcm:: SIBLING_PARA_ID ;
41
42
pub type RelayChainPalletXcm = pallet_xcm:: Pallet < relay_chain:: Runtime > ;
42
43
43
- fn reserve_transfer_on_AH ( amount : u128 , beneficiary : Location ) {
44
- let asset_location_on_assethub = Location :: new ( 1 , Here ) ;
44
+ #[ test]
45
+ fn should_dispatch_ismp_request_when_assets_are_received_from_assethub ( ) {
46
+ init_tracing ( ) ;
47
+ MockNet :: reset ( ) ;
48
+ let asset_location_on_assethub = Location :: new ( 1 , Here ) ;
45
49
46
50
//let asset_location_on_assethub_h256: H256 = sp_io::hashing::keccak_256(&asset_location_on_assethub.encode()).into();
47
51
@@ -78,10 +82,10 @@ fn reserve_transfer_on_AH(amount: u128, beneficiary: Location) {
78
82
Parachain ( 1000 ) ,
79
83
] ) ) ;
80
84
81
- let assets = Asset {
82
- id : AssetId ( asset_location_on_assethub. clone ( ) ) ,
83
- fun : Fungibility :: Fungible ( amount ) ,
84
- } ;
85
+ let assets = Asset {
86
+ id : AssetId ( asset_location_on_assethub. clone ( ) ) ,
87
+ fun : Fungibility :: Fungible ( SEND_AMOUNT ) ,
88
+ } ;
85
89
86
90
let fee_asset = assets. clone ( ) . reanchored ( & dest, & context) . expect ( "should reanchor" ) ;
87
91
let fees = fee_asset. clone ( ) ;
@@ -156,43 +160,10 @@ fn reserve_transfer_on_AH(amount: u128, beneficiary: Location) {
156
160
} ) ;
157
161
158
162
}
159
- #[ test]
160
- fn should_dispatch_ismp_request_when_assets_are_received_from_assethub ( ) {
161
- init_tracing ( ) ;
162
- MockNet :: reset ( ) ;
163
-
164
- let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & Location :: new ( 1 , Here ) . encode ( ) ) . into ( ) ;
165
-
166
- let beneficiary: Location = Junctions :: X3 ( Arc :: new ( [
167
- Junction :: AccountId32 { network : None , id : ALICE . into ( ) } ,
168
- Junction :: AccountKey20 {
169
- network : Some ( NetworkId :: Ethereum { chain_id : 97 } ) ,
170
- key : [ 1u8 ; 20 ] ,
171
- } ,
172
- Junction :: GeneralIndex ( 60 * 60 ) ,
173
- ] ) )
174
- . into_location ( ) ;
175
-
176
- reserve_transfer_on_AH ( SEND_AMOUNT , beneficiary) ;
177
-
178
- ParaA :: execute_with ( || {
179
- let nonce = pallet_ismp:: Nonce :: < Test > :: get ( ) ;
180
- assert_eq ! ( nonce, 1 ) ;
181
-
182
- let protocol_fees = pallet_xcm_gateway:: Pallet :: < Test > :: protocol_fee_percentage ( ) ;
183
- let custodied_amount = SEND_AMOUNT - ( protocol_fees * SEND_AMOUNT ) ;
184
-
185
- let pallet_account_balance =
186
- <runtime:: Assets as Inspect < <Test as frame_system:: Config >:: AccountId > >:: balance (
187
- asset_id. into ( ) ,
188
- & pallet_xcm_gateway:: Pallet :: < Test > :: account_id ( ) ,
189
- ) ;
190
- assert_eq ! ( custodied_amount, pallet_account_balance) ;
191
- } ) ;
192
- }
193
163
194
164
#[ test]
195
165
fn should_process_on_accept_module_callback_correctly ( ) {
166
+ init_tracing ( ) ;
196
167
MockNet :: reset ( ) ;
197
168
198
169
let beneficiary: Location = Junctions :: X3 ( Arc :: new ( [
@@ -206,14 +177,22 @@ fn should_process_on_accept_module_callback_correctly() {
206
177
. into_location ( ) ;
207
178
let weight_limit = WeightLimit :: Unlimited ;
208
179
209
- let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & Location :: new ( 1 , Here ) . encode ( ) ) . into ( ) ;
210
-
211
-
212
- reserve_transfer_on_AH ( SEND_AMOUNT , beneficiary) ;
180
+ let asset_location = Location :: new ( 1 , Here ) ;
213
181
182
+ let dest = Location :: new ( 1 , [ Parachain ( PARA_ID ) ] ) ;
183
+ let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & asset_location. encode ( ) ) . into ( ) ;
214
184
215
185
216
186
let alice_balance = ParaB :: execute_with ( || {
187
+ let result = PalletXcm :: limited_reserve_transfer_assets (
188
+ runtime:: RuntimeOrigin :: signed ( ALICE ) ,
189
+ Box :: new ( dest. clone ( ) . into ( ) ) ,
190
+ Box :: new ( beneficiary. clone ( ) . into ( ) ) ,
191
+ Box :: new ( ( asset_location, SEND_AMOUNT ) . into ( ) ) ,
192
+ 0 ,
193
+ weight_limit,
194
+ ) ;
195
+ assert_ok ! ( result) ;
217
196
let alice_balance = <runtime:: Assets as Inspect <
218
197
<Test as frame_system:: Config >:: AccountId ,
219
198
> >:: balance ( asset_id, & ALICE ) ;
@@ -244,15 +223,9 @@ fn should_process_on_accept_module_callback_correctly() {
244
223
assert_eq ! ( custodied_amount, pallet_account_balance) ;
245
224
} ) ;
246
225
247
- ParaB :: execute_with ( || {
248
- let dot_asset_location = Location :: new ( 1 , Parachain ( 1000 ) ) ;
249
- let dot_asset_id: H256 = sp_io:: hashing:: keccak_256 ( & dot_asset_location. encode ( ) ) . into ( ) ;
250
-
251
- Assets :: set_balance ( dot_asset_id, & pallet_xcm_gateway:: Pallet :: < Test > :: account_id ( ) , SEND_AMOUNT * 10 ) ;
252
- } ) ;
253
-
254
226
// Process on accept call back
255
227
let transferred = ParaA :: execute_with ( || {
228
+
256
229
let protocol_fees = pallet_xcm_gateway:: Pallet :: < Test > :: protocol_fee_percentage ( ) ;
257
230
let amount = SEND_AMOUNT - ( protocol_fees * SEND_AMOUNT ) ;
258
231
let body = Body {
@@ -284,6 +257,7 @@ fn should_process_on_accept_module_callback_correctly() {
284
257
let initial_total_issuance = <pallet_assets:: Pallet < Test > as Inspect <
285
258
<Test as frame_system:: Config >:: AccountId ,
286
259
> >:: total_issuance ( asset_id. clone ( ) ) ;
260
+ dbg ! ( initial_total_issuance) ;
287
261
ismp_module. on_accept ( post) . unwrap ( ) ;
288
262
289
263
let total_issuance_after = <pallet_assets:: Pallet < Test > as Inspect <
@@ -294,15 +268,16 @@ fn should_process_on_accept_module_callback_correctly() {
294
268
amount
295
269
} ) ;
296
270
297
- Relay :: execute_with ( || {
298
- // Alice's balance on relay chain should have increased by the amount transferred
299
- let current_balance = pallet_balances :: Pallet :: < relay_chain :: Runtime > :: free_balance ( & ALICE ) ;
271
+ ParaB :: execute_with ( || {
272
+ // Alice's balance on asset hub should have increased by the amount transferred
273
+ let current_balance = Assets :: balance ( asset_id , & ALICE ) ;
300
274
assert_eq ! ( current_balance, alice_balance + transferred) ;
301
275
} )
302
276
}
303
277
304
278
#[ test]
305
279
fn should_process_on_timeout_module_callback_correctly ( ) {
280
+ init_tracing ( ) ;
306
281
MockNet :: reset ( ) ;
307
282
308
283
let beneficiary: Location = Junctions :: X3 ( Arc :: new ( [
@@ -316,22 +291,26 @@ fn should_process_on_timeout_module_callback_correctly() {
316
291
. into_location ( ) ;
317
292
let weight_limit = WeightLimit :: Unlimited ;
318
293
319
- let dest: Location = Junction :: Parachain ( PARA_ID ) . into ( ) ;
320
- let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & Location :: parent ( ) . encode ( ) ) . into ( ) ;
294
+ let asset_location = Location :: new ( 1 , Here ) ;
295
+
296
+ let dest = Location :: new ( 1 , [ Parachain ( PARA_ID ) ] ) ;
297
+ let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & asset_location. encode ( ) ) . into ( ) ;
321
298
322
- let alice_balance = Relay :: execute_with ( || {
323
- // call extrinsic
324
- let result = RelayChainPalletXcm :: limited_reserve_transfer_assets (
325
- RuntimeOrigin :: signed ( ALICE ) ,
299
+ let alice_balance = ParaB :: execute_with ( || {
300
+ let result = PalletXcm :: limited_reserve_transfer_assets (
301
+ runtime:: RuntimeOrigin :: signed ( ALICE ) ,
326
302
Box :: new ( dest. clone ( ) . into ( ) ) ,
327
303
Box :: new ( beneficiary. clone ( ) . into ( ) ) ,
328
- Box :: new ( ( Junctions :: Here , SEND_AMOUNT ) . into ( ) ) ,
304
+ Box :: new ( ( asset_location , SEND_AMOUNT ) . into ( ) ) ,
329
305
0 ,
330
306
weight_limit,
331
307
) ;
332
308
assert_ok ! ( result) ;
333
- // return alice's account balance
334
- pallet_balances:: Pallet :: < relay_chain:: Runtime > :: free_balance ( & ALICE )
309
+ let alice_balance = <runtime:: Assets as Inspect <
310
+ <Test as frame_system:: Config >:: AccountId ,
311
+ > >:: balance ( asset_id, & ALICE ) ;
312
+ dbg ! ( alice_balance) ;
313
+ alice_balance
335
314
} ) ;
336
315
337
316
// Parachain should receive xcm
@@ -403,9 +382,9 @@ fn should_process_on_timeout_module_callback_correctly() {
403
382
amount
404
383
} ) ;
405
384
406
- Relay :: execute_with ( || {
385
+ ParaB :: execute_with ( || {
407
386
// Alice's balance on relay chain should have increased by the amount transferred
408
- let current_balance = pallet_balances :: Pallet :: < relay_chain :: Runtime > :: free_balance ( & ALICE ) ;
387
+ let current_balance = Assets :: balance ( asset_id , & ALICE ) ;
409
388
assert_eq ! ( current_balance, alice_balance + transferred) ;
410
389
} )
411
390
}
0 commit comments