Add some funds, fund a channel without enough funds
(node_factory, bitcoind)
| 1046 | @pytest.mark.openchannel('v1') |
| 1047 | @pytest.mark.openchannel('v2') |
| 1048 | def test_funding_fail(node_factory, bitcoind): |
| 1049 | """Add some funds, fund a channel without enough funds""" |
| 1050 | # Previous runs with same bitcoind can leave funds! |
| 1051 | max_locktime = 5 * 6 * 24 |
| 1052 | l1 = node_factory.get_node(random_hsm=True, options={'max-locktime-blocks': max_locktime}) |
| 1053 | l2 = node_factory.get_node(options={'watchtime-blocks': max_locktime + 1}) |
| 1054 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 1055 | |
| 1056 | funds = 1000000 |
| 1057 | |
| 1058 | addr = l1.rpc.newaddr()['bech32'] |
| 1059 | l1.bitcoin.rpc.sendtoaddress(addr, funds / 10**8) |
| 1060 | bitcoind.generate_block(1) |
| 1061 | |
| 1062 | # Wait for it to arrive. |
| 1063 | wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0) |
| 1064 | |
| 1065 | # Fail because l1 dislikes l2's huge locktime. |
| 1066 | with pytest.raises(RpcError, match=r'to_self_delay \d+ larger than \d+'): |
| 1067 | l1.rpc.fundchannel(l2.info['id'], int(funds / 10)) |
| 1068 | |
| 1069 | # channels disconnect on failure |
| 1070 | wait_for(lambda: len(l1.rpc.listpeers()['peers']) == 0) |
| 1071 | wait_for(lambda: len(l2.rpc.listpeers()['peers']) == 0) |
| 1072 | |
| 1073 | # Restart l2 without ridiculous locktime. |
| 1074 | del l2.daemon.opts['watchtime-blocks'] |
| 1075 | l2.restart() |
| 1076 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 1077 | |
| 1078 | # We don't have enough left to cover fees if we try to spend it all. |
| 1079 | with pytest.raises(RpcError, match=r'not afford'): |
| 1080 | l1.rpc.fundchannel(l2.info['id'], funds) |
| 1081 | |
| 1082 | # Should still be connected (we didn't contact the peer) |
| 1083 | assert only_one(l1.rpc.listpeers()['peers'])['connected'] |
| 1084 | l2.daemon.wait_for_log('Handed peer, entering loop') |
| 1085 | assert only_one(l2.rpc.listpeers()['peers'])['connected'] |
| 1086 | |
| 1087 | # This works. |
| 1088 | l1.rpc.fundchannel(l2.info['id'], int(funds / 10)) |
| 1089 | |
| 1090 | |
| 1091 | @pytest.mark.openchannel('v1') |
nothing calls this directly
no test coverage detected