Skip to content

Commit af011f9

Browse files
committed
pytest: make spendable test for askrene work properly, give a better name.
Based on great test case from https://github.com/daywalker90 ``` E AssertionError: assert {'107x2x0/1': 'Path total 285720859 > spendable 285718000', '108x1x0/1': 'Path total 384721849 > spendable 384718000'} == {} E Left contains 2 more items: E {'107x2x0/1': 'Path total 285720859 > spendable 285718000', E '108x1x0/1': 'Path total 384721849 > spendable 384718000'} E Full diff: E { E - , E + '107x2x0/1': 'Path total 285720859 > spendable 285718000', E + '108x1x0/1': 'Path total 384721849 > spendable 384718000', E } ``` Signed-off-by: Rusty Russell <[email protected]>
1 parent 4e309dc commit af011f9

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

tests/test_askrene.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ def test_fees_dont_exceed_constraints(node_factory):
451451
assert amount <= max_msat
452452

453453

454-
def test_mpp_pay2(node_factory, bitcoind):
454+
@pytest.mark.xfail(strict=True)
455+
def test_live_spendable(node_factory, bitcoind):
456+
"""Test we don't exceed spendable limits on a real network on nodes"""
455457
l1, l2, l3 = node_factory.get_nodes(3)
456458
l1.fundwallet(10_000_000)
457459
l2.fundwallet(10_000_000)
@@ -480,11 +482,22 @@ def test_mpp_pay2(node_factory, bitcoind):
480482

481483
# Don't exceed spendable_msat
482484
maxes = {}
483-
for chan in l1.rpc.listpeerchannels()['channels']:
484-
maxes["{}/{}".format(chan['short_channel_id'], chan['direction'])] = chan['spendable_msat']
485-
486-
for r in routes['routes']:
487-
for p in r['path']:
488-
scidd = "{}/{}".format(p['short_channel_id'], p['direction'])
489-
if scidd in maxes:
490-
assert p['amount_msat'] <= maxes[scidd]
485+
for chan in l1.rpc.listpeerchannels()["channels"]:
486+
maxes["{}/{}".format(chan["short_channel_id"], chan["direction"])] = chan[
487+
"spendable_msat"
488+
]
489+
490+
path_total = {}
491+
for r in routes["routes"]:
492+
key = "{}/{}".format(
493+
r["path"][0]["short_channel_id"], r["path"][0]["direction"]
494+
)
495+
path_total[key] = path_total.get(key, 0) + r["path"][0]["amount_msat"]
496+
497+
exceeded = {}
498+
for scidd in maxes.keys():
499+
if scidd in path_total:
500+
if path_total[scidd] > maxes[scidd]:
501+
exceeded[scidd] = f"Path total {path_total[scidd]} > spendable {maxes[scidd]}"
502+
503+
assert exceeded == {}

0 commit comments

Comments
 (0)