@@ -22,10 +22,8 @@ use pallet_xcm_gateway::Module;
2222use polkadot_sdk:: {
2323 sp_runtime:: traits:: AccountIdConversion ,
2424 xcm_simulator:: {
25- All , AllCounted , Asset , AssetFilter , AssetId , BuyExecution , DepositAsset , Fungibility ,
26- GeneralIndex , Here , InitiateTransfer , PalletInstance , ParaId , Parachain , Parent ,
27- Reanchorable , SetFeesMode , TransferAsset , TransferReserveAsset , VersionedXcm , Weight , Wild ,
28- Xcm ,
25+ All , Asset , AssetId , BuyExecution , DepositAsset , Fungibility , Here , ParaId , Parachain ,
26+ SetFeesMode , TransferReserveAsset , VersionedXcm , Weight , Wild , Xcm ,
2927 } ,
3028} ;
3129use sp_core:: { ByteArray , H160 , H256 } ;
@@ -46,7 +44,6 @@ fn reserve_transfer_on_ah() {
4644 Junction :: GeneralIndex ( 1 ) ,
4745 ] ) )
4846 . into_location ( ) ;
49- let weight_limit = WeightLimit :: Unlimited ;
5047
5148 let asset_location_on_assethub = Location :: new ( 1 , Here ) ;
5249
@@ -83,8 +80,6 @@ fn should_dispatch_ismp_request_when_assets_are_received_from_assethub() {
8380 let asset_id_on_paraa: H256 =
8481 sp_io:: hashing:: keccak_256 ( & Location :: new ( 1 , Here ) . encode ( ) ) . into ( ) ;
8582
86- let asset_location_on_assethub = Location :: new ( 1 , Here ) ;
87-
8883 reserve_transfer_on_ah ( ) ;
8984
9085 ParaA :: execute_with ( || {
@@ -119,18 +114,6 @@ fn should_dispatch_ismp_request_when_assets_are_received_from_assethub() {
119114fn should_process_on_accept_module_callback_correctly ( ) {
120115 MockNet :: reset ( ) ;
121116
122- let beneficiary: Location = Junctions :: X4 ( Arc :: new ( [
123- Junction :: AccountId32 { network : None , id : ALICE . into ( ) } ,
124- Junction :: AccountKey20 {
125- network : Some ( NetworkId :: Ethereum { chain_id : 97 } ) ,
126- key : [ 1u8 ; 20 ] ,
127- } ,
128- Junction :: GeneralIndex ( 60 * 60 ) ,
129- Junction :: GeneralIndex ( 1 ) ,
130- ] ) )
131- . into_location ( ) ;
132- let weight_limit = WeightLimit :: Unlimited ;
133-
134117 let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & Location :: new ( 1 , Here ) . encode ( ) ) . into ( ) ;
135118
136119 reserve_transfer_on_ah ( ) ;
@@ -224,18 +207,6 @@ fn should_process_on_timeout_module_callback_correctly() {
224207
225208 let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & Location :: new ( 1 , Here ) . encode ( ) ) . into ( ) ;
226209
227- let beneficiary: Location = Junctions :: X4 ( Arc :: new ( [
228- Junction :: AccountId32 { network : None , id : ALICE . into ( ) } ,
229- Junction :: AccountKey20 {
230- network : Some ( NetworkId :: Ethereum { chain_id : 97 } ) ,
231- key : [ 0u8 ; 20 ] ,
232- } ,
233- Junction :: GeneralIndex ( 60 * 60 ) ,
234- Junction :: GeneralIndex ( 1 ) ,
235- ] ) )
236- . into_location ( ) ;
237- let weight_limit = WeightLimit :: Unlimited ;
238-
239210 reserve_transfer_on_ah ( ) ;
240211
241212 let alice_balance = ParaB :: execute_with ( || {
@@ -321,3 +292,41 @@ fn should_process_on_timeout_module_callback_correctly() {
321292 assert_eq ! ( current_balance, alice_balance + transferred) ;
322293 } )
323294}
295+
296+ #[ test]
297+ fn should_withdraw_protocol_fees_successfully ( ) {
298+ MockNet :: reset ( ) ;
299+
300+ let asset_id: H256 = sp_io:: hashing:: keccak_256 ( & Location :: new ( 1 , Here ) . encode ( ) ) . into ( ) ;
301+
302+ // First, trigger a reserve transfer to accumulate protocol fees
303+ reserve_transfer_on_ah ( ) ;
304+
305+ ParaA :: execute_with ( || {
306+ let protocol_account = pallet_xcm_gateway:: Pallet :: < Test > :: protocol_account_id ( ) ;
307+
308+ // Verify protocol fees have accumulated
309+ let protocol_balance_before = <runtime:: Assets as Inspect <
310+ <Test as frame_system:: Config >:: AccountId ,
311+ > >:: balance ( asset_id, & protocol_account) ;
312+
313+ let protocol_fee_percentage = pallet_xcm_gateway:: Pallet :: < Test > :: protocol_fee_percentage ( ) ;
314+ let expected_protocol_fees = protocol_fee_percentage * SEND_AMOUNT ;
315+
316+ assert_eq ! ( protocol_balance_before, expected_protocol_fees) ;
317+ assert ! ( protocol_balance_before > 0 , "Protocol fees should have accumulated" ) ;
318+
319+ // Withdraw protocol fees to BOB as beneficiary
320+ assert_ok ! ( pallet_xcm_gateway:: Pallet :: <Test >:: withdraw_protocol_fees(
321+ frame_system:: RawOrigin :: Root . into( ) ,
322+ BOB
323+ ) ) ;
324+
325+ // Verify protocol account balance is now zero (all fees withdrawn)
326+ let protocol_balance_after = <runtime:: Assets as Inspect <
327+ <Test as frame_system:: Config >:: AccountId ,
328+ > >:: balance ( asset_id, & protocol_account) ;
329+
330+ assert_eq ! ( protocol_balance_after, 0 , "Protocol account should be empty after withdrawal" ) ;
331+ } ) ;
332+ }
0 commit comments