Skip to content

Commit fa2205b

Browse files
committed
test: add commit rbf case
1 parent 5236315 commit fa2205b

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,4 +3233,82 @@ mod tests {
32333233
resubmit.unwrap_err()
32343234
);
32353235
}
3236+
3237+
#[test]
3238+
fn test_build_leader_block_commit_tx_ok_rbf_block_commit() {
3239+
let miner_seed = vec![1, 1, 1, 1];
3240+
let keychain = Keychain::default(miner_seed.clone());
3241+
let miner_pubkey = keychain.get_pub_key();
3242+
let mut signer = keychain.generate_op_signer();
3243+
let burn_signer = keychain.get_burnchain_signer();
3244+
3245+
let mut config = Config::default();
3246+
config.burnchain.magic_bytes = "T3".as_bytes().into();
3247+
config.burnchain.local_mining_public_key = Some(miner_pubkey.to_hex());
3248+
config.burnchain.username = Some("user".to_owned());
3249+
config.burnchain.password = Some("12345".to_owned());
3250+
3251+
let mut btcd_controller = BitcoinCoreController::new(config.clone());
3252+
btcd_controller
3253+
.start_bitcoind()
3254+
.expect("bitcoind should be started!");
3255+
3256+
let mut btc_controller = BitcoinRegtestController::new(config, None);
3257+
btc_controller.bootstrap_chain(101);
3258+
btc_controller
3259+
.connect_dbs()
3260+
.expect("Cannot initialize dbs!");
3261+
3262+
let mut commit_op = LeaderBlockCommitOp {
3263+
block_header_hash: BlockHeaderHash::from_hex(
3264+
"e88c3d30cb59a142f83de3b27f897a43bbb0f13316911bb98a3229973dae32af",
3265+
)
3266+
.unwrap(),
3267+
new_seed: VRFSeed::from_hex(
3268+
"d5b9f21bc1f40f24e2c101ecd13c55b8619e5e03dad81de2c62a1cc1d8c1b375",
3269+
)
3270+
.unwrap(),
3271+
parent_block_ptr: 2211, // 0x000008a3
3272+
parent_vtxindex: 1, // 0x0001
3273+
key_block_ptr: 1432, // 0x00000598
3274+
key_vtxindex: 1, // 0x0001
3275+
memo: vec![11], // 0x5a >> 3
3276+
3277+
burn_fee: 0,
3278+
input: (Txid([0x00; 32]), 0),
3279+
burn_parent_modulus: 2, // 0x5a & 0b111
3280+
3281+
apparent_sender: burn_signer,
3282+
commit_outs: vec![
3283+
PoxAddress::Standard(StacksAddress::burn_address(false), None),
3284+
PoxAddress::Standard(StacksAddress::burn_address(false), None),
3285+
],
3286+
3287+
treatment: vec![],
3288+
sunset_burn: 0,
3289+
3290+
txid: Txid([0x00; 32]),
3291+
vtxindex: 0,
3292+
block_height: 2212,
3293+
burn_header_hash: BurnchainHeaderHash([0x01; 32]),
3294+
};
3295+
3296+
let _first_tx_ok = btc_controller
3297+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op.clone(), &mut signer, 0)
3298+
.expect("Build leader block commit should work");
3299+
3300+
//re-gen signer othewise fails because it will be disposed during previous commit tx.
3301+
let mut signer = keychain.generate_op_signer();
3302+
//small change to the commit op payload
3303+
commit_op.burn_fee = 2;
3304+
3305+
let rbf_tx = btc_controller
3306+
.build_leader_block_commit_tx(StacksEpochId::Epoch31, commit_op, &mut signer, 0)
3307+
.expect("Commit tx should be rbf-ed");
3308+
3309+
assert_eq!(1, rbf_tx.version);
3310+
assert_eq!(0, rbf_tx.lock_time);
3311+
assert_eq!(1, rbf_tx.input.len());
3312+
assert_eq!(4, rbf_tx.output.len());
3313+
}
32363314
}

0 commit comments

Comments
 (0)