11#[test_only]
22module oft ::oft_impl_config_tests {
3- use std::account::create_account_for_test;
3+ use std::account::{ create_account_for_test, create_signer_for_test} ;
44 use std::event::was_event_emitted;
55 use std::string::utf8;
6+ use std::timestamp;
67 use std::vector;
78
89 use oft::oapp_store;
@@ -12,6 +13,7 @@ module oft::oft_impl_config_tests {
1213 assert_not_blocklisted,
1314 blocked_amount_redirected_event,
1415 blocklisting_disabled_event,
16+ checkpoint_rate_limit_in_flight,
1517 debit_view_with_possible_fee,
1618 fee_bps,
1719 fee_details_with_possible_fee,
@@ -279,6 +281,7 @@ module oft::oft_impl_config_tests {
279281 #[test]
280282 fun test_set_rate_limit_net () {
281283 setup ();
284+ timestamp::set_time_has_started_for_testing (&create_signer_for_test (@std ));
282285
283286 // No rate limit configured
284287 assert ! (has_rate_limit (30100 ) == false , 2 );
@@ -300,7 +303,10 @@ module oft::oft_impl_config_tests {
300303 assert ! (in_flight_at_time (30100 , 500 ) == 10000 , 1 );
301304 assert ! (rate_limit_capacity_at_time (30100 , 500 ) == 10000 , 2 );
302305
303- // release most of remaining capacity
306+ // Release most of remaining capacity
307+ // release_rate_limit_capacity will checkpoint at now_seconds() (which is 0 after initialization)
308+ // At time 0: in_flight = 20000, so after release of 9000: in_flight_on_last_update = 11000, last_update = 0
309+ // At time 500: in_flight = 11000 - (500 * 20000 / 1000) = 11000 - 10000 = 1000
304310 release_rate_limit_capacity (30100 , 9000 );
305311 assert ! (in_flight_at_time (30100 , 500 ) == 1000 , 1 );
306312 assert ! (rate_limit_capacity_at_time (30100 , 500 ) == 19000 , 2 );
@@ -310,7 +316,9 @@ module oft::oft_impl_config_tests {
310316 assert ! (in_flight_at_time (30100 , 500 ) == 20000 , 1 );
311317 assert ! (rate_limit_capacity_at_time (30100 , 500 ) == 0 , 2 );
312318
313- // release excess capacity (5x limit) - should not overshoot
319+ // Release excess capacity (5x limit) - should not overshoot
320+ // First checkpoint at 500 to get correct state, then release will checkpoint at now_seconds()
321+ checkpoint_rate_limit_in_flight (30100 , 500 );
314322 release_rate_limit_capacity (30100 , 100_000 );
315323 assert ! (in_flight_at_time (30100 , 500 ) == 0 , 1 );
316324 assert ! (rate_limit_capacity_at_time (30100 , 500 ) == 20000 , 2 );
0 commit comments