@@ -538,6 +538,36 @@ impl<'a> TestPeer<'a> {
538
538
miner_setup : F ,
539
539
after_block : G ,
540
540
) -> NakamotoBlock
541
+ where
542
+ F : FnMut ( & mut NakamotoBlockBuilder ) ,
543
+ G : FnMut ( & mut NakamotoBlock ) -> bool ,
544
+ {
545
+ let nakamoto_tip = {
546
+ let chainstate = & mut self . stacks_node . as_mut ( ) . unwrap ( ) . chainstate ;
547
+ let sort_db = self . sortdb . as_mut ( ) . unwrap ( ) ;
548
+ NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , sort_db)
549
+ . unwrap ( )
550
+ . unwrap ( )
551
+ } ;
552
+ self . mine_single_block_tenure_at_tip (
553
+ & nakamoto_tip. index_block_hash ( ) ,
554
+ sender_key,
555
+ tenure_change_tx,
556
+ coinbase_tx,
557
+ miner_setup,
558
+ after_block,
559
+ )
560
+ }
561
+
562
+ pub fn mine_single_block_tenure_at_tip < F , G > (
563
+ & mut self ,
564
+ nakamoto_tip : & StacksBlockId ,
565
+ sender_key : & StacksPrivateKey ,
566
+ tenure_change_tx : & StacksTransaction ,
567
+ coinbase_tx : & StacksTransaction ,
568
+ miner_setup : F ,
569
+ after_block : G ,
570
+ ) -> NakamotoBlock
541
571
where
542
572
F : FnMut ( & mut NakamotoBlockBuilder ) ,
543
573
G : FnMut ( & mut NakamotoBlock ) -> bool ,
@@ -547,6 +577,8 @@ impl<'a> TestPeer<'a> {
547
577
let recipient_addr =
548
578
StacksAddress :: from_string ( "ST2YM3J4KQK09V670TD6ZZ1XYNYCNGCWCVTASN5VM" ) . unwrap ( ) ;
549
579
580
+ let sender_acct = self . get_account ( nakamoto_tip, & sender_addr. to_account_principal ( ) ) ;
581
+
550
582
// do a stx transfer in each block to a given recipient
551
583
let mut blocks_and_sizes = self . make_nakamoto_tenure_and (
552
584
tenure_change_tx. clone ( ) ,
@@ -555,12 +587,11 @@ impl<'a> TestPeer<'a> {
555
587
miner_setup,
556
588
|_miner, chainstate, sortdb, blocks_so_far| {
557
589
if blocks_so_far. len ( ) < 1 {
558
- let account = get_account ( chainstate, sortdb, & sender_addr) ;
559
590
let stx_transfer = make_token_transfer (
560
591
chainstate,
561
592
sortdb,
562
593
& sender_key,
563
- account . nonce ,
594
+ sender_acct . nonce ,
564
595
100 ,
565
596
1 ,
566
597
& recipient_addr,
@@ -607,12 +638,33 @@ impl<'a> TestPeer<'a> {
607
638
tenure_change. tenure_consensus_hash = consensus_hash. clone ( ) ;
608
639
tenure_change. burn_view_consensus_hash = consensus_hash. clone ( ) ;
609
640
641
+ let nakamoto_tip =
642
+ if let Some ( nakamoto_parent_tenure) = self . nakamoto_parent_tenure_opt . as_ref ( ) {
643
+ nakamoto_parent_tenure. last ( ) . as_ref ( ) . unwrap ( ) . block_id ( )
644
+ } else {
645
+ let tip = {
646
+ let chainstate = & mut self . stacks_node . as_mut ( ) . unwrap ( ) . chainstate ;
647
+ let sort_db = self . sortdb . as_mut ( ) . unwrap ( ) ;
648
+ NakamotoChainState :: get_canonical_block_header ( chainstate. db ( ) , sort_db)
649
+ . unwrap ( )
650
+ . unwrap ( )
651
+ } ;
652
+ tip. index_block_hash ( )
653
+ } ;
654
+
655
+ let miner_addr = self . miner . origin_address ( ) . unwrap ( ) ;
656
+ let miner_acct = self . get_account ( & nakamoto_tip, & miner_addr. to_account_principal ( ) ) ;
657
+
610
658
let tenure_change_tx = self
611
659
. miner
612
- . make_nakamoto_tenure_change ( tenure_change. clone ( ) ) ;
613
- let coinbase_tx = self . miner . make_nakamoto_coinbase ( None , vrf_proof) ;
660
+ . make_nakamoto_tenure_change_with_nonce ( tenure_change. clone ( ) , miner_acct. nonce ) ;
661
+
662
+ let coinbase_tx =
663
+ self . miner
664
+ . make_nakamoto_coinbase_with_nonce ( None , vrf_proof, miner_acct. nonce + 1 ) ;
614
665
615
- let block = self . mine_single_block_tenure (
666
+ let block = self . mine_single_block_tenure_at_tip (
667
+ & nakamoto_tip,
616
668
sender_key,
617
669
& tenure_change_tx,
618
670
& coinbase_tx,
0 commit comments