@@ -2625,6 +2625,111 @@ fn pox_4_check_cycle_id_range_in_print_events_in_prepare_phase() {
2625
2625
) ;
2626
2626
}
2627
2627
2628
+ // test that delegate-stack-increase calls emit and event
2629
+ #[ test]
2630
+ fn pox_4_delegate_stack_increase_events ( ) {
2631
+ // Config for this test
2632
+ let ( epochs, pox_constants) = make_test_epochs_pox ( ) ;
2633
+
2634
+ let mut burnchain = Burnchain :: default_unittest (
2635
+ 0 ,
2636
+ & BurnchainHeaderHash :: from_hex ( BITCOIN_REGTEST_FIRST_BLOCK_HASH ) . unwrap ( ) ,
2637
+ ) ;
2638
+ burnchain. pox_constants = pox_constants. clone ( ) ;
2639
+
2640
+ let observer = TestEventObserver :: new ( ) ;
2641
+
2642
+ let ( mut peer, mut keys) = instantiate_pox_peer_with_epoch (
2643
+ & burnchain,
2644
+ function_name ! ( ) ,
2645
+ Some ( epochs. clone ( ) ) ,
2646
+ Some ( & observer) ,
2647
+ ) ;
2648
+
2649
+ assert_eq ! ( burnchain. pox_constants. reward_slots( ) , 6 ) ;
2650
+ let mut coinbase_nonce = 0 ;
2651
+ let mut latest_block = None ;
2652
+
2653
+ let alice_key = keys. pop ( ) . unwrap ( ) ;
2654
+ let alice_address = key_to_stacks_addr ( & alice_key) ;
2655
+ let alice_principal = PrincipalData :: from ( alice_address. clone ( ) ) ;
2656
+ let alice_pox_addr = pox_addr_from ( & alice_key) ;
2657
+
2658
+ let bob_key = keys. pop ( ) . unwrap ( ) ;
2659
+ let bob_address = key_to_stacks_addr ( & bob_key) ;
2660
+ let bob_principal = PrincipalData :: from ( bob_address. clone ( ) ) ;
2661
+ let bob_pox_addr = pox_addr_from ( & bob_key) ;
2662
+ let bob_pox_addr_val = Value :: Tuple ( bob_pox_addr. as_clarity_tuple ( ) . unwrap ( ) ) ;
2663
+
2664
+ // Advance into pox4
2665
+ let target_height = burnchain. pox_constants . pox_4_activation_height ;
2666
+ // produce blocks until the first reward phase that everyone should be in
2667
+ while get_tip ( peer. sortdb . as_ref ( ) ) . block_height < u64:: from ( target_height) {
2668
+ latest_block = Some ( peer. tenure_with_txs ( & [ ] , & mut coinbase_nonce) ) ;
2669
+ }
2670
+
2671
+ // alice delegate to bob
2672
+ let next_cycle = get_current_reward_cycle ( & peer, & burnchain) + 1 ;
2673
+ let amount = 100_000_000 ;
2674
+ let alice_delegate =
2675
+ make_pox_4_delegate_stx ( & alice_key, 0 , amount, bob_principal. clone ( ) , None , None ) ;
2676
+
2677
+ // bob delegate-stack-stx
2678
+ let bob_delegate_stack_stx = make_pox_4_delegate_stack_stx (
2679
+ & bob_key,
2680
+ 0 ,
2681
+ alice_principal. clone ( ) ,
2682
+ amount / 2 ,
2683
+ bob_pox_addr. clone ( ) ,
2684
+ get_tip ( peer. sortdb . as_ref ( ) ) . block_height as u128 ,
2685
+ 2 ,
2686
+ ) ;
2687
+
2688
+ // bob delegate-stack-increase
2689
+ let bob_delegate_stack_increase = make_pox_4_delegate_stack_increase (
2690
+ & bob_key,
2691
+ 1 ,
2692
+ & alice_principal,
2693
+ bob_pox_addr. clone ( ) ,
2694
+ amount / 2 ,
2695
+ ) ;
2696
+
2697
+ latest_block = Some ( peer. tenure_with_txs (
2698
+ & [
2699
+ alice_delegate. clone ( ) ,
2700
+ bob_delegate_stack_stx. clone ( ) ,
2701
+ bob_delegate_stack_increase. clone ( ) ,
2702
+ ] ,
2703
+ & mut coinbase_nonce,
2704
+ ) ) ;
2705
+
2706
+ let txs: HashMap < _ , _ > = observer
2707
+ . get_blocks ( )
2708
+ . into_iter ( )
2709
+ . flat_map ( |b| b. receipts )
2710
+ . filter_map ( |r| match r. transaction {
2711
+ TransactionOrigin :: Stacks ( ref t) => Some ( ( t. txid ( ) , r. clone ( ) ) ) ,
2712
+ _ => None ,
2713
+ } )
2714
+ . collect ( ) ;
2715
+
2716
+ let bob_delegate_stack_increase_tx = txs
2717
+ . get ( & bob_delegate_stack_increase. txid ( ) )
2718
+ . unwrap ( )
2719
+ . clone ( ) ;
2720
+
2721
+ // Check event for delegate-stack-increase tx
2722
+ let bob_delegate_stack_increase_tx_events = & bob_delegate_stack_increase_tx. events ;
2723
+ assert_eq ! ( bob_delegate_stack_increase_tx_events. len( ) as u64 , 2 ) ;
2724
+ let bob_delegate_stack_increase_op_data = HashMap :: from ( [
2725
+ ( "start-cycle-id" , Value :: UInt ( next_cycle) ) ,
2726
+ ( "end-cycle-id" , Optional ( OptionalData { data : None } ) ) ,
2727
+ ( "increase-by" , Value :: UInt ( amount / 2 ) ) ,
2728
+ ( "pox-addr" , bob_pox_addr_val. clone ( ) ) ,
2729
+ ( "delegator" , alice_principal. clone ( ) . into ( ) ) ,
2730
+ ] ) ;
2731
+ }
2732
+
2628
2733
// test that revoke-delegate-stx calls emit an event and
2629
2734
// test that revoke-delegate-stx is only successfull if user has delegated.
2630
2735
#[ test]
0 commit comments