MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_getroute_exclude

Function test_getroute_exclude

tests/test_gossip.py:1508–1594  ·  view source on GitHub ↗

Test getroute's exclude argument

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1506
1507
1508def test_getroute_exclude(node_factory, bitcoind):
1509 """Test getroute's exclude argument"""
1510 l1, l2, l3, l4, l5 = node_factory.get_nodes(5,
1511 opts={'allow-deprecated-apis': True})
1512 node_factory.join_nodes([l1, l2, l3, l4], wait_for_announce=True)
1513
1514 # This should work
1515 route = l1.rpc.getroute(l4.info['id'], 1, 1)['route']
1516
1517 # l1 id (038194) > l2 id (033845), so direction 1 means l1->l2
1518 chan_l1l2 = route[0]['channel'] + '/1'
1519 chan_l2l1 = route[0]['channel'] + '/0'
1520
1521 # This should not
1522 with pytest.raises(RpcError):
1523 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[chan_l1l2])
1524
1525 # This should also not
1526 with pytest.raises(RpcError):
1527 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[l2.info['id']])
1528
1529 # Blocking the wrong way should be fine.
1530 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[chan_l2l1])
1531
1532 # Now, create an alternate (better) route.
1533 l2.rpc.connect(l4.info['id'], 'localhost', l4.port)
1534 scid, _ = l2.fundchannel(l4, 1000000, wait_for_active=False)
1535 mine_funding_to_announce(bitcoind, [l1, l2, l3, l4, l5])
1536
1537 # We don't wait above, because we care about it hitting l1.
1538 l1.daemon.wait_for_logs([r'update for channel {}/0 now ACTIVE'
1539 .format(scid),
1540 r'update for channel {}/1 now ACTIVE'
1541 .format(scid)])
1542
1543 # l2 id (033845) < l3 id (03cecb), so direction 0 means l2->l3
1544 chan_l2l3 = route[1]['channel'] + '/0'
1545
1546 # l2 id (033845) > l4 id (02287b), so direction 1 means l2->l4
1547 chan_l2l4 = scid + '/1'
1548
1549 # This works
1550 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[chan_l2l3])
1551
1552 # This works
1553 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[chan_l2l4])
1554
1555 # This works
1556 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[l3.info['id']])
1557
1558 # This doesn't
1559 with pytest.raises(RpcError):
1560 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[chan_l2l3, chan_l2l4])
1561
1562 # This doesn't
1563 with pytest.raises(RpcError):
1564 l1.rpc.getroute(l4.info['id'], 1, 1, exclude=[l3.info['id'], chan_l2l4])
1565

Callers

nothing calls this directly

Calls 7

mine_funding_to_announceFunction · 0.90
get_nodesMethod · 0.80
join_nodesMethod · 0.80
getrouteMethod · 0.80
wait_for_logsMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45

Tested by

no test coverage detected