@@ -161,11 +161,11 @@ impl SenderFeeTracker {
161161 }
162162
163163 pub fn get_total_fee ( & self ) -> u128 {
164- self . total_fee
164+ self . total_fee - self . fees_requesting
165165 }
166166
167167 pub fn get_total_fee_outside_buffer ( & mut self ) -> u128 {
168- self . total_fee - self . get_buffer_fee ( ) . min ( self . total_fee )
168+ self . get_total_fee ( ) - self . get_buffer_fee ( ) . min ( self . total_fee )
169169 }
170170
171171 pub fn get_buffer_fee ( & mut self ) -> u128 {
@@ -371,4 +371,35 @@ mod tests {
371371 assert_eq ! ( tracker. get_heaviest_allocation_id( ) , Some ( allocation_id_1) ) ;
372372 assert_eq ! ( tracker. get_total_fee( ) , 30 ) ;
373373 }
374+
375+ #[ test]
376+ fn test_ongoing_rav_requests ( ) {
377+ let allocation_id_0 = address ! ( "abababababababababababababababababababab" ) ;
378+ let allocation_id_1 = address ! ( "bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc" ) ;
379+ let allocation_id_2 = address ! ( "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" ) ;
380+
381+ let mut tracker = SenderFeeTracker :: default ( ) ;
382+ assert_eq ! ( tracker. get_heaviest_allocation_id( ) , None ) ;
383+ assert_eq ! ( tracker. get_total_fee_outside_buffer( ) , 0 ) ;
384+ assert_eq ! ( tracker. get_total_fee( ) , 0 ) ;
385+
386+ tracker. add ( allocation_id_0, 10 ) ;
387+ tracker. add ( allocation_id_1, 20 ) ;
388+ tracker. add ( allocation_id_2, 30 ) ;
389+ assert_eq ! ( tracker. get_heaviest_allocation_id( ) , Some ( allocation_id_2) ) ;
390+ assert_eq ! ( tracker. get_total_fee( ) , 60 ) ;
391+ assert_eq ! ( tracker. get_total_fee_outside_buffer( ) , 60 ) ;
392+
393+ tracker. start_rav_request ( allocation_id_2) ;
394+
395+ assert_eq ! ( tracker. get_heaviest_allocation_id( ) , Some ( allocation_id_1) ) ;
396+ assert_eq ! ( tracker. get_total_fee( ) , 30 ) ;
397+ assert_eq ! ( tracker. get_total_fee_outside_buffer( ) , 30 ) ;
398+
399+ tracker. finish_rav_request ( allocation_id_2) ;
400+
401+ assert_eq ! ( tracker. get_heaviest_allocation_id( ) , Some ( allocation_id_2) ) ;
402+ assert_eq ! ( tracker. get_total_fee( ) , 60 ) ;
403+ assert_eq ! ( tracker. get_total_fee_outside_buffer( ) , 60 ) ;
404+ }
374405}
0 commit comments