@@ -3045,7 +3045,7 @@ mod tests {
3045
3045
}
3046
3046
3047
3047
#[ test]
3048
- fn test_get_all_utxos ( ) {
3048
+ fn test_get_all_utxos_with_one_confirmed ( ) {
3049
3049
let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
3050
3050
let keychain = Keychain :: default ( miner_seed. clone ( ) ) ;
3051
3051
let miner_pubkey = keychain. get_pub_key ( ) ;
@@ -3066,11 +3066,13 @@ mod tests {
3066
3066
3067
3067
let utxos = btc_controller. get_all_utxos ( & miner_pubkey) ;
3068
3068
assert_eq ! ( 1 , utxos. len( ) ) ;
3069
+ let utxo = & utxos[ 0 ] ;
3070
+ assert_eq ! ( 101 , utxo. confirmations) ;
3071
+ assert_eq ! ( 5000000000 , utxo. amount) ;
3069
3072
}
3070
3073
3071
3074
#[ test]
3072
- //NOTE: STALL if burn block at block_height doesn't exist....
3073
- fn test_get_utxos ( ) {
3075
+ fn test_get_utxos_ok ( ) {
3074
3076
let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
3075
3077
let keychain = Keychain :: default ( miner_seed. clone ( ) ) ;
3076
3078
let miner_pubkey = keychain. get_pub_key ( ) ;
@@ -3089,7 +3091,7 @@ mod tests {
3089
3091
let btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3090
3092
btc_controller. bootstrap_chain ( 101 ) ;
3091
3093
3092
- let utxos = btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & miner_pubkey, 19000 , None , 0 ) ;
3094
+ let utxos = btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & miner_pubkey, 10000 , None , 0 ) ;
3093
3095
3094
3096
let uxto_set = utxos. expect ( "Shouldn't be None!" ) ;
3095
3097
assert_eq ! ( 1 , uxto_set. num_utxos( ) ) ;
@@ -3099,6 +3101,45 @@ mod tests {
3099
3101
assert_eq ! ( 5000000000 , utxo. amount) ;
3100
3102
}
3101
3103
3104
+
3105
+ #[ test]
3106
+ //NOTE: STALL if burn block at block_height doesn't exist....
3107
+ fn test_get_utxos_fails_due_to_filtering ( ) {
3108
+ let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
3109
+ let keychain = Keychain :: default ( miner_seed. clone ( ) ) ;
3110
+ let miner_pubkey = keychain. get_pub_key ( ) ;
3111
+
3112
+ let mut config = Config :: default ( ) ;
3113
+ config. burnchain . magic_bytes = "T3" . as_bytes ( ) . into ( ) ;
3114
+ config. burnchain . local_mining_public_key = Some ( miner_pubkey. to_hex ( ) ) ;
3115
+ config. burnchain . username = Some ( "user" . to_owned ( ) ) ;
3116
+ config. burnchain . password = Some ( "12345" . to_owned ( ) ) ;
3117
+
3118
+ let mut btcd_controller = BitcoinCoreController :: new ( config. clone ( ) ) ;
3119
+ btcd_controller
3120
+ . start_bitcoind ( )
3121
+ . expect ( "bitcoind should be started!" ) ;
3122
+
3123
+ let btc_controller = BitcoinRegtestController :: new ( config. clone ( ) , None ) ;
3124
+ btc_controller. bootstrap_chain ( 101 ) ;
3125
+
3126
+ let too_much_required = 1000000000000000000_u64 ;
3127
+ let utxos = btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & miner_pubkey, too_much_required, None , 0 ) ;
3128
+ assert ! ( utxos. is_none( ) , "None because too much required" ) ;
3129
+
3130
+ let other_pubkey = Secp256k1PublicKey :: from_hex ( "01010101010101100101010101" ) . unwrap ( ) ;
3131
+ let utxos = btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & other_pubkey, too_much_required, None , 0 ) ;
3132
+ assert ! ( utxos. is_none( ) , "None because utxos for other pubkey don't exist" ) ;
3133
+
3134
+ let future_block_height = 1000 ;
3135
+ let utxos = btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & miner_pubkey, too_much_required, None , future_block_height) ;
3136
+ assert ! ( utxos. is_none( ) , "None because utxos for future block height don't exist" ) ;
3137
+
3138
+ let existent_utxo = btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & miner_pubkey, 0 , None , 0 ) . expect ( "utxo set should exist" ) ;
3139
+ let utxos = btc_controller. get_utxos ( StacksEpochId :: Epoch31 , & miner_pubkey, 0 , Some ( existent_utxo) , 0 ) ;
3140
+ assert ! ( utxos. is_none( ) , "None because utxos filtering out existent utxo set" ) ;
3141
+ }
3142
+
3102
3143
#[ test]
3103
3144
fn test_build_leader_block_commit_tx_ok_with_new_block_commit ( ) {
3104
3145
let miner_seed = vec ! [ 1 , 1 , 1 , 1 ] ;
0 commit comments