Skip to content

Commit b4580fc

Browse files
committed
Take multiple spent-txn to check_spends! in functional_tests
This reintroduces a check_spends!() removed in 3d640da due to check_spends not being able to check a transaction which spends multiple other transactions. It also simplifies a few calls in claim_htlc_outputs_single_tx by using check_spends!().
1 parent 7feb88b commit b4580fc

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,15 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a
403403
}
404404

405405
macro_rules! check_spends {
406-
($tx: expr, $spends_tx: expr) => {
406+
($tx: expr, $($spends_txn: expr),*) => {
407407
{
408408
$tx.verify(|out_point| {
409-
if out_point.txid == $spends_tx.txid() {
410-
$spends_tx.output.get(out_point.vout as usize).cloned()
411-
} else {
412-
None
413-
}
409+
$(
410+
if out_point.txid == $spends_txn.txid() {
411+
return $spends_txn.output.get(out_point.vout as usize).cloned()
412+
}
413+
)*
414+
None
414415
}).unwrap();
415416
}
416417
}

lightning/src/ln/functional_tests.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,16 +2360,9 @@ fn claim_htlc_outputs_single_tx() {
23602360
assert_eq!(node_txn[2].input.len(), 1);
23612361
assert_eq!(node_txn[3].input.len(), 1);
23622362
assert_eq!(node_txn[4].input.len(), 1);
2363-
fn get_txout(out_point: &BitcoinOutPoint, tx: &Transaction) -> Option<TxOut> {
2364-
if out_point.txid == tx.txid() {
2365-
tx.output.get(out_point.vout as usize).cloned()
2366-
} else {
2367-
None
2368-
}
2369-
}
2370-
node_txn[2].verify(|out|get_txout(out, &revoked_local_txn[0])).unwrap();
2371-
node_txn[3].verify(|out|get_txout(out, &revoked_local_txn[0])).unwrap();
2372-
node_txn[4].verify(|out|get_txout(out, &revoked_local_txn[0])).unwrap();
2363+
check_spends!(node_txn[2], revoked_local_txn[0]);
2364+
check_spends!(node_txn[3], revoked_local_txn[0]);
2365+
check_spends!(node_txn[4], revoked_local_txn[0]);
23732366

23742367
let mut witness_lens = BTreeSet::new();
23752368
witness_lens.insert(node_txn[2].input[0].witness.last().unwrap().len());
@@ -6924,13 +6917,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
69246917
// Verify claim tx are spending revoked HTLC txn
69256918
assert_eq!(node_txn[4].input.len(), 2);
69266919
assert_eq!(node_txn[4].output.len(), 1);
6927-
if node_txn[4].input[0].previous_output.txid == revoked_htlc_txn[0].txid() {
6928-
assert_eq!(node_txn[4].input[1].previous_output.txid, revoked_htlc_txn[1].txid());
6929-
} else if node_txn[4].input[0].previous_output.txid == revoked_htlc_txn[1].txid() {
6930-
assert_eq!(node_txn[4].input[1].previous_output.txid, revoked_htlc_txn[0].txid());
6931-
} else {
6932-
panic!();
6933-
}
6920+
check_spends!(node_txn[4], revoked_htlc_txn[0], revoked_htlc_txn[1]);
69346921
first = node_txn[4].txid();
69356922
// Store both feerates for later comparison
69366923
let fee_1 = revoked_htlc_txn[0].output[0].value + revoked_htlc_txn[1].output[0].value - node_txn[4].output[0].value;
@@ -6954,24 +6941,14 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
69546941

69556942
// Few more blocks to confirm penalty txn
69566943
let header_135 = connect_blocks(&nodes[0].block_notifier, 5, 130, true, header_130.bitcoin_hash());
6957-
{
6958-
let mut node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
6959-
assert_eq!(node_txn.len(), 0);
6960-
node_txn.clear();
6961-
}
6944+
assert!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().is_empty());
69626945
let header_144 = connect_blocks(&nodes[0].block_notifier, 9, 135, true, header_135);
69636946
let node_txn = {
69646947
let mut node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
69656948
assert_eq!(node_txn.len(), 1);
69666949

69676950
assert_eq!(node_txn[0].input.len(), 2);
6968-
if node_txn[0].input[0].previous_output.txid == revoked_htlc_txn[0].txid() {
6969-
assert_eq!(node_txn[0].input[1].previous_output.txid, revoked_htlc_txn[1].txid());
6970-
} else if node_txn[0].input[0].previous_output.txid == revoked_htlc_txn[1].txid() {
6971-
assert_eq!(node_txn[0].input[1].previous_output.txid, revoked_htlc_txn[0].txid());
6972-
} else {
6973-
panic!();
6974-
}
6951+
check_spends!(node_txn[0], revoked_htlc_txn[0], revoked_htlc_txn[1]);
69756952
//// Verify bumped tx is different and 25% bump heuristic
69766953
assert_ne!(first, node_txn[0].txid());
69776954
let fee_2 = revoked_htlc_txn[0].output[0].value + revoked_htlc_txn[1].output[0].value - node_txn[0].output[0].value;

0 commit comments

Comments
 (0)