Test multiple channels between same nodes
(node_factory, executor, bitcoind)
| 4045 | @pytest.mark.openchannel('v1') |
| 4046 | @pytest.mark.openchannel('v2') |
| 4047 | def test_multichan(node_factory, executor, bitcoind): |
| 4048 | """Test multiple channels between same nodes""" |
| 4049 | l1, l2, l3 = node_factory.line_graph(3, opts={'may_reconnect': True}) |
| 4050 | |
| 4051 | scid12 = l1.get_channel_scid(l2) |
| 4052 | scid23a = l2.get_channel_scid(l3) |
| 4053 | |
| 4054 | # Now fund *second* channel l2->l3 (slightly larger) |
| 4055 | bitcoind.rpc.sendtoaddress(l2.rpc.newaddr()['bech32'], 0.1) |
| 4056 | bitcoind.generate_block(1) |
| 4057 | sync_blockheight(bitcoind, [l1, l2, l3]) |
| 4058 | l2.rpc.fundchannel(l3.info['id'], '0.01001btc') |
| 4059 | assert(len(only_one(l2.rpc.listpeers(l3.info['id'])['peers'])['channels']) == 2) |
| 4060 | assert(len(only_one(l3.rpc.listpeers(l2.info['id'])['peers'])['channels']) == 2) |
| 4061 | |
| 4062 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 4063 | sync_blockheight(bitcoind, [l1, l2, l3]) |
| 4064 | # Make sure new channel is also CHANNELD_NORMAL |
| 4065 | wait_for(lambda: [c['state'] for c in only_one(l2.rpc.listpeers(l3.info['id'])['peers'])['channels']] == ["CHANNELD_NORMAL", "CHANNELD_NORMAL"]) |
| 4066 | |
| 4067 | # Dance around to get the *other* scid. |
| 4068 | wait_for(lambda: all(['short_channel_id' in c for c in l3.rpc.listpeers()['peers'][0]['channels']])) |
| 4069 | scids = [c['short_channel_id'] for c in l3.rpc.listpeers()['peers'][0]['channels']] |
| 4070 | assert len(scids) == 2 |
| 4071 | |
| 4072 | if scids[0] == scid23a: |
| 4073 | scid23b = scids[1] |
| 4074 | else: |
| 4075 | assert scids[1] == scid23a |
| 4076 | scid23b = scids[0] |
| 4077 | |
| 4078 | # Test paying by each, |
| 4079 | route = [{'amount_msat': 100001001, |
| 4080 | 'id': l2.info['id'], |
| 4081 | 'delay': 11, |
| 4082 | # Unneeded |
| 4083 | 'channel': scid12}, |
| 4084 | {'amount_msat': 100000000, |
| 4085 | 'id': l3.info['id'], |
| 4086 | 'delay': 5, |
| 4087 | 'channel': scid23a}] |
| 4088 | before = only_one(l2.rpc.listpeers(l3.info['id'])['peers'])['channels'] |
| 4089 | inv1 = l3.rpc.invoice(100000000, "invoice", "invoice") |
| 4090 | l1.rpc.sendpay(route, inv1['payment_hash'], payment_secret=inv1['payment_secret']) |
| 4091 | l1.rpc.waitsendpay(inv1['payment_hash']) |
| 4092 | # Wait until HTLCs fully settled |
| 4093 | wait_for(lambda: [c['htlcs'] for c in only_one(l2.rpc.listpeers(l3.info['id'])['peers'])['channels']] == [[], []]) |
| 4094 | after = only_one(l2.rpc.listpeers(l3.info['id'])['peers'])['channels'] |
| 4095 | |
| 4096 | if before[0]['short_channel_id'] == scid23a: |
| 4097 | chan23a_idx = 0 |
| 4098 | chan23b_idx = 1 |
| 4099 | else: |
| 4100 | chan23a_idx = 1 |
| 4101 | chan23b_idx = 0 |
| 4102 | |
| 4103 | # Gratuitous reconnect |
| 4104 | with pytest.raises(RpcError, match=r"Peer has \(at least one\) channel"): |
nothing calls this directly
no test coverage detected