(node_factory, bitcoind)
| 2240 | |
| 2241 | |
| 2242 | def test_setchannel_state(node_factory, bitcoind): |
| 2243 | # TEST SETUP |
| 2244 | # |
| 2245 | # [l1] --> [l2] --> [l3] |
| 2246 | # |
| 2247 | # Initiate channel [l2,l3] and try to set feerates other states than |
| 2248 | # CHANNELD_NORMAL or CHANNELD_AWAITING_LOCKIN. Should raise error. |
| 2249 | # Use l1 to make a forward through l2/l3 for testing. |
| 2250 | DEF_BASE = 0 |
| 2251 | DEF_PPM = 0 |
| 2252 | |
| 2253 | l1, l2, l3 = node_factory.get_nodes(3, opts={ |
| 2254 | 'fee-base': DEF_BASE, |
| 2255 | 'fee-per-satoshi': DEF_PPM |
| 2256 | }) |
| 2257 | |
| 2258 | # connection and funding |
| 2259 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 2260 | l1.fundchannel(l2, 1000000, wait_for_active=True) |
| 2261 | l2.rpc.connect(l3.info['id'], 'localhost', l3.port) |
| 2262 | scid, _ = l2.fundchannel(l3, 1000000, wait_for_active=False) |
| 2263 | |
| 2264 | # try setting the fee in state AWAITING_LOCKIN should be possible |
| 2265 | # assert(l2.channel_state(l3) == "CHANNELD_AWAITING_LOCKIN") |
| 2266 | result = l2.rpc.setchannel(l3.info['id'], 42, 0) |
| 2267 | assert(result['channels'][0]['peer_id'] == l3.info['id']) |
| 2268 | # cid = result['channels'][0]['channel_id'] |
| 2269 | |
| 2270 | # test routing correct new fees once routing is established |
| 2271 | mine_funding_to_announce(bitcoind, [l1, l2, l3]) |
| 2272 | |
| 2273 | l1.wait_for_route(l3) |
| 2274 | inv = l3.rpc.invoice(100000, 'test_setchannel_state', 'desc')['bolt11'] |
| 2275 | result = l1.dev_pay(inv, dev_use_shadow=False) |
| 2276 | assert result['status'] == 'complete' |
| 2277 | assert result['amount_sent_msat'] == 100042 |
| 2278 | |
| 2279 | # Disconnect and unilaterally close from l3 to l2 |
| 2280 | l3.rpc.disconnect(l2.info['id'], force=True) |
| 2281 | result = l3.rpc.close(scid, 1) |
| 2282 | assert result['type'] == 'unilateral' |
| 2283 | |
| 2284 | # wait for l2 to see unilateral close via bitcoin network |
| 2285 | while l2.channel_state(l3) == "CHANNELD_NORMAL": |
| 2286 | bitcoind.generate_block(1) |
| 2287 | # assert l2.channel_state(l3) == "FUNDING_SPEND_SEEN" |
| 2288 | |
| 2289 | # Try to setchannel in order to raise expected error. |
| 2290 | # To reduce false positive flakes, only test if state is not NORMAL anymore. |
| 2291 | with pytest.raises(RpcError, match=r'-1.*'): |
| 2292 | # l2.rpc.setchannel(l3.info['id'], 10, 1) |
| 2293 | l2.rpc.setchannel(l3.info['id'], 10, 1) |
| 2294 | |
| 2295 | |
| 2296 | def test_setchannel_routing(node_factory, bitcoind): |
nothing calls this directly
no test coverage detected