@@ -506,26 +506,27 @@ fn charges_fee_when_validate_with_fee_path_call() {
506506 // Enable dex with Alice, and initialize tx charge fee pool
507507 builder_with_dex_and_fee_pool ( true ) . execute_with ( || {
508508 let dex_acc: AccountId = PalletId ( * b"aca/dexm" ) . into_account ( ) ;
509- let dex_ausd = Currencies :: free_balance ( ACA , & dex_acc) ;
509+ let dex_aca = Currencies :: free_balance ( ACA , & dex_acc) ;
510510
511- let fee: Balance = 50 * 2 + 100 ;
512- let fee_perc = CustomFeeSurplus :: get ( ) ;
513- let surplus = fee_perc. mul_ceil ( fee) ;
514- let fee_surplus = fee + surplus;
511+ let fee: Balance = 50 * 2 + 100 + 10 ;
512+ let fee_surplus = fee + CustomFeeSurplus :: get ( ) . mul_ceil ( fee) ;
513+ assert_eq ! ( 315 , fee_surplus) ;
514+
515+ assert_ok ! ( Currencies :: update_balance( Origin :: root( ) , BOB , AUSD , 10000 ) ) ;
515516
516517 // AUSD - ACA
517518 assert_ok ! ( ChargeTransactionPayment :: <Runtime >:: from( 0 ) . validate(
518- & ALICE ,
519+ & BOB ,
519520 & with_fee_path_call( vec![ AUSD , ACA ] ) ,
520521 & INFO2 ,
521522 50
522523 ) ) ;
523524 System :: assert_has_event ( crate :: mock:: Event :: DEXModule ( module_dex:: Event :: Swap {
524- trader : ALICE ,
525+ trader : BOB ,
525526 path : vec ! [ AUSD , ACA ] ,
526- liquidity_changes : vec ! [ 31 , fee_surplus] , // 31 AUSD - 300 ACA
527+ liquidity_changes : vec ! [ 33 , fee_surplus] , // 33 AUSD - 315 ACA
527528 } ) ) ;
528- assert_eq ! ( dex_ausd - fee_surplus, Currencies :: free_balance( ACA , & dex_acc) ) ;
529+ assert_eq ! ( dex_aca - fee_surplus, Currencies :: free_balance( ACA , & dex_acc) ) ;
529530
530531 // DOT - ACA swap dex is invalid
531532 assert_noop ! (
@@ -539,18 +540,26 @@ fn charges_fee_when_validate_with_fee_path_call() {
539540 ) ;
540541
541542 // DOT - AUSD - ACA
543+ let fee: Balance = 50 * 2 + 100 ;
544+ let fee_surplus2 = fee + CustomFeeSurplus :: get ( ) . mul_ceil ( fee) ;
545+ assert_eq ! ( 300 , fee_surplus2) ;
546+
547+ assert_ok ! ( Currencies :: update_balance( Origin :: root( ) , BOB , DOT , 10000 ) ) ;
542548 assert_ok ! ( ChargeTransactionPayment :: <Runtime >:: from( 0 ) . validate(
543- & ALICE ,
549+ & BOB ,
544550 & with_fee_path_call( vec![ DOT , AUSD , ACA ] ) ,
545551 & INFO2 ,
546552 50
547553 ) ) ;
548554 System :: assert_has_event ( crate :: mock:: Event :: DEXModule ( module_dex:: Event :: Swap {
549- trader : ALICE ,
555+ trader : BOB ,
550556 path : vec ! [ DOT , AUSD , ACA ] ,
551- liquidity_changes : vec ! [ 4 , 33 , fee_surplus ] , // 4 DOT - 33 AUSD - 300 ACA
557+ liquidity_changes : vec ! [ 4 , 34 , fee_surplus2 ] , // 4 DOT - 34 AUSD - 300 ACA
552558 } ) ) ;
553- assert_eq ! ( dex_ausd - fee_surplus * 2 , Currencies :: free_balance( ACA , & dex_acc) ) ;
559+ assert_eq ! (
560+ dex_aca - fee_surplus - fee_surplus2,
561+ Currencies :: free_balance( ACA , & dex_acc)
562+ ) ;
554563 } ) ;
555564}
556565
@@ -565,28 +574,48 @@ fn charges_fee_when_validate_with_fee_currency_call() {
565574 let sub_dot_aca = Currencies :: free_balance ( ACA , & dot_acc) ;
566575 let sub_dot_dot = Currencies :: free_balance ( DOT , & dot_acc) ;
567576
568- let fee: Balance = 50 * 2 + 100 ;
577+ let fee: Balance = 50 * 2 + 100 + 10 ;
569578 let fee_perc = AlternativeFeeSurplus :: get ( ) ;
570- let surplus = fee_perc. mul_ceil ( fee) ;
571- let fee_amount = fee + surplus;
579+ let surplus = fee_perc. mul_ceil ( fee) ; // 53
580+ let fee_amount = fee + surplus; // 263
572581
582+ assert_ok ! ( Currencies :: update_balance( Origin :: root( ) , BOB , AUSD , 10000 ) ) ;
583+ assert_eq ! ( 0 , Currencies :: free_balance( ACA , & BOB ) ) ;
573584 assert_ok ! ( ChargeTransactionPayment :: <Runtime >:: from( 0 ) . validate(
574- & ALICE ,
585+ & BOB ,
575586 & with_fee_currency_call( AUSD ) ,
576587 & INFO2 ,
577588 50
578589 ) ) ;
590+ assert_eq ! ( 10 , Currencies :: free_balance( ACA , & BOB ) ) ; // ED
591+ assert_eq ! ( 7370 , Currencies :: free_balance( AUSD , & BOB ) ) ;
592+ System :: assert_has_event ( crate :: mock:: Event :: Tokens ( orml_tokens:: Event :: Transfer {
593+ currency_id : AUSD ,
594+ from : BOB ,
595+ to : ausd_acc. clone ( ) ,
596+ amount : 2630 ,
597+ } ) ) ;
598+ System :: assert_has_event ( crate :: mock:: Event :: PalletBalances ( pallet_balances:: Event :: Transfer {
599+ from : ausd_acc. clone ( ) ,
600+ to : BOB ,
601+ amount : 263 ,
602+ } ) ) ;
603+
579604 assert_eq ! ( sub_ausd_aca - fee_amount, Currencies :: free_balance( ACA , & ausd_acc) ) ;
580605 assert_eq ! (
581606 sub_ausd_usd + fee_amount * 10 ,
582607 Currencies :: free_balance( AUSD , & ausd_acc)
583608 ) ;
584609
610+ let fee: Balance = 50 * 2 + 100 ;
585611 let fee_perc = CustomFeeSurplus :: get ( ) ;
586612 let surplus = fee_perc. mul_ceil ( fee) ;
587613 let fee_amount = fee + surplus;
614+
615+ assert_ok ! ( Currencies :: update_balance( Origin :: root( ) , BOB , DOT , 10000 ) ) ;
616+ assert_eq ! ( 10 , Currencies :: free_balance( ACA , & BOB ) ) ;
588617 assert_ok ! ( ChargeTransactionPayment :: <Runtime >:: from( 0 ) . validate(
589- & ALICE ,
618+ & BOB ,
590619 & with_fee_currency_call( DOT ) ,
591620 & INFO2 ,
592621 50
0 commit comments