Skip to content

Commit 4f3c0f5

Browse files
committed
test: add commit rbf case
1 parent 435e06f commit 4f3c0f5

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

0 commit comments

Comments
 (0)