@@ -839,7 +839,6 @@ impl BitcoinRegtestController {
839
839
epoch_id : StacksEpochId ,
840
840
payload : LeaderKeyRegisterOp ,
841
841
signer : & mut BurnchainOpSigner ,
842
- _attempt : u64 ,
843
842
) -> Result < Transaction , BurnchainControllerError > {
844
843
let public_key = signer. get_public_key ( ) ;
845
844
@@ -2064,14 +2063,14 @@ impl BitcoinRegtestController {
2064
2063
epoch_id : StacksEpochId ,
2065
2064
operation : BlockstackOperationType ,
2066
2065
op_signer : & mut BurnchainOpSigner ,
2067
- attempt : u64 ,
2066
+ _attempt : u64 ,
2068
2067
) -> Result < SerializedTx , BurnchainControllerError > {
2069
2068
let transaction = match operation {
2070
2069
BlockstackOperationType :: LeaderBlockCommit ( payload) => {
2071
2070
self . build_leader_block_commit_tx ( epoch_id, payload, op_signer)
2072
2071
}
2073
2072
BlockstackOperationType :: LeaderKeyRegister ( payload) => {
2074
- self . build_leader_key_register_tx ( epoch_id, payload, op_signer, attempt )
2073
+ self . build_leader_key_register_tx ( epoch_id, payload, op_signer)
2075
2074
}
2076
2075
BlockstackOperationType :: PreStx ( payload) => {
2077
2076
self . build_pre_stacks_tx ( epoch_id, payload, op_signer)
@@ -2838,7 +2837,7 @@ mod tests {
2838
2837
use std:: io:: Write ;
2839
2838
2840
2839
use stacks:: burnchains:: BurnchainSigner ;
2841
- use stacks:: config:: DEFAULT_SATS_PER_VB ;
2840
+ use stacks:: config:: { DEFAULT_SATS_PER_VB } ;
2842
2841
use stacks_common:: deps_common:: bitcoin:: blockdata:: script:: Builder ;
2843
2842
use stacks_common:: types:: chainstate:: { BlockHeaderHash , StacksAddress , VRFSeed } ;
2844
2843
use stacks_common:: util:: hash:: to_hex;
@@ -2852,6 +2851,8 @@ mod tests {
2852
2851
use std:: net:: TcpListener ;
2853
2852
2854
2853
use stacks:: burnchains:: MagicBytes ;
2854
+ use stacks:: chainstate:: burn:: ConsensusHash ;
2855
+ use stacks:: util:: vrf:: { VRFPrivateKey , VRFPublicKey } ;
2855
2856
2856
2857
use super :: * ;
2857
2858
use crate :: tests:: bitcoin_regtest:: BURNCHAIN_CONFIG_PEER_PORT_DISABLED ;
@@ -3052,6 +3053,38 @@ mod tests {
3052
3053
3053
3054
tx. input [ index] . clone ( )
3054
3055
}
3056
+
3057
+
3058
+ pub fn create_templated_leader_key_op ( ) -> LeaderKeyRegisterOp {
3059
+ LeaderKeyRegisterOp {
3060
+ consensus_hash : ConsensusHash ( [ 0u8 ; 20 ] ) ,
3061
+ public_key : VRFPublicKey :: from_private ( & VRFPrivateKey :: new ( ) ) ,
3062
+ memo : vec ! [ ] ,
3063
+ txid : Txid ( [ 3u8 ; 32 ] ) ,
3064
+ vtxindex : 0 ,
3065
+ block_height : 1 ,
3066
+ burn_header_hash : BurnchainHeaderHash ( [ 9u8 ; 32 ] ) ,
3067
+ }
3068
+ }
3069
+
3070
+ pub fn txout_opreturn_v2 < T : StacksMessageCodec > ( op : & T , magic : & MagicBytes , value : u64 ) -> TxOut {
3071
+ let op_bytes = {
3072
+ let mut buffer = vec ! [ ] ;
3073
+ let mut magic_bytes = magic. as_bytes ( ) . to_vec ( ) ;
3074
+ buffer. append ( & mut magic_bytes) ;
3075
+ op. consensus_serialize ( & mut buffer)
3076
+ . expect ( "FATAL: invalid operation" ) ;
3077
+ buffer
3078
+ } ;
3079
+
3080
+ TxOut {
3081
+ value,
3082
+ script_pubkey : Builder :: new ( )
3083
+ . push_opcode ( opcodes:: All :: OP_RETURN )
3084
+ . push_slice ( & op_bytes)
3085
+ . into_script ( ) ,
3086
+ }
3087
+ }
3055
3088
}
3056
3089
3057
3090
#[ test]
@@ -3773,6 +3806,55 @@ mod tests {
3773
3806
assert_eq ! ( op_change, rbf_tx. output[ 3 ] ) ;
3774
3807
}
3775
3808
3809
+ #[ test]
3810
+ #[ ignore]
3811
+ fn test_build_leader_key_tx_ok ( ) {
3812
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
3813
+ return ;
3814
+ }
3815
+
3816
+ let keychain = utils:: create_keychain ( ) ;
3817
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3818
+ let mut op_signer = keychain. generate_op_signer ( ) ;
3819
+
3820
+ let mut config = utils:: create_config ( ) ;
3821
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3822
+
3823
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3824
+ btcd_controller
3825
+ . start_bitcoind ( )
3826
+ . expect ( "bitcoind should be started!" ) ;
3827
+
3828
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3829
+ btc_controller
3830
+ . connect_dbs ( )
3831
+ . expect ( "Dbs initialization required!" ) ;
3832
+ btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
3833
+
3834
+ let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
3835
+
3836
+ let tx = btc_controller
3837
+ . build_leader_key_register_tx ( StacksEpochId :: Epoch31 , leader_key_op. clone ( ) , & mut op_signer)
3838
+ . expect ( "Build leader key should work" ) ;
3839
+
3840
+ assert ! ( op_signer. is_disposed( ) ) ;
3841
+
3842
+ assert_eq ! ( 1 , tx. version) ;
3843
+ assert_eq ! ( 0 , tx. lock_time) ;
3844
+ assert_eq ! ( 1 , tx. input. len( ) ) ;
3845
+ assert_eq ! ( 2 , tx. output. len( ) ) ;
3846
+
3847
+ // utxos list contains the only existing utxo
3848
+ let used_utxos = btc_controller. get_all_utxos ( & miner_pubkey) ;
3849
+ let input_0 = utils:: txin_at_index ( & tx, & op_signer, & used_utxos, 0 ) ;
3850
+ assert_eq ! ( input_0, tx. input[ 0 ] ) ;
3851
+
3852
+ let op_return = utils:: txout_opreturn_v2 ( & leader_key_op, & config. burnchain . magic_bytes , 0 ) ;
3853
+ let op_change = utils:: txout_opdup_change_legacy ( & mut op_signer, 4_999_980_000 ) ;
3854
+ assert_eq ! ( op_return, tx. output[ 0 ] ) ;
3855
+ assert_eq ! ( op_change, tx. output[ 1 ] ) ;
3856
+ }
3857
+
3776
3858
/// Tests related to `BitcoinRegtestController::make_operation_tx`
3777
3859
mod make_operation {
3778
3860
use super :: * ;
@@ -3822,5 +3904,49 @@ mod tests {
3822
3904
tx. to_hex( )
3823
3905
) ;
3824
3906
}
3907
+
3908
+ #[ test]
3909
+ #[ ignore]
3910
+ fn test_make_operation_leader_key_register_tx_ok ( ) {
3911
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
3912
+ return ;
3913
+ }
3914
+
3915
+ let keychain = utils:: create_keychain ( ) ;
3916
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3917
+ let mut op_signer = keychain. generate_op_signer ( ) ;
3918
+
3919
+ let mut config = utils:: create_config ( ) ;
3920
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3921
+
3922
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3923
+ btcd_controller
3924
+ . start_bitcoind ( )
3925
+ . expect ( "bitcoind should be started!" ) ;
3926
+
3927
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3928
+ btc_controller
3929
+ . connect_dbs ( )
3930
+ . expect ( "Dbs initialization required!" ) ;
3931
+ btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
3932
+
3933
+ let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
3934
+
3935
+ let tx = btc_controller
3936
+ . make_operation_tx (
3937
+ StacksEpochId :: Epoch31 ,
3938
+ BlockstackOperationType :: LeaderKeyRegister ( leader_key_op) ,
3939
+ & mut op_signer,
3940
+ 0 ,
3941
+ )
3942
+ . expect ( "Build leader block commit should work" ) ;
3943
+
3944
+ assert ! ( op_signer. is_disposed( ) ) ;
3945
+
3946
+ assert_eq ! (
3947
+ "01000000014d9e9dc7d126446e90dd013f023937eba9cb2c88f4d12707400a3ede994a62c5000000008b483045022100f25168ce653d1f40aa7bf48d5dcad97e96ecdeaa8c142f74316bf6e151c918b002201211c493f3add7302d286af9009a18c685f8733504ffda9b80963bd6900819f40141044227d7e5c0997524ce011c126f0464d43e7518872a9b1ad29436ac5142d73eab5fb48d764676900fc2fac56917412114bf7dfafe51f715cf466fe0c1a6c69d11fdffffff020000000000000000396a3754335e0000000000000000000000000000000000000000edb3ebc987bf6911e64048c5637c85687815fb777bf882bce10a4d692dc9631ee0a3052a010000001976a9145e52c53cb96b55f0e3d719adbca21005bc54cb2e88ac00000000" ,
3948
+ tx. to_hex( )
3949
+ ) ;
3950
+ }
3825
3951
}
3826
3952
}
0 commit comments