Skip to content

Commit 41491db

Browse files
committed
test: improve utxo tests
1 parent 4f3c0f5 commit 41491db

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ mod tests {
30453045
}
30463046

30473047
#[test]
3048-
fn test_get_all_utxos() {
3048+
fn test_get_all_utxos_with_one_confirmed() {
30493049
let miner_seed = vec![1, 1, 1, 1];
30503050
let keychain = Keychain::default(miner_seed.clone());
30513051
let miner_pubkey = keychain.get_pub_key();
@@ -3066,11 +3066,13 @@ mod tests {
30663066

30673067
let utxos = btc_controller.get_all_utxos(&miner_pubkey);
30683068
assert_eq!(1, utxos.len());
3069+
let utxo = &utxos[0];
3070+
assert_eq!(101, utxo.confirmations);
3071+
assert_eq!(5000000000, utxo.amount);
30693072
}
30703073

30713074
#[test]
3072-
//NOTE: STALL if burn block at block_height doesn't exist....
3073-
fn test_get_utxos() {
3075+
fn test_get_utxos_ok() {
30743076
let miner_seed = vec![1, 1, 1, 1];
30753077
let keychain = Keychain::default(miner_seed.clone());
30763078
let miner_pubkey = keychain.get_pub_key();
@@ -3089,7 +3091,7 @@ mod tests {
30893091
let btc_controller = BitcoinRegtestController::new(config.clone(), None);
30903092
btc_controller.bootstrap_chain(101);
30913093

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);
30933095

30943096
let uxto_set = utxos.expect("Shouldn't be None!");
30953097
assert_eq!(1, uxto_set.num_utxos());
@@ -3099,6 +3101,45 @@ mod tests {
30993101
assert_eq!(5000000000, utxo.amount);
31003102
}
31013103

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+
31023143
#[test]
31033144
fn test_build_leader_block_commit_tx_ok_with_new_block_commit() {
31043145
let miner_seed = vec![1, 1, 1, 1];

0 commit comments

Comments
 (0)