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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-08-23 04:23:19 +09:30
parent 4e309dc478
commit af011f9dac

View file

@ -451,7 +451,9 @@ def test_fees_dont_exceed_constraints(node_factory):
assert amount <= max_msat
def test_mpp_pay2(node_factory, bitcoind):
@pytest.mark.xfail(strict=True)
def test_live_spendable(node_factory, bitcoind):
"""Test we don't exceed spendable limits on a real network on nodes"""
l1, l2, l3 = node_factory.get_nodes(3)
l1.fundwallet(10_000_000)
l2.fundwallet(10_000_000)
@ -480,11 +482,22 @@ def test_mpp_pay2(node_factory, bitcoind):
# Don't exceed spendable_msat
maxes = {}
for chan in l1.rpc.listpeerchannels()['channels']:
maxes["{}/{}".format(chan['short_channel_id'], chan['direction'])] = chan['spendable_msat']
for chan in l1.rpc.listpeerchannels()["channels"]:
maxes["{}/{}".format(chan["short_channel_id"], chan["direction"])] = chan[
"spendable_msat"
]
for r in routes['routes']:
for p in r['path']:
scidd = "{}/{}".format(p['short_channel_id'], p['direction'])
if scidd in maxes:
assert p['amount_msat'] <= maxes[scidd]
path_total = {}
for r in routes["routes"]:
key = "{}/{}".format(
r["path"][0]["short_channel_id"], r["path"][0]["direction"]
)
path_total[key] = path_total.get(key, 0) + r["path"][0]["amount_msat"]
exceeded = {}
for scidd in maxes.keys():
if scidd in path_total:
if path_total[scidd] > maxes[scidd]:
exceeded[scidd] = f"Path total {path_total[scidd]} > spendable {maxes[scidd]}"
assert exceeded == {}