@@ -2841,6 +2841,8 @@ mod tests {
2841
2841
mod utils {
2842
2842
use std:: net:: TcpListener ;
2843
2843
2844
+ use stacks:: burnchains:: MagicBytes ;
2845
+
2844
2846
use super :: * ;
2845
2847
use crate :: tests:: bitcoin_regtest:: BURNCHAIN_CONFIG_PEER_PORT_DISABLED ;
2846
2848
use crate :: util:: get_epoch_time_nanos;
@@ -2924,6 +2926,35 @@ mod tests {
2924
2926
burn_header_hash : BurnchainHeaderHash ( [ 0x01 ; 32 ] ) ,
2925
2927
}
2926
2928
}
2929
+
2930
+ pub fn txout_opreturn ( op : & LeaderBlockCommitOp , magic : & MagicBytes ) -> TxOut {
2931
+ let op_bytes = {
2932
+ let mut buffer = vec ! [ ] ;
2933
+ let mut magic_bytes = magic. as_bytes ( ) . to_vec ( ) ;
2934
+ buffer. append ( & mut magic_bytes) ;
2935
+ op. consensus_serialize ( & mut buffer)
2936
+ . expect ( "FATAL: invalid operation" ) ;
2937
+ buffer
2938
+ } ;
2939
+
2940
+ TxOut {
2941
+ value : op. sunset_burn ,
2942
+ script_pubkey : Builder :: new ( )
2943
+ . push_opcode ( opcodes:: All :: OP_RETURN )
2944
+ . push_slice ( & op_bytes)
2945
+ . into_script ( ) ,
2946
+ }
2947
+ }
2948
+
2949
+ pub fn txout_opdup_commit_to ( addr : & PoxAddress , amount : u64 ) -> TxOut {
2950
+ addr. to_bitcoin_tx_out ( amount)
2951
+ }
2952
+
2953
+ pub fn txout_opdup_change_legacy ( signer : & mut BurnchainOpSigner , amount : u64 ) -> TxOut {
2954
+ let public_key = signer. get_public_key ( ) ;
2955
+ let change_address_hash = Hash160 :: from_data ( & public_key. to_bytes ( ) ) ;
2956
+ LegacyBitcoinAddress :: to_p2pkh_tx_out ( & change_address_hash, amount)
2957
+ }
2927
2958
}
2928
2959
2929
2960
#[ test]
@@ -3349,7 +3380,7 @@ mod tests {
3349
3380
. start_bitcoind ( )
3350
3381
. expect ( "bitcoind should be started!" ) ;
3351
3382
3352
- let mut btc_controller = BitcoinRegtestController :: new ( config, None ) ;
3383
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3353
3384
btc_controller
3354
3385
. connect_dbs ( )
3355
3386
. expect ( "Dbs initialization required!" ) ;
@@ -3358,13 +3389,27 @@ mod tests {
3358
3389
let commit_op = utils:: create_commit_op ( ) ;
3359
3390
3360
3391
let tx = btc_controller
3361
- . build_leader_block_commit_tx ( StacksEpochId :: Epoch31 , commit_op, & mut signer, 0 )
3392
+ . build_leader_block_commit_tx ( StacksEpochId :: Epoch31 , commit_op. clone ( ) , & mut signer, 0 )
3362
3393
. expect ( "Build leader block commit should work" ) ;
3363
3394
3364
3395
assert_eq ! ( 1 , tx. version) ;
3365
3396
assert_eq ! ( 0 , tx. lock_time) ;
3366
3397
assert_eq ! ( 1 , tx. input. len( ) ) ;
3367
3398
assert_eq ! ( 4 , tx. output. len( ) ) ;
3399
+
3400
+ //TODO: Try to implement assertion for TxIn
3401
+ //let utxos = btc_controller.get_all_utxos(&miner_pubkey);
3402
+ //let input_0 = utils::txin_utxo_legacy(&utxos[0])
3403
+ //assert_ne!(tx.input[0], tx.input[0]);
3404
+
3405
+ let op_return = utils:: txout_opreturn ( & commit_op, & config. burnchain . magic_bytes ) ;
3406
+ let op_commit_1 = utils:: txout_opdup_commit_to ( & commit_op. commit_outs [ 0 ] , 55_000 ) ;
3407
+ let op_commit_2 = utils:: txout_opdup_commit_to ( & commit_op. commit_outs [ 1 ] , 55_000 ) ;
3408
+ let op_change = utils:: txout_opdup_change_legacy ( & mut signer, 4_999_865_300 ) ;
3409
+ assert_eq ! ( op_return, tx. output[ 0 ] ) ;
3410
+ assert_eq ! ( op_commit_1, tx. output[ 1 ] ) ;
3411
+ assert_eq ! ( op_commit_2, tx. output[ 2 ] ) ;
3412
+ assert_eq ! ( op_change, tx. output[ 3 ] ) ;
3368
3413
}
3369
3414
3370
3415
#[ test]
@@ -3481,7 +3526,7 @@ mod tests {
3481
3526
. start_bitcoind ( )
3482
3527
. expect ( "bitcoind should be started!" ) ;
3483
3528
3484
- let mut btc_controller = BitcoinRegtestController :: new ( config, None ) ;
3529
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3485
3530
btc_controller
3486
3531
. connect_dbs ( )
3487
3532
. expect ( "Dbs initialization required!" ) ;
@@ -3505,13 +3550,22 @@ mod tests {
3505
3550
commit_op. burn_fee += 10 ;
3506
3551
3507
3552
let rbf_tx = btc_controller
3508
- . build_leader_block_commit_tx ( StacksEpochId :: Epoch31 , commit_op, & mut signer, 0 )
3553
+ . build_leader_block_commit_tx ( StacksEpochId :: Epoch31 , commit_op. clone ( ) , & mut signer, 0 )
3509
3554
. expect ( "Commit tx should be rbf-ed" ) ;
3510
3555
3511
3556
assert_eq ! ( 1 , rbf_tx. version) ;
3512
3557
assert_eq ! ( 0 , rbf_tx. lock_time) ;
3513
3558
assert_eq ! ( 1 , rbf_tx. input. len( ) ) ;
3514
3559
assert_eq ! ( 4 , rbf_tx. output. len( ) ) ;
3560
+
3561
+ let op_return = utils:: txout_opreturn ( & commit_op, & config. burnchain . magic_bytes ) ;
3562
+ let op_commit_1 = utils:: txout_opdup_commit_to ( & commit_op. commit_outs [ 0 ] , 55_005 ) ;
3563
+ let op_commit_2 = utils:: txout_opdup_commit_to ( & commit_op. commit_outs [ 1 ] , 55_005 ) ;
3564
+ let op_change = utils:: txout_opdup_change_legacy ( & mut signer, 4_999_730_590 ) ;
3565
+ assert_eq ! ( op_return, rbf_tx. output[ 0 ] ) ;
3566
+ assert_eq ! ( op_commit_1, rbf_tx. output[ 1 ] ) ;
3567
+ assert_eq ! ( op_commit_2, rbf_tx. output[ 2 ] ) ;
3568
+ assert_eq ! ( op_change, rbf_tx. output[ 3 ] ) ;
3515
3569
}
3516
3570
3517
3571
#[ test]
@@ -3532,7 +3586,7 @@ mod tests {
3532
3586
. start_bitcoind ( )
3533
3587
. expect ( "bitcoind should be started!" ) ;
3534
3588
3535
- let mut btc_controller = BitcoinRegtestController :: new ( config, None ) ;
3589
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3536
3590
btc_controller
3537
3591
. connect_dbs ( )
3538
3592
. expect ( "Dbs initialization required!" ) ;
@@ -3556,12 +3610,21 @@ mod tests {
3556
3610
commit_op. burn_fee += 10 ;
3557
3611
3558
3612
let rbf_tx = btc_controller
3559
- . build_leader_block_commit_tx ( StacksEpochId :: Epoch31 , commit_op, & mut signer, 0 )
3613
+ . build_leader_block_commit_tx ( StacksEpochId :: Epoch31 , commit_op. clone ( ) , & mut signer, 0 )
3560
3614
. expect ( "Commit tx should be rbf-ed" ) ;
3561
3615
3562
3616
assert_eq ! ( 1 , rbf_tx. version) ;
3563
3617
assert_eq ! ( 0 , rbf_tx. lock_time) ;
3564
3618
assert_eq ! ( 1 , rbf_tx. input. len( ) ) ;
3565
3619
assert_eq ! ( 4 , rbf_tx. output. len( ) ) ;
3620
+
3621
+ let op_return = utils:: txout_opreturn ( & commit_op, & config. burnchain . magic_bytes ) ;
3622
+ let op_commit_1 = utils:: txout_opdup_commit_to ( & commit_op. commit_outs [ 0 ] , 55_005 ) ;
3623
+ let op_commit_2 = utils:: txout_opdup_commit_to ( & commit_op. commit_outs [ 1 ] , 55_005 ) ;
3624
+ let op_change = utils:: txout_opdup_change_legacy ( & mut signer, 4_999_730_590 ) ;
3625
+ assert_eq ! ( op_return, rbf_tx. output[ 0 ] ) ;
3626
+ assert_eq ! ( op_commit_1, rbf_tx. output[ 1 ] ) ;
3627
+ assert_eq ! ( op_commit_2, rbf_tx. output[ 2 ] ) ;
3628
+ assert_eq ! ( op_change, rbf_tx. output[ 3 ] ) ;
3566
3629
}
3567
3630
}
0 commit comments