Skip to content

Commit 28f2dac

Browse files
committed
Add anchors coverage to chanmon_claim_value_coop_close
1 parent 52d76f9 commit 28f2dac

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lightning/src/ln/monitor_tests.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,19 @@ fn revoked_output_htlc_resolution_timing() {
153153
expect_payment_failed!(nodes[1], payment_hash_1, false);
154154
}
155155

156-
#[test]
157-
fn chanmon_claim_value_coop_close() {
156+
fn do_chanmon_claim_value_coop_close(anchors: bool) {
158157
// Tests `get_claimable_balances` returns the correct values across a simple cooperative claim.
159158
// Specifically, this tests that the channel non-HTLC balances show up in
160159
// `get_claimable_balances` until the cooperative claims have confirmed and generated a
161160
// `SpendableOutputs` event, and no longer.
162161
let chanmon_cfgs = create_chanmon_cfgs(2);
163162
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
164-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
163+
let mut user_config = test_default_channel_config();
164+
if anchors {
165+
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
166+
user_config.manually_accept_inbound_channels = true;
167+
}
168+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(user_config), Some(user_config)]);
165169
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
166170

167171
let (_, _, chan_id, funding_tx) =
@@ -172,8 +176,10 @@ fn chanmon_claim_value_coop_close() {
172176
let chan_feerate = get_feerate!(nodes[0], nodes[1], chan_id) as u64;
173177
let channel_type_features = get_channel_type_features!(nodes[0], nodes[1], chan_id);
174178

179+
let commitment_tx_fee = chan_feerate * channel::commitment_tx_base_weight(&channel_type_features) / 1000;
180+
let anchor_outputs_value = if anchors { channel::ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 };
175181
assert_eq!(vec![Balance::ClaimableOnChannelClose {
176-
amount_satoshis: 1_000_000 - 1_000 - chan_feerate * channel::commitment_tx_base_weight(&channel_type_features) / 1000
182+
amount_satoshis: 1_000_000 - 1_000 - commitment_tx_fee - anchor_outputs_value
177183
}],
178184
nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances());
179185
assert_eq!(vec![Balance::ClaimableOnChannelClose { amount_satoshis: 1_000, }],
@@ -208,7 +214,7 @@ fn chanmon_claim_value_coop_close() {
208214
assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
209215

210216
assert_eq!(vec![Balance::ClaimableAwaitingConfirmations {
211-
amount_satoshis: 1_000_000 - 1_000 - chan_feerate * channel::commitment_tx_base_weight(&channel_type_features) / 1000,
217+
amount_satoshis: 1_000_000 - 1_000 - commitment_tx_fee - anchor_outputs_value,
212218
confirmation_height: nodes[0].best_block_info().1 + ANTI_REORG_DELAY - 1,
213219
}],
214220
nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances());
@@ -250,6 +256,12 @@ fn chanmon_claim_value_coop_close() {
250256
check_closed_event!(nodes[1], 1, ClosureReason::CooperativeClosure, [nodes[0].node.get_our_node_id()], 1000000);
251257
}
252258

259+
#[test]
260+
fn chanmon_claim_value_coop_close() {
261+
do_chanmon_claim_value_coop_close(false);
262+
do_chanmon_claim_value_coop_close(true);
263+
}
264+
253265
fn sorted_vec<T: Ord>(mut v: Vec<T>) -> Vec<T> {
254266
v.sort_unstable();
255267
v

0 commit comments

Comments
 (0)