Skip to content

Commit 83ea0d2

Browse files
committed
test: check flipped channel policies when comparing against mainnet
1 parent 6b83e3b commit 83ea0d2

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/warnet/lnchannel.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(
4747
self.node2_fee_rate_milli_msat = node2_fee_rate_milli_msat
4848
self.node1_time_lock_delta = node1_time_lock_delta
4949
self.node2_time_lock_delta = node2_time_lock_delta
50-
self.logger = logging.getLogger("lnchannel")
50+
self.logger = logging.getLogger("lnchan")
5151

5252
def __str__(self) -> str:
5353
return (
@@ -67,6 +67,28 @@ def __str__(self) -> str:
6767
f"time_lock_delta={self.node2_time_lock_delta}))"
6868
)
6969

70+
# Only used to compare warnet channels imported from a mainnet source file
71+
# because pubkeys are unpredictable and node 1/2 might be swapped
72+
def flip(self) -> "LNChannel":
73+
return LNChannel(
74+
# Keep the old pubkeys so the constructor doesn't just flip it back
75+
node1_pub=self.node1_pub,
76+
node2_pub=self.node2_pub,
77+
capacity_msat=self.capacity_msat,
78+
short_chan_id=self.short_chan_id,
79+
# Flip the policies
80+
node1_min_htlc=self.node2_min_htlc,
81+
node2_min_htlc=self.node1_min_htlc,
82+
node1_max_htlc=self.node2_max_htlc,
83+
node2_max_htlc=self.node1_max_htlc,
84+
node1_base_fee_msat=self.node2_base_fee_msat,
85+
node2_base_fee_msat=self.node1_base_fee_msat,
86+
node1_fee_rate_milli_msat=self.node2_fee_rate_milli_msat,
87+
node2_fee_rate_milli_msat=self.node1_fee_rate_milli_msat,
88+
node1_time_lock_delta=self.node2_time_lock_delta,
89+
node2_time_lock_delta=self.node1_time_lock_delta,
90+
)
91+
7092
def policy_match(self, ch2: "LNChannel") -> bool:
7193
assert isinstance(ch2, LNChannel)
7294

test/graph_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ def verify_ln_channel_policies(self):
9898
expected_chan = LNDNode.lnchannel_from_json(expected[chan_index])
9999
actual_chan = LNDNode.lnchannel_from_json(actual_chan_json)
100100
if not expected_chan.channel_match(actual_chan):
101-
raise Exception(
102-
f"Channel policy doesn't match source: {actual_chan.short_chan_id}\n"
103-
+ f"Actual:\n{actual_chan}\n"
104-
+ f"Expected:\n{expected_chan}\n"
101+
self.log.info(
102+
f"Channel {chan_index} policy mismatch, testing flipped channel: {actual_chan.short_chan_id}"
105103
)
104+
if not expected_chan.channel_match(actual_chan.flip()):
105+
raise Exception(
106+
f"Channel policy doesn't match source: {actual_chan.short_chan_id}\n"
107+
+ f"Actual:\n{actual_chan}\n"
108+
+ f"Expected:\n{expected_chan}\n"
109+
)
106110

107111

108112
if __name__ == "__main__":

0 commit comments

Comments
 (0)