@@ -609,7 +609,7 @@ mod tests {
609
609
DispatchClass , DispatchInfo , PostDispatchInfo , GetDispatchInfo , Weight ,
610
610
WeightToFeePolynomial , WeightToFeeCoefficients , WeightToFeeCoefficient ,
611
611
} ,
612
- traits:: Currency ,
612
+ traits:: { Currency , OnUnbalanced , Imbalance } ,
613
613
} ;
614
614
use pallet_balances:: Call as BalancesCall ;
615
615
use sp_core:: H256 ;
@@ -718,8 +718,27 @@ mod tests {
718
718
}
719
719
}
720
720
721
+ thread_local ! {
722
+ static TIP_UNBALANCED_AMOUNT : RefCell <u64 > = RefCell :: new( 0 ) ;
723
+ static FEE_UNBALANCED_AMOUNT : RefCell <u64 > = RefCell :: new( 0 ) ;
724
+ }
725
+
726
+ pub struct DealWithFees ;
727
+ impl OnUnbalanced < pallet_balances:: NegativeImbalance < Runtime > > for DealWithFees {
728
+ fn on_unbalanceds < B > (
729
+ mut fees_then_tips : impl Iterator < Item =pallet_balances:: NegativeImbalance < Runtime > >
730
+ ) {
731
+ if let Some ( fees) = fees_then_tips. next ( ) {
732
+ FEE_UNBALANCED_AMOUNT . with ( |a| * a. borrow_mut ( ) += fees. peek ( ) ) ;
733
+ if let Some ( tips) = fees_then_tips. next ( ) {
734
+ TIP_UNBALANCED_AMOUNT . with ( |a| * a. borrow_mut ( ) += tips. peek ( ) ) ;
735
+ }
736
+ }
737
+ }
738
+ }
739
+
721
740
impl Config for Runtime {
722
- type OnChargeTransaction = CurrencyAdapter < Balances , ( ) > ;
741
+ type OnChargeTransaction = CurrencyAdapter < Balances , DealWithFees > ;
723
742
type TransactionByteFee = TransactionByteFee ;
724
743
type WeightToFee = WeightToFee ;
725
744
type FeeMultiplierUpdate = ( ) ;
@@ -832,6 +851,10 @@ mod tests {
832
851
:: post_dispatch( pre, & info_from_weight( 5 ) , & default_post_info( ) , len, & Ok ( ( ) ) )
833
852
) ;
834
853
assert_eq ! ( Balances :: free_balance( 1 ) , 100 - 5 - 5 - 10 ) ;
854
+ assert_eq ! ( FEE_UNBALANCED_AMOUNT . with( |a| a. borrow( ) . clone( ) ) , 5 + 5 + 10 ) ;
855
+ assert_eq ! ( TIP_UNBALANCED_AMOUNT . with( |a| a. borrow( ) . clone( ) ) , 0 ) ;
856
+
857
+ FEE_UNBALANCED_AMOUNT . with ( |a| * a. borrow_mut ( ) = 0 ) ;
835
858
836
859
let pre = ChargeTransactionPayment :: < Runtime > :: from ( 5 /* tipped */ )
837
860
. pre_dispatch ( & 2 , CALL , & info_from_weight ( 100 ) , len)
@@ -843,6 +866,8 @@ mod tests {
843
866
:: post_dispatch( pre, & info_from_weight( 100 ) , & post_info_from_weight( 50 ) , len, & Ok ( ( ) ) )
844
867
) ;
845
868
assert_eq ! ( Balances :: free_balance( 2 ) , 200 - 5 - 10 - 50 - 5 ) ;
869
+ assert_eq ! ( FEE_UNBALANCED_AMOUNT . with( |a| a. borrow( ) . clone( ) ) , 5 + 10 + 50 ) ;
870
+ assert_eq ! ( TIP_UNBALANCED_AMOUNT . with( |a| a. borrow( ) . clone( ) ) , 5 ) ;
846
871
} ) ;
847
872
}
848
873
0 commit comments