@@ -3809,61 +3809,8 @@ mod tests {
3809
3809
assert_eq ! ( op_change, rbf_tx. output[ 3 ] ) ;
3810
3810
}
3811
3811
3812
- #[ test]
3813
- #[ ignore]
3814
- fn test_build_leader_key_tx_ok ( ) {
3815
- if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
3816
- return ;
3817
- }
3818
-
3819
- let keychain = utils:: create_keychain ( ) ;
3820
- let miner_pubkey = keychain. get_pub_key ( ) ;
3821
- let mut op_signer = keychain. generate_op_signer ( ) ;
3822
-
3823
- let mut config = utils:: create_config ( ) ;
3824
- config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3825
-
3826
- let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3827
- btcd_controller
3828
- . start_bitcoind ( )
3829
- . expect ( "bitcoind should be started!" ) ;
3830
-
3831
- let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3832
- btc_controller
3833
- . connect_dbs ( )
3834
- . expect ( "Dbs initialization required!" ) ;
3835
- btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
3836
-
3837
- let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
3838
-
3839
- let tx = btc_controller
3840
- . build_leader_key_register_tx (
3841
- StacksEpochId :: Epoch31 ,
3842
- leader_key_op. clone ( ) ,
3843
- & mut op_signer,
3844
- )
3845
- . expect ( "Build leader key should work" ) ;
3846
-
3847
- assert ! ( op_signer. is_disposed( ) ) ;
3848
-
3849
- assert_eq ! ( 1 , tx. version) ;
3850
- assert_eq ! ( 0 , tx. lock_time) ;
3851
- assert_eq ! ( 1 , tx. input. len( ) ) ;
3852
- assert_eq ! ( 2 , tx. output. len( ) ) ;
3853
-
3854
- // utxos list contains the only existing utxo
3855
- let used_utxos = btc_controller. get_all_utxos ( & miner_pubkey) ;
3856
- let input_0 = utils:: txin_at_index ( & tx, & op_signer, & used_utxos, 0 ) ;
3857
- assert_eq ! ( input_0, tx. input[ 0 ] ) ;
3858
-
3859
- let op_return = utils:: txout_opreturn_v2 ( & leader_key_op, & config. burnchain . magic_bytes , 0 ) ;
3860
- let op_change = utils:: txout_opdup_change_legacy ( & mut op_signer, 4_999_980_000 ) ;
3861
- assert_eq ! ( op_return, tx. output[ 0 ] ) ;
3862
- assert_eq ! ( op_change, tx. output[ 1 ] ) ;
3863
- }
3864
-
3865
- /// Tests related to `BitcoinRegtestController::make_operation_tx`
3866
- mod make_operation {
3812
+ /// Tests related to Leader Block Commit operation
3813
+ mod leader_commit_op {
3867
3814
use super :: * ;
3868
3815
3869
3816
#[ test]
@@ -3913,7 +3860,7 @@ mod tests {
3913
3860
3914
3861
#[ test]
3915
3862
#[ ignore]
3916
- fn test_make_operation_leader_key_register_tx_ok ( ) {
3863
+ fn test_submit_leader_block_commit_tx_ok ( ) {
3917
3864
if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
3918
3865
return ;
3919
3866
}
@@ -3936,32 +3883,34 @@ mod tests {
3936
3883
. expect ( "Dbs initialization required!" ) ;
3937
3884
btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
3938
3885
3939
- let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
3886
+ let mut commit_op = utils:: create_templated_commit_op ( ) ;
3887
+ commit_op. sunset_burn = 5_500 ;
3888
+ commit_op. burn_fee = 110_000 ;
3940
3889
3941
- let ser_tx = btc_controller
3942
- . make_operation_tx (
3890
+ let tx_id = btc_controller
3891
+ . submit_operation (
3943
3892
StacksEpochId :: Epoch31 ,
3944
- BlockstackOperationType :: LeaderKeyRegister ( leader_key_op ) ,
3893
+ BlockstackOperationType :: LeaderBlockCommit ( commit_op ) ,
3945
3894
& mut op_signer,
3946
3895
)
3947
3896
. expect ( "Build leader block commit should work" ) ;
3948
3897
3949
3898
assert ! ( op_signer. is_disposed( ) ) ;
3950
3899
3951
3900
assert_eq ! (
3952
- "01000000014d9e9dc7d126446e90dd013f023937eba9cb2c88f4d12707400a3ede994a62c5000000008b483045022100c8694688b4269585ef63bfeb96d017bafae02621ebd0b5012e7564d3efcb71f70220070528674f75ca3503246030f064a85d2010256336372b246100f29ba21bf28b0141044227d7e5c0997524ce011c126f0464d43e7518872a9b1ad29436ac5142d73eab5fb48d764676900fc2fac56917412114bf7dfafe51f715cf466fe0c1a6c69d11fdffffff020000000000000000396a3754335e00000000000000000000000000000000000000003b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29e0a3052a010000001976a9145e52c53cb96b55f0e3d719adbca21005bc54cb2e88ac00000000 " ,
3953
- ser_tx . to_hex( )
3901
+ "1a74106bd760117892fbd90fca11646b4de46f99fd2b065c9e0706cfdcea0336 " ,
3902
+ tx_id . to_hex( )
3954
3903
) ;
3955
3904
}
3956
3905
}
3957
3906
3958
- /// Tests related to `BitcoinRegtestController::submit_operation`
3959
- mod submit_operation {
3907
+ /// Tests related to Leader Key Register operation
3908
+ mod leader_key_op {
3960
3909
use super :: * ;
3961
3910
3962
3911
#[ test]
3963
3912
#[ ignore]
3964
- fn test_submit_leader_block_commit_tx_ok ( ) {
3913
+ fn test_build_leader_key_tx_ok ( ) {
3965
3914
if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
3966
3915
return ;
3967
3916
}
@@ -3979,28 +3928,110 @@ mod tests {
3979
3928
. expect ( "bitcoind should be started!" ) ;
3980
3929
3981
3930
let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3982
- btc_controller
3983
- . connect_dbs ( )
3984
- . expect ( "Dbs initialization required!" ) ;
3985
3931
btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
3986
3932
3987
- let mut commit_op = utils:: create_templated_commit_op ( ) ;
3988
- commit_op. sunset_burn = 5_500 ;
3989
- commit_op. burn_fee = 110_000 ;
3933
+ let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
3990
3934
3991
- let tx_id = btc_controller
3992
- . submit_operation (
3935
+ let tx = btc_controller
3936
+ . build_leader_key_register_tx (
3993
3937
StacksEpochId :: Epoch31 ,
3994
- BlockstackOperationType :: LeaderBlockCommit ( commit_op) ,
3938
+ leader_key_op. clone ( ) ,
3939
+ & mut op_signer,
3940
+ )
3941
+ . expect ( "Build leader key should work" ) ;
3942
+
3943
+ assert ! ( op_signer. is_disposed( ) ) ;
3944
+
3945
+ assert_eq ! ( 1 , tx. version) ;
3946
+ assert_eq ! ( 0 , tx. lock_time) ;
3947
+ assert_eq ! ( 1 , tx. input. len( ) ) ;
3948
+ assert_eq ! ( 2 , tx. output. len( ) ) ;
3949
+
3950
+ // utxos list contains the only existing utxo
3951
+ let used_utxos = btc_controller. get_all_utxos ( & miner_pubkey) ;
3952
+ let input_0 = utils:: txin_at_index ( & tx, & op_signer, & used_utxos, 0 ) ;
3953
+ assert_eq ! ( input_0, tx. input[ 0 ] ) ;
3954
+
3955
+ let op_return =
3956
+ utils:: txout_opreturn_v2 ( & leader_key_op, & config. burnchain . magic_bytes , 0 ) ;
3957
+ let op_change = utils:: txout_opdup_change_legacy ( & mut op_signer, 4_999_980_000 ) ;
3958
+ assert_eq ! ( op_return, tx. output[ 0 ] ) ;
3959
+ assert_eq ! ( op_change, tx. output[ 1 ] ) ;
3960
+ }
3961
+
3962
+ #[ test]
3963
+ #[ ignore]
3964
+ fn test_build_leader_key_tx_fails_due_to_no_utxos ( ) {
3965
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
3966
+ return ;
3967
+ }
3968
+
3969
+ let keychain = utils:: create_keychain ( ) ;
3970
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3971
+ let mut op_signer = keychain. generate_op_signer ( ) ;
3972
+
3973
+ let mut config = utils:: create_config ( ) ;
3974
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3975
+
3976
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3977
+ btcd_controller
3978
+ . start_bitcoind ( )
3979
+ . expect ( "bitcoind should be started!" ) ;
3980
+
3981
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3982
+ btc_controller. bootstrap_chain ( 100 ) ; // no utxos exist
3983
+
3984
+ let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
3985
+
3986
+ let error = btc_controller
3987
+ . build_leader_key_register_tx (
3988
+ StacksEpochId :: Epoch31 ,
3989
+ leader_key_op. clone ( ) ,
3990
+ & mut op_signer,
3991
+ )
3992
+ . expect_err ( "Leader key build should fail!" ) ;
3993
+
3994
+ assert ! ( !op_signer. is_disposed( ) ) ;
3995
+ assert_eq ! ( BurnchainControllerError :: NoUTXOs , error) ;
3996
+ }
3997
+
3998
+ #[ test]
3999
+ #[ ignore]
4000
+ fn test_make_operation_leader_key_register_tx_ok ( ) {
4001
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
4002
+ return ;
4003
+ }
4004
+
4005
+ let keychain = utils:: create_keychain ( ) ;
4006
+ let miner_pubkey = keychain. get_pub_key ( ) ;
4007
+ let mut op_signer = keychain. generate_op_signer ( ) ;
4008
+
4009
+ let mut config = utils:: create_config ( ) ;
4010
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
4011
+
4012
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
4013
+ btcd_controller
4014
+ . start_bitcoind ( )
4015
+ . expect ( "bitcoind should be started!" ) ;
4016
+
4017
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
4018
+ btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
4019
+
4020
+ let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
4021
+
4022
+ let ser_tx = btc_controller
4023
+ . make_operation_tx (
4024
+ StacksEpochId :: Epoch31 ,
4025
+ BlockstackOperationType :: LeaderKeyRegister ( leader_key_op) ,
3995
4026
& mut op_signer,
3996
4027
)
3997
4028
. expect ( "Build leader block commit should work" ) ;
3998
4029
3999
4030
assert ! ( op_signer. is_disposed( ) ) ;
4000
4031
4001
4032
assert_eq ! (
4002
- "1a74106bd760117892fbd90fca11646b4de46f99fd2b065c9e0706cfdcea0336 " ,
4003
- tx_id . to_hex( )
4033
+ "01000000014d9e9dc7d126446e90dd013f023937eba9cb2c88f4d12707400a3ede994a62c5000000008b483045022100c8694688b4269585ef63bfeb96d017bafae02621ebd0b5012e7564d3efcb71f70220070528674f75ca3503246030f064a85d2010256336372b246100f29ba21bf28b0141044227d7e5c0997524ce011c126f0464d43e7518872a9b1ad29436ac5142d73eab5fb48d764676900fc2fac56917412114bf7dfafe51f715cf466fe0c1a6c69d11fdffffff020000000000000000396a3754335e00000000000000000000000000000000000000003b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29e0a3052a010000001976a9145e52c53cb96b55f0e3d719adbca21005bc54cb2e88ac00000000 " ,
4034
+ ser_tx . to_hex( )
4004
4035
) ;
4005
4036
}
4006
4037
@@ -4024,9 +4055,6 @@ mod tests {
4024
4055
. expect ( "bitcoind should be started!" ) ;
4025
4056
4026
4057
let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
4027
- btc_controller
4028
- . connect_dbs ( )
4029
- . expect ( "Dbs initialization required!" ) ;
4030
4058
btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
4031
4059
4032
4060
let leader_key_op = utils:: create_templated_leader_key_op ( ) ;
0 commit comments