@@ -37,38 +37,125 @@ use xcm_simulator::TestExt;
37
37
use crate :: runtime:: ReputationAssetId ;
38
38
39
39
const SEND_AMOUNT : u128 = 1000_000_000_0000 ;
40
- const PARA_ID : u32 = 100 ;
40
+ const PARA_ID : u32 = crate :: xcm :: SIBLING_PARA_ID ;
41
41
pub type RelayChainPalletXcm = pallet_xcm:: Pallet < relay_chain:: Runtime > ;
42
42
43
43
fn reserve_transfer_on_AH ( amount : u128 , beneficiary : Location ) {
44
44
let asset_location_on_assethub = Location :: new ( 1 , Here ) ;
45
45
46
- let dest = Location :: new ( 1 , [ Parachain ( 100 ) ] ) ;
46
+ //let asset_location_on_assethub_h256: H256 = sp_io::hashing::keccak_256(&asset_location_on_assethub.encode()).into();
47
+
48
+ let asset_id_on_paraa: H256 =
49
+ sp_io:: hashing:: keccak_256 ( & Location :: new ( 1 , Here ) . encode ( ) )
50
+ . into ( ) ;
51
+
52
+
53
+ ParaA :: execute_with ( || {
54
+ /*assert_ok!(runtime::Assets::force_create(
55
+ runtime::RuntimeOrigin::root(),
56
+ asset_id_on_paraa.into(),
57
+ ALICE.into(),
58
+ true,
59
+ 1
60
+ ));*/
61
+ } ) ;
62
+
63
+
64
+ ParaB :: execute_with ( || {
65
+ let dest = Location :: new ( 1 , [ Parachain ( PARA_ID ) ] ) ;
66
+ let beneficiary: Location = Junctions :: X3 ( Arc :: new ( [
67
+ Junction :: AccountId32 { network : None , id : ALICE . into ( ) } ,
68
+ Junction :: AccountKey20 {
69
+ network : Some ( NetworkId :: Ethereum { chain_id : 97 } ) ,
70
+ key : [ 1u8 ; 20 ] ,
71
+ } ,
72
+ Junction :: GeneralIndex ( 60 * 60 ) ,
73
+ ] ) )
74
+ . into_location ( ) ;
75
+
76
+ let context = Junctions :: X2 ( Arc :: new ( [
77
+ Junction :: GlobalConsensus ( NetworkId :: Polkadot ) ,
78
+ Parachain ( 1000 ) ,
79
+ ] ) ) ;
47
80
48
81
let assets = Asset {
49
82
id : AssetId ( asset_location_on_assethub. clone ( ) ) ,
50
83
fun : Fungibility :: Fungible ( amount) ,
51
84
} ;
52
85
53
- let remote_xcm = Xcm ( vec ! [
54
- BuyExecution { fees: assets. clone( ) , weight_limit: WeightLimit :: Unlimited } ,
55
- DepositAsset { assets: Wild ( All ) , beneficiary } ,
56
- ] ) ;
86
+ let fee_asset = assets. clone ( ) . reanchored ( & dest, & context) . expect ( "should reanchor" ) ;
87
+ let fees = fee_asset. clone ( ) ;
88
+
89
+ // let xcm = Xcm(vec![
90
+ // BuyExecution { fees, weight_limit: WeightLimit::Unlimited },
91
+ // DepositAsset {
92
+ // assets: Wild(All),
93
+ // beneficiary,
94
+ // },
95
+ // ]);
96
+
97
+ // let message = Xcm(vec![
98
+ // SetFeesMode { jit_withdraw: true },
99
+ // TransferReserveAsset {
100
+ // assets: assets.into(),
101
+ // dest,
102
+ // xcm,
103
+ // },
104
+ // ]);
105
+
106
+ // assert_ok!(runtime::PalletXcm::execute(
107
+ // runtime::RuntimeOrigin::signed(ALICE.into()),
108
+ // Box::new(VersionedXcm::from(message)),
109
+ // Weight::MAX
110
+ // ));
111
+
112
+ assert_ok ! ( runtime:: PalletXcm :: limited_reserve_transfer_assets(
113
+ runtime:: RuntimeOrigin :: signed( ALICE . into( ) ) ,
114
+ Box :: new( dest. into( ) ) ,
115
+ Box :: new( beneficiary. into( ) ) ,
116
+ Box :: new( vec![ ( asset_location_on_assethub, SEND_AMOUNT ) . into( ) ] . into( ) ) ,
117
+ 0 ,
118
+ WeightLimit :: Unlimited ,
119
+ ) ) ;
120
+ } ) ;
121
+
122
+
123
+ ParaA :: execute_with ( || {
124
+
125
+ let bobs_balance = <runtime:: Assets as Inspect <
126
+ <Test as frame_system:: Config >:: AccountId ,
127
+ > >:: balance (
128
+ asset_id_on_paraa,
129
+ & BOB ,
130
+ ) ;
131
+ dbg ! ( bobs_balance) ;
132
+
133
+ let parachain_account: ParaId = PARA_ID . into ( ) ;
134
+ let parachain_account = parachain_account. into_account_truncating ( ) ;
135
+
136
+ let alice_balance = <runtime:: Assets as Inspect <
137
+ <Test as frame_system:: Config >:: AccountId ,
138
+ > >:: balance (
139
+ asset_id_on_paraa,
140
+ & parachain_account,
141
+ ) ;
142
+ dbg ! ( alice_balance) ;
143
+ let nonce = pallet_ismp:: Nonce :: < Test > :: get ( ) ;
144
+ assert_eq ! ( nonce, 1 ) ;
145
+
146
+ let protocol_fees = pallet_xcm_gateway:: Pallet :: < Test > :: protocol_fee_percentage ( ) ;
147
+ let custodied_amount = SEND_AMOUNT - ( protocol_fees * SEND_AMOUNT ) ;
148
+
149
+ let pallet_account_balance = <runtime:: Assets as Inspect <
150
+ <Test as frame_system:: Config >:: AccountId ,
151
+ > >:: balance (
152
+ asset_id_on_paraa. into ( ) ,
153
+ & pallet_xcm_gateway:: Pallet :: < Test > :: account_id ( ) ,
154
+ ) ;
155
+ assert_eq ! ( custodied_amount, pallet_account_balance) ;
156
+ } ) ;
57
157
58
- let message = Xcm ( vec ! [
59
- SetFeesMode { jit_withdraw: true } ,
60
- TransferReserveAsset { assets: assets. into( ) , dest, xcm: remote_xcm } ,
61
- ] ) ;
62
-
63
- ParaB :: execute_with ( || {
64
- assert_ok ! ( runtime:: PalletXcm :: execute(
65
- runtime:: RuntimeOrigin :: signed( ALICE . into( ) ) ,
66
- Box :: new( VersionedXcm :: from( message) ) ,
67
- Weight :: MAX
68
- ) ) ;
69
- } ) ;
70
158
}
71
-
72
159
#[ test]
73
160
fn should_dispatch_ismp_request_when_assets_are_received_from_assethub ( ) {
74
161
init_tracing ( ) ;
0 commit comments