Skip to content

Commit 301de11

Browse files
committed
test: add tests stacks-network#6157
1 parent 52fcf78 commit 301de11

File tree

2 files changed

+151
-1
lines changed

2 files changed

+151
-1
lines changed

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

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,9 @@ mod tests {
28322832
use stacks_common::util::hash::to_hex;
28332833
use stacks_common::util::secp256k1::Secp256k1PrivateKey;
28342834

2835+
use crate::tests::bitcoin_regtest::BitcoinCoreController;
2836+
use crate::Keychain;
2837+
28352838
use super::*;
28362839

28372840
#[test]
@@ -3007,4 +3010,151 @@ mod tests {
30073010

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

testnet/stacks-node/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use crate::tests::neon_integrations::{get_chain_info, next_block_and_wait};
4444
use crate::BitcoinRegtestController;
4545

4646
mod atlas;
47-
mod bitcoin_regtest;
47+
pub mod bitcoin_regtest;
4848
mod epoch_205;
4949
mod epoch_21;
5050
mod epoch_22;

0 commit comments

Comments
 (0)