@@ -2843,6 +2843,9 @@ mod tests {
2843
2843
use stacks_common:: util:: hash:: to_hex;
2844
2844
use stacks_common:: util:: secp256k1:: Secp256k1PrivateKey ;
2845
2845
2846
+ use crate :: tests:: bitcoin_regtest:: BitcoinCoreController ;
2847
+ use crate :: Keychain ;
2848
+
2846
2849
use super :: * ;
2847
2850
2848
2851
#[ test]
@@ -3018,4 +3021,151 @@ mod tests {
3018
3021
3019
3022
assert_eq ! ( & SerializedTx :: new( block_commit) . to_hex( ) , "0100000002eeda098987728e4a2e21b34b74000dcb0bd0e4d20e55735492ec3cba3afbead3030000006a4730440220558286e20e10ce31537f0625dae5cc62fac7961b9d2cf272c990de96323d7e2502202255adbea3d2e0509b80c5d8a3a4fe6397a87bcf18da1852740d5267d89a0cb20121035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7cfdffffff243b0b329a5889ab8801b315eea19810848d4c2133e0245671cc984a2d2f1301000000006a47304402206d9f8de107f9e1eb15aafac66c2bb34331a7523260b30e18779257e367048d34022013c7dabb32a5c281aa00d405e2ccbd00f34f03a65b2336553a4acd6c52c251ef0121035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7cfdffffff040000000000000000536a4c5054335be88c3d30cb59a142f83de3b27f897a43bbb0f13316911bb98a3229973dae32afd5b9f21bc1f40f24e2c101ecd13c55b8619e5e03dad81de2c62a1cc1d8c1b375000008a300010000059800015a10270000000000001976a914000000000000000000000000000000000000000088ac10270000000000001976a914000000000000000000000000000000000000000088acb3ef0400000000001976a9141dc27eba0247f8cc9575e7d45e50a0bc7e72427d88ac00000000" ) ;
3020
3023
}
3024
+
3025
+ #[ test]
3026
+ fn test_create_wallet_if_not_exists ( ) {
3027
+ let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
3028
+ let keychain = Keychain :: default ( miner_seed. clone ( ) ) ;
3029
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3030
+
3031
+ let mut config = Config :: default ( ) ;
3032
+ config. burnchain . magic_bytes = "T3" . as_bytes ( ) . into ( ) ;
3033
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3034
+ config. burnchain . username = Some ( "user" . to_owned ( ) ) ;
3035
+ config. burnchain . password = Some ( "12345" . to_owned ( ) ) ;
3036
+
3037
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3038
+ btcd_controller. start_bitcoind ( ) . expect ( "bitcoind should be started!" ) ;
3039
+
3040
+ let btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3041
+ btc_controller
3042
+ . create_wallet_if_dne ( )
3043
+ . expect ( "Wallet should now exists!" ) ;
3044
+ }
3045
+
3046
+ #[ test]
3047
+ fn test_get_all_utxos ( ) {
3048
+ let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
3049
+ let keychain = Keychain :: default ( miner_seed. clone ( ) ) ;
3050
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3051
+
3052
+ let mut config = Config :: default ( ) ;
3053
+ config. burnchain . magic_bytes = "T3" . as_bytes ( ) . into ( ) ;
3054
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3055
+ config. burnchain . username = Some ( "user" . to_owned ( ) ) ;
3056
+ config. burnchain . password = Some ( "12345" . to_owned ( ) ) ;
3057
+
3058
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3059
+ btcd_controller. start_bitcoind ( ) . expect ( "bitcoind should be started!" ) ;
3060
+
3061
+ let btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3062
+ btc_controller. bootstrap_chain ( 101 ) ;
3063
+
3064
+ let utxos = btc_controller. get_all_utxos ( & miner_pubkey) ;
3065
+ assert_eq ! ( 1 , utxos. len( ) ) ;
3066
+ }
3067
+
3068
+ #[ test]
3069
+ //NOTE: STALL if burn block at block_height doesn't exist....
3070
+ fn test_get_utxos ( ) {
3071
+ let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
3072
+ let keychain = Keychain :: default ( miner_seed. clone ( ) ) ;
3073
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3074
+
3075
+ let mut config = Config :: default ( ) ;
3076
+ config. burnchain . magic_bytes = "T3" . as_bytes ( ) . into ( ) ;
3077
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3078
+ config. burnchain . username = Some ( "user" . to_owned ( ) ) ;
3079
+ config. burnchain . password = Some ( "12345" . to_owned ( ) ) ;
3080
+
3081
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3082
+ btcd_controller. start_bitcoind ( ) . expect ( "bitcoind should be started!" ) ;
3083
+
3084
+ let btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3085
+ btc_controller. bootstrap_chain ( 101 ) ;
3086
+
3087
+ let utxos =
3088
+ btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & miner_pubkey, 19000 , None , 0 ) ;
3089
+
3090
+ let uxto_set = utxos. expect ( "Shouldn't be None!" ) ;
3091
+ assert_eq ! ( 1 , uxto_set. num_utxos( ) ) ;
3092
+ assert_eq ! ( 5000000000 , uxto_set. total_available( ) ) ;
3093
+ let utxo = & uxto_set. utxos [ 0 ] ;
3094
+ assert_eq ! ( 101 , utxo. confirmations) ;
3095
+ assert_eq ! ( 5000000000 , utxo. amount) ;
3096
+ }
3097
+
3098
+ #[ test]
3099
+ fn test_build_leader_block_commit_tx ( ) {
3100
+ let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
3101
+ let keychain = Keychain :: default ( miner_seed. clone ( ) ) ;
3102
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3103
+
3104
+ let mut config = Config :: default ( ) ;
3105
+ config. burnchain . magic_bytes = "T3" . as_bytes ( ) . into ( ) ;
3106
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3107
+ config. burnchain . username = Some ( "user" . to_owned ( ) ) ;
3108
+ config. burnchain . password = Some ( "12345" . to_owned ( ) ) ;
3109
+
3110
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3111
+ btcd_controller. start_bitcoind ( ) . unwrap ( ) ;
3112
+
3113
+ let mut btc_controller = BitcoinRegtestController :: new ( config, None ) ;
3114
+ btc_controller. bootstrap_chain ( 101 ) ;
3115
+
3116
+ btc_controller. connect_dbs ( ) . expect ( "Cannot initialize dbs!" ) ;
3117
+
3118
+ let tip = btc_controller
3119
+ . get_burnchain ( )
3120
+ . open_burnchain_db ( false )
3121
+ . unwrap ( )
3122
+ . get_canonical_chain_tip ( ) ;
3123
+ info ! ( "{:?}" , tip) ;
3124
+
3125
+
3126
+ let mut signer = keychain. generate_op_signer ( ) ;
3127
+
3128
+ let commit_op = LeaderBlockCommitOp {
3129
+ block_header_hash : BlockHeaderHash :: from_hex (
3130
+ "e88c3d30cb59a142f83de3b27f897a43bbb0f13316911bb98a3229973dae32af" ,
3131
+ )
3132
+ . unwrap ( ) ,
3133
+ new_seed : VRFSeed :: from_hex (
3134
+ "d5b9f21bc1f40f24e2c101ecd13c55b8619e5e03dad81de2c62a1cc1d8c1b375" ,
3135
+ )
3136
+ . unwrap ( ) ,
3137
+ parent_block_ptr : 2211 , // 0x000008a3
3138
+ parent_vtxindex : 1 , // 0x0001
3139
+ key_block_ptr : 1432 , // 0x00000598
3140
+ key_vtxindex : 1 , // 0x0001
3141
+ memo : vec ! [ 11 ] , // 0x5a >> 3
3142
+
3143
+ burn_fee : 0 ,
3144
+ input : ( Txid ( [ 0x00 ; 32 ] ) , 0 ) ,
3145
+ burn_parent_modulus : 2 , // 0x5a & 0b111
3146
+
3147
+ apparent_sender : BurnchainSigner ( "mgbpit8FvkVJ9kuXY8QSM5P7eibnhcEMBk" . to_string ( ) ) ,
3148
+ commit_outs : vec ! [
3149
+ PoxAddress :: Standard ( StacksAddress :: burn_address( false ) , None ) ,
3150
+ PoxAddress :: Standard ( StacksAddress :: burn_address( false ) , None ) ,
3151
+ ] ,
3152
+
3153
+ treatment : vec ! [ ] ,
3154
+ sunset_burn : 0 ,
3155
+
3156
+ txid : Txid ( [ 0x00 ; 32 ] ) ,
3157
+ vtxindex : 0 ,
3158
+ block_height : 2212 , //FDF
3159
+ burn_header_hash : BurnchainHeaderHash ( [ 0x01 ; 32 ] ) ,
3160
+ } ;
3161
+
3162
+ let tx = btc_controller
3163
+ . build_leader_block_commit_tx ( StacksEpochId :: Epoch31 , commit_op, & mut signer, 0 )
3164
+ . expect ( "Build leader block commit should work" ) ;
3165
+
3166
+ assert_eq ! ( 1 , tx. version) ;
3167
+ assert_eq ! ( 0 , tx. lock_time) ;
3168
+ assert_eq ! ( 1 , tx. input. len( ) ) ;
3169
+ assert_eq ! ( 4 , tx. output. len( ) ) ;
3170
+ }
3021
3171
}
0 commit comments