@@ -3413,7 +3413,7 @@ fn test_coinbase_alpha_in_more_than_alpha_emission() {
34133413 } ) ;
34143414}
34153415
3416- // Tests for the excess TAO condition
3416+ // Tests for the inject and swap are in the right order.
34173417#[ test]
34183418fn test_coinbase_inject_and_maybe_swap_does_not_skew_reserves ( ) {
34193419 new_test_ext ( 1 ) . execute_with ( || {
@@ -3452,3 +3452,90 @@ fn test_coinbase_inject_and_maybe_swap_does_not_skew_reserves() {
34523452 ) ;
34533453 } ) ;
34543454}
3455+
3456+ #[ test]
3457+ fn test_coinbase_drain_pending_increments_blockssincelaststep ( ) {
3458+ new_test_ext ( 1 ) . execute_with ( || {
3459+ let zero = U96F32 :: saturating_from_num ( 0 ) ;
3460+ let netuid0 = add_dynamic_network ( & U256 :: from ( 1 ) , & U256 :: from ( 2 ) ) ;
3461+
3462+ let blocks_since_last_step_before = BlocksSinceLastStep :: < Test > :: get ( netuid0) ;
3463+
3464+ // Check that blockssincelaststep is incremented
3465+ SubtensorModule :: drain_pending ( & [ netuid0] , 1 ) ;
3466+
3467+ let blocks_since_last_step_after = BlocksSinceLastStep :: < Test > :: get ( netuid0) ;
3468+ assert ! ( blocks_since_last_step_after > blocks_since_last_step_before) ;
3469+ assert_eq ! (
3470+ blocks_since_last_step_after,
3471+ blocks_since_last_step_before + 1
3472+ ) ;
3473+ } ) ;
3474+ }
3475+
3476+ #[ test]
3477+ fn test_coinbase_drain_pending_resets_blockssincelaststep ( ) {
3478+ new_test_ext ( 1 ) . execute_with ( || {
3479+ let zero = U96F32 :: saturating_from_num ( 0 ) ;
3480+ let netuid0 = add_dynamic_network ( & U256 :: from ( 1 ) , & U256 :: from ( 2 ) ) ;
3481+ Tempo :: < Test > :: insert ( netuid0, 100 ) ;
3482+ // Ensure the block number we use is the tempo block
3483+ let block_number = 98 ;
3484+ assert ! ( SubtensorModule :: should_run_epoch( netuid0, block_number) ) ;
3485+
3486+ let blocks_since_last_step_before = 12345678 ;
3487+ BlocksSinceLastStep :: < Test > :: insert ( netuid0, blocks_since_last_step_before) ;
3488+ LastMechansimStepBlock :: < Test > :: insert ( netuid0, 12345 ) ; // garbage value
3489+
3490+ // Check that blockssincelaststep is reset to 0 on tempo
3491+ SubtensorModule :: drain_pending ( & [ netuid0] , block_number) ;
3492+
3493+ let blocks_since_last_step_after = BlocksSinceLastStep :: < Test > :: get ( netuid0) ;
3494+ assert_eq ! ( blocks_since_last_step_after, 0 ) ;
3495+ // Also check LastMechansimStepBlock is set to the block number we ran on
3496+ assert_eq ! ( LastMechansimStepBlock :: <Test >:: get( netuid0) , block_number) ;
3497+ } ) ;
3498+ }
3499+
3500+ #[ test]
3501+ fn test_coinbase_drain_pending_gets_counters_and_resets_them ( ) {
3502+ new_test_ext ( 1 ) . execute_with ( || {
3503+ let zero = U96F32 :: saturating_from_num ( 0 ) ;
3504+ let netuid0 = add_dynamic_network ( & U256 :: from ( 1 ) , & U256 :: from ( 2 ) ) ;
3505+ Tempo :: < Test > :: insert ( netuid0, 100 ) ;
3506+ // Ensure the block number we use is the tempo block
3507+ let block_number = 98 ;
3508+ assert ! ( SubtensorModule :: should_run_epoch( netuid0, block_number) ) ;
3509+
3510+ mock:: setup_reserves (
3511+ netuid0,
3512+ TaoCurrency :: from ( 1_000_000_000_000_000 ) ,
3513+ AlphaCurrency :: from ( 1_000_000_000_000_000 ) ,
3514+ ) ;
3515+ // Initialize swap v3
3516+ Swap :: maybe_initialize_v3 ( netuid0) ;
3517+
3518+ let pending_em = AlphaCurrency :: from ( 123434534 ) ;
3519+ let pending_root = AlphaCurrency :: from ( 12222222 ) ;
3520+ let pending_owner_cut = AlphaCurrency :: from ( 12345678 ) ;
3521+
3522+ PendingEmission :: < Test > :: insert ( netuid0, pending_em) ;
3523+ PendingRootAlphaDivs :: < Test > :: insert ( netuid0, pending_root) ;
3524+ PendingOwnerCut :: < Test > :: insert ( netuid0, pending_owner_cut) ;
3525+
3526+ let emissions_to_distribute = SubtensorModule :: drain_pending ( & [ netuid0] , block_number) ;
3527+ assert_eq ! ( emissions_to_distribute. len( ) , 1 ) ;
3528+ assert_eq ! (
3529+ emissions_to_distribute[ & netuid0] ,
3530+ ( pending_em, pending_root, pending_owner_cut)
3531+ ) ;
3532+
3533+ // Check that the pending emissions are reset
3534+ assert_eq ! ( PendingEmission :: <Test >:: get( netuid0) , AlphaCurrency :: ZERO ) ;
3535+ assert_eq ! (
3536+ PendingRootAlphaDivs :: <Test >:: get( netuid0) ,
3537+ AlphaCurrency :: ZERO
3538+ ) ;
3539+ assert_eq ! ( PendingOwnerCut :: <Test >:: get( netuid0) , AlphaCurrency :: ZERO ) ;
3540+ } ) ;
3541+ }
0 commit comments