|
1 | 1 | from fixtures import * # noqa: F401,F403
|
2 | 2 | from pyln.client import RpcError, Millisatoshi
|
3 |
| -from utils import only_one, wait_for, mine_funding_to_announce |
| 3 | +from utils import only_one, wait_for, mine_funding_to_announce, sync_blockheight |
4 | 4 | import pytest
|
5 | 5 | import random
|
6 | 6 | import time
|
| 7 | +import json |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def test_simple(node_factory):
|
@@ -225,3 +226,82 @@ def test_limits(node_factory):
|
225 | 226 | invoice = only_one(l6.rpc.listinvoices('inv2')['invoices'])
|
226 | 227 | assert isinstance(invoice['amount_received_msat'], Millisatoshi)
|
227 | 228 | assert invoice['amount_received_msat'] >= Millisatoshi('800000sat')
|
| 229 | + |
| 230 | + |
| 231 | +def start_channels(connections): |
| 232 | + nodes = list() |
| 233 | + for src, dst, fundamount in connections: |
| 234 | + nodes.append(src) |
| 235 | + nodes.append(dst) |
| 236 | + src.rpc.connect(dst.info['id'], 'localhost', dst.port) |
| 237 | + |
| 238 | + bitcoind = nodes[0].bitcoin |
| 239 | + # If we got here, we want to fund channels |
| 240 | + for src, dst, fundamount in connections: |
| 241 | + addr = src.rpc.newaddr()['bech32'] |
| 242 | + bitcoind.rpc.sendtoaddress(addr, (fundamount + 1000000) / 10**8) |
| 243 | + |
| 244 | + bitcoind.generate_block(1) |
| 245 | + sync_blockheight(bitcoind, nodes) |
| 246 | + txids = [] |
| 247 | + for src, dst, fundamount in connections: |
| 248 | + txids.append(src.rpc.fundchannel(dst.info['id'], fundamount, |
| 249 | + announce=True)['txid']) |
| 250 | + |
| 251 | + # Confirm all channels and wait for them to become usable |
| 252 | + bitcoind.generate_block(1, wait_for_mempool=txids) |
| 253 | + scids = [] |
| 254 | + for src, dst, fundamount in connections: |
| 255 | + wait_for(lambda: src.channel_state(dst) == 'CHANNELD_NORMAL') |
| 256 | + scid = src.get_channel_scid(dst) |
| 257 | + scids.append(scid) |
| 258 | + |
| 259 | + bitcoind.generate_block(5) |
| 260 | + |
| 261 | + # Make sure everyone sees all channels, all other nodes |
| 262 | + for n in nodes: |
| 263 | + for scid in scids: |
| 264 | + n.wait_channel_active(scid) |
| 265 | + |
| 266 | + # Make sure we have all node announcements, too |
| 267 | + for n in nodes: |
| 268 | + for n2 in nodes: |
| 269 | + wait_for(lambda: 'alias' in only_one(n.rpc.listnodes(n2.info['id'])['nodes'])) |
| 270 | + |
| 271 | + |
| 272 | +def test_hardmpp(node_factory): |
| 273 | + ''' |
| 274 | + Topology: |
| 275 | + 1----2----4 |
| 276 | + | | |
| 277 | + 3----5----6 |
| 278 | + This a payment that fails if pending HTLCs are not taken into account when |
| 279 | + we build the network capacities. |
| 280 | + ''' |
| 281 | + opts = [ |
| 282 | + {'disable-mpp': None, 'fee-base': 0, 'fee-per-satoshi': 0}, |
| 283 | + ] |
| 284 | + l1, l2, l3, l4, l5, l6 = node_factory.get_nodes(6, opts=opts * 6) |
| 285 | + start_channels([(l1, l2, 10000000), (l2, l4, 3000000), (l4, l6, 10000000), |
| 286 | + (l1, l3, 10000000), (l3, l5, 1000000), (l5, l6, 10000000)]) |
| 287 | + |
| 288 | + with open('/tmp/l1-chans.txt', 'w') as f: |
| 289 | + print(json.dumps(l1.rpc.listchannels()), file=f) |
| 290 | + |
| 291 | + inv = l4.rpc.invoice('any', 'any', 'description') |
| 292 | + l2.rpc.call('pay', {'bolt11': inv['bolt11'], 'amount_msat': 2000000000}) |
| 293 | + l2.wait_for_htlcs() |
| 294 | + assert l4.rpc.listinvoices()["invoices"][0]["amount_received_msat"] == 2000000000 |
| 295 | + |
| 296 | + with open('/tmp/l2-peerchan.txt', 'w') as f: |
| 297 | + print(json.dumps(l2.rpc.listpeerchannels()), file=f) |
| 298 | + with open('/tmp/l3-peerchan.txt', 'w') as f: |
| 299 | + print(json.dumps(l3.rpc.listpeerchannels()), file=f) |
| 300 | + |
| 301 | + inv2 = l6.rpc.invoice("1800000sat", "inv2", 'description') |
| 302 | + l1.rpc.call( |
| 303 | + 'renepay', {'invstring': inv2['bolt11']}) |
| 304 | + l1.wait_for_htlcs() |
| 305 | + invoice = only_one(l6.rpc.listinvoices('inv2')['invoices']) |
| 306 | + assert isinstance(invoice['amount_received_msat'], Millisatoshi) |
| 307 | + assert invoice['amount_received_msat'] >= Millisatoshi('1800000sat') |
0 commit comments