@@ -3088,6 +3088,16 @@ mod tests {
3088
3088
. into_script ( ) ,
3089
3089
}
3090
3090
}
3091
+
3092
+ pub fn create_templated_pre_stx_op ( ) -> PreStxOp {
3093
+ PreStxOp {
3094
+ output : StacksAddress :: p2pkh_from_hash ( false , Hash160 :: from_data ( & [ 2u8 ; 20 ] ) ) ,
3095
+ txid : Txid ( [ 0u8 ; 32 ] ) ,
3096
+ vtxindex : 0 ,
3097
+ block_height : 0 ,
3098
+ burn_header_hash : BurnchainHeaderHash ( [ 0u8 ; 32 ] ) ,
3099
+ }
3100
+ }
3091
3101
}
3092
3102
3093
3103
#[ test]
@@ -3848,7 +3858,7 @@ mod tests {
3848
3858
BlockstackOperationType :: LeaderBlockCommit ( commit_op) ,
3849
3859
& mut op_signer,
3850
3860
)
3851
- . expect ( "Build leader block commit should work" ) ;
3861
+ . expect ( "Make op should work" ) ;
3852
3862
3853
3863
assert ! ( op_signer. is_disposed( ) ) ;
3854
3864
@@ -4025,7 +4035,7 @@ mod tests {
4025
4035
BlockstackOperationType :: LeaderKeyRegister ( leader_key_op) ,
4026
4036
& mut op_signer,
4027
4037
)
4028
- . expect ( "Build leader block commit should work" ) ;
4038
+ . expect ( "Make op should work" ) ;
4029
4039
4030
4040
assert ! ( op_signer. is_disposed( ) ) ;
4031
4041
@@ -4075,4 +4085,171 @@ mod tests {
4075
4085
) ;
4076
4086
}
4077
4087
}
4088
+
4089
+ /// Tests related to Pre Stacks operation
4090
+ mod pre_stx_op {
4091
+ use super :: * ;
4092
+
4093
+ #[ test]
4094
+ #[ ignore]
4095
+ fn test_build_pre_stx_tx_ok ( ) {
4096
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
4097
+ return ;
4098
+ }
4099
+
4100
+ let keychain = utils:: create_keychain ( ) ;
4101
+ let miner_pubkey = keychain. get_pub_key ( ) ;
4102
+ let mut op_signer = keychain. generate_op_signer ( ) ;
4103
+
4104
+ let mut config = utils:: create_config ( ) ;
4105
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
4106
+
4107
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
4108
+ btcd_controller
4109
+ . start_bitcoind ( )
4110
+ . expect ( "bitcoind should be started!" ) ;
4111
+
4112
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
4113
+ btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
4114
+
4115
+ let mut pre_stx_op = utils:: create_templated_pre_stx_op ( ) ;
4116
+ pre_stx_op. output = keychain. get_address ( false ) ;
4117
+
4118
+ let tx = btc_controller
4119
+ . build_pre_stacks_tx ( StacksEpochId :: Epoch31 , pre_stx_op. clone ( ) , & mut op_signer)
4120
+ . expect ( "Build leader key should work" ) ;
4121
+
4122
+ assert ! ( op_signer. is_disposed( ) ) ;
4123
+
4124
+ assert_eq ! ( 1 , tx. version) ;
4125
+ assert_eq ! ( 0 , tx. lock_time) ;
4126
+ assert_eq ! ( 1 , tx. input. len( ) ) ;
4127
+ assert_eq ! ( 3 , tx. output. len( ) ) ;
4128
+
4129
+ // utxos list contains the only existing utxo
4130
+ let used_utxos = btc_controller. get_all_utxos ( & miner_pubkey) ;
4131
+ let input_0 = utils:: txin_at_index ( & tx, & op_signer, & used_utxos, 0 ) ;
4132
+ assert_eq ! ( input_0, tx. input[ 0 ] ) ;
4133
+
4134
+ let op_return = utils:: txout_opreturn_v2 ( & pre_stx_op, & config. burnchain . magic_bytes , 0 ) ;
4135
+ let op_change = utils:: txout_opdup_change_legacy ( & mut op_signer, 24_500 ) ;
4136
+ assert_eq ! ( op_return, tx. output[ 0 ] ) ;
4137
+ assert_eq ! ( op_change, tx. output[ 1 ] ) ;
4138
+ }
4139
+
4140
+ #[ test]
4141
+ #[ ignore]
4142
+ fn test_build_pre_stx_tx_fails_due_to_no_utxos ( ) {
4143
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
4144
+ return ;
4145
+ }
4146
+
4147
+ let keychain = utils:: create_keychain ( ) ;
4148
+ let miner_pubkey = keychain. get_pub_key ( ) ;
4149
+ let mut op_signer = keychain. generate_op_signer ( ) ;
4150
+
4151
+ let mut config = utils:: create_config ( ) ;
4152
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
4153
+
4154
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
4155
+ btcd_controller
4156
+ . start_bitcoind ( )
4157
+ . expect ( "bitcoind should be started!" ) ;
4158
+
4159
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
4160
+ btc_controller. bootstrap_chain ( 100 ) ; // no utxo exists
4161
+
4162
+ let mut pre_stx_op = utils:: create_templated_pre_stx_op ( ) ;
4163
+ pre_stx_op. output = keychain. get_address ( false ) ;
4164
+
4165
+ let error = btc_controller
4166
+ . build_pre_stacks_tx ( StacksEpochId :: Epoch31 , pre_stx_op. clone ( ) , & mut op_signer)
4167
+ . expect_err ( "Leader key build should fail!" ) ;
4168
+
4169
+ assert ! ( !op_signer. is_disposed( ) ) ;
4170
+ assert_eq ! ( BurnchainControllerError :: NoUTXOs , error) ;
4171
+ }
4172
+
4173
+ #[ test]
4174
+ #[ ignore]
4175
+ fn test_make_operation_pre_stx_tx_ok ( ) {
4176
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
4177
+ return ;
4178
+ }
4179
+
4180
+ let keychain = utils:: create_keychain ( ) ;
4181
+ let miner_pubkey = keychain. get_pub_key ( ) ;
4182
+ let mut op_signer = keychain. generate_op_signer ( ) ;
4183
+
4184
+ let mut config = utils:: create_config ( ) ;
4185
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
4186
+
4187
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
4188
+ btcd_controller
4189
+ . start_bitcoind ( )
4190
+ . expect ( "bitcoind should be started!" ) ;
4191
+
4192
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
4193
+ btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
4194
+
4195
+ let mut pre_stx_op = utils:: create_templated_pre_stx_op ( ) ;
4196
+ pre_stx_op. output = keychain. get_address ( false ) ;
4197
+
4198
+ let ser_tx = btc_controller
4199
+ . make_operation_tx (
4200
+ StacksEpochId :: Epoch31 ,
4201
+ BlockstackOperationType :: PreStx ( pre_stx_op) ,
4202
+ & mut op_signer,
4203
+ )
4204
+ . expect ( "Make op should work" ) ;
4205
+
4206
+ assert ! ( op_signer. is_disposed( ) ) ;
4207
+
4208
+ assert_eq ! (
4209
+ "01000000014d9e9dc7d126446e90dd013f023937eba9cb2c88f4d12707400a3ede994a62c5000000008a47304402203351a9351e887f4b66023893f55e308c3c345aec6f50dd3bd11fc90b7049703102200fbbf08747e4961ec8e0a5f5e991fa5f709cac9083d22772cd48e9325a48bba30141044227d7e5c0997524ce011c126f0464d43e7518872a9b1ad29436ac5142d73eab5fb48d764676900fc2fac56917412114bf7dfafe51f715cf466fe0c1a6c69d11fdffffff030000000000000000056a03543370b45f0000000000001976a9145e52c53cb96b55f0e3d719adbca21005bc54cb2e88ac9c5b052a010000001976a9145e52c53cb96b55f0e3d719adbca21005bc54cb2e88ac00000000" ,
4210
+ ser_tx. to_hex( )
4211
+ ) ;
4212
+ }
4213
+
4214
+ #[ test]
4215
+ #[ ignore]
4216
+ fn test_submit_operation_pre_stx_tx_ok ( ) {
4217
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
4218
+ return ;
4219
+ }
4220
+
4221
+ let keychain = utils:: create_keychain ( ) ;
4222
+ let miner_pubkey = keychain. get_pub_key ( ) ;
4223
+ let mut op_signer = keychain. generate_op_signer ( ) ;
4224
+
4225
+ let mut config = utils:: create_config ( ) ;
4226
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
4227
+
4228
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
4229
+ btcd_controller
4230
+ . start_bitcoind ( )
4231
+ . expect ( "bitcoind should be started!" ) ;
4232
+
4233
+ let mut btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
4234
+ btc_controller. bootstrap_chain ( 101 ) ; // now, one utxo exists
4235
+
4236
+ let mut pre_stx_op = utils:: create_templated_pre_stx_op ( ) ;
4237
+ pre_stx_op. output = keychain. get_address ( false ) ;
4238
+
4239
+ let tx_id = btc_controller
4240
+ . submit_operation (
4241
+ StacksEpochId :: Epoch31 ,
4242
+ BlockstackOperationType :: PreStx ( pre_stx_op) ,
4243
+ & mut op_signer,
4244
+ )
4245
+ . expect ( "submit op should work" ) ;
4246
+
4247
+ assert ! ( op_signer. is_disposed( ) ) ;
4248
+
4249
+ assert_eq ! (
4250
+ "2d061c42c6f13a62fd9d80dc9fdcd19bdb4f9e4a07f786e42530c64c52ed9d1d" ,
4251
+ tx_id. to_hex( )
4252
+ ) ;
4253
+ }
4254
+ }
4078
4255
}
0 commit comments