Skip to content

Commit 1618c77

Browse files
committed
Add test_p2a_anchor_values_under_trims_and_rounds
1 parent 6a697b1 commit 1618c77

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

lightning/src/ln/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,7 @@ mod splicing_tests;
125125
#[cfg(any(test, feature = "_externalize_tests"))]
126126
#[allow(unused_mut)]
127127
pub mod update_fee_tests;
128+
#[cfg(test)]
129+
mod zero_fee_commitment_tests;
128130

129131
pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use crate::ln::chan_utils::shared_anchor_script_pubkey;
2+
use crate::ln::functional_test_utils::*;
3+
4+
#[test]
5+
fn test_p2a_anchor_values_under_trims_and_rounds() {
6+
let chanmon_cfgs = create_chanmon_cfgs(2);
7+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
8+
let mut user_cfg = test_default_channel_config();
9+
user_cfg.channel_handshake_config.our_htlc_minimum_msat = 1;
10+
user_cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
11+
user_cfg.manually_accept_inbound_channels = true;
12+
13+
let configs = [Some(user_cfg.clone()), Some(user_cfg)];
14+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &configs);
15+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
16+
17+
let _coinbase_tx = provide_anchor_reserves(&nodes);
18+
19+
let _node_a_id = nodes[0].node.get_our_node_id();
20+
let _node_b_id = nodes[1].node.get_our_node_id();
21+
22+
const CHAN_CAPACITY: u64 = 10_000_000;
23+
let chan_id = create_announced_chan_between_nodes_with_value(
24+
&nodes,
25+
0,
26+
1,
27+
CHAN_CAPACITY,
28+
(CHAN_CAPACITY / 2) * 1000,
29+
)
30+
.2;
31+
32+
macro_rules! p2a_value_test {
33+
([$($node_0_1_amt_msat:expr),*], $expected_p2a_value_sat:expr) => {
34+
p2a_value_test!([$($node_0_1_amt_msat),*], [], $expected_p2a_value_sat)
35+
};
36+
([$($node_0_1_amt_msat:expr),*], [$($node_1_0_amt_msat:expr),*], $expected_p2a_value_sat:expr) => {
37+
let mut node_0_1_hashes = Vec::new();
38+
#[allow(unused_mut)]
39+
let mut node_1_0_hashes = Vec::new();
40+
41+
$(
42+
node_0_1_hashes.push(route_payment(&nodes[0], &[&nodes[1]], $node_0_1_amt_msat).1);
43+
)*
44+
$(
45+
node_1_0_hashes.push(route_payment(&nodes[1], &[&nodes[0]], $node_1_0_amt_msat).1);
46+
)*
47+
let txn = get_local_commitment_txn!(nodes[0], chan_id);
48+
assert_eq!(txn.len(), 1);
49+
assert_eq!(txn[0].output.iter().find(|output| output.script_pubkey == shared_anchor_script_pubkey()).unwrap().value.to_sat(), $expected_p2a_value_sat);
50+
let txn = get_local_commitment_txn!(nodes[1], chan_id);
51+
assert_eq!(txn.len(), 1);
52+
assert_eq!(txn[0].output.iter().find(|output| output.script_pubkey == shared_anchor_script_pubkey()).unwrap().value.to_sat(), $expected_p2a_value_sat);
53+
for hash in node_0_1_hashes {
54+
fail_payment(&nodes[0], &[&nodes[1]], hash);
55+
}
56+
for hash in node_1_0_hashes {
57+
fail_payment(&nodes[1], &[&nodes[0]], hash);
58+
}
59+
};
60+
}
61+
62+
p2a_value_test!([1], 1);
63+
p2a_value_test!([238_000], 238);
64+
p2a_value_test!([238_001], 239);
65+
p2a_value_test!([240_000], 240);
66+
p2a_value_test!([240_001], 240);
67+
p2a_value_test!([353_000], 240);
68+
p2a_value_test!([353_999], 240);
69+
p2a_value_test!([354_000], 0);
70+
p2a_value_test!([354_001], 1);
71+
72+
p2a_value_test!([1, 1], 1);
73+
p2a_value_test!([1, 999], 1);
74+
p2a_value_test!([1, 1000], 2);
75+
p2a_value_test!([354_001], 1);
76+
p2a_value_test!([354_001, 999], 1);
77+
p2a_value_test!([354_001, 1000], 2);
78+
p2a_value_test!([354_001, 1999], 2);
79+
p2a_value_test!([354_002, 1999], 3);
80+
81+
p2a_value_test!([1], [1], 2);
82+
p2a_value_test!([1], [999], 2);
83+
p2a_value_test!([1], [1000], 2);
84+
p2a_value_test!([354_001], 1);
85+
p2a_value_test!([354_001], [999], 2);
86+
p2a_value_test!([354_001], [1000], 2);
87+
p2a_value_test!([354_001], [1999], 3);
88+
p2a_value_test!([354_002], [1999], 3);
89+
90+
p2a_value_test!([353_000], [353_000], 240);
91+
p2a_value_test!([353_001], [353_000], 240);
92+
p2a_value_test!([353_000], [353_001], 240);
93+
p2a_value_test!([353_001], [353_001], 240);
94+
}

0 commit comments

Comments
 (0)