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

Function test_setchannel_state

tests/test_pay.py:2215–2266  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2213
2214
2215def test_setchannel_state(node_factory, bitcoind):
2216 # TEST SETUP
2217 #
2218 # [l1] --> [l2] --> [l3]
2219 #
2220 # Initiate channel [l2,l3] and try to set feerates other states than
2221 # CHANNELD_NORMAL or CHANNELD_AWAITING_LOCKIN. Should raise error.
2222 # Use l1 to make a forward through l2/l3 for testing.
2223 DEF_BASE = 0
2224 DEF_PPM = 0
2225
2226 l1, l2, l3 = node_factory.get_nodes(3, opts={
2227 'fee-base': DEF_BASE,
2228 'fee-per-satoshi': DEF_PPM
2229 })
2230
2231 # connection and funding
2232 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
2233 l1.fundchannel(l2, 1000000, wait_for_active=True)
2234 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
2235 scid, _ = l2.fundchannel(l3, 1000000, wait_for_active=False)
2236
2237 # try setting the fee in state AWAITING_LOCKIN should be possible
2238 # assert(l2.channel_state(l3) == "CHANNELD_AWAITING_LOCKIN")
2239 result = l2.rpc.setchannel(l3.info['id'], 42, 0)
2240 assert(result['channels'][0]['peer_id'] == l3.info['id'])
2241 # cid = result['channels'][0]['channel_id']
2242
2243 # test routing correct new fees once routing is established
2244 mine_funding_to_announce(bitcoind, [l1, l2, l3])
2245
2246 l1.wait_for_route(l3)
2247 inv = l3.rpc.invoice(100000, 'test_setchannel_state', 'desc')['bolt11']
2248 result = l1.dev_pay(inv, dev_use_shadow=False)
2249 assert result['status'] == 'complete'
2250 assert result['amount_sent_msat'] == 100042
2251
2252 # Disconnect and unilaterally close from l3 to l2
2253 l3.rpc.disconnect(l2.info['id'], force=True)
2254 result = l3.rpc.close(scid, 1)
2255 assert result['type'] == 'unilateral'
2256
2257 # wait for l2 to see unilateral close via bitcoin network
2258 while l2.channel_state(l3) == "CHANNELD_NORMAL":
2259 bitcoind.generate_block(1)
2260 # assert l2.channel_state(l3) == "FUNDING_SPEND_SEEN"
2261
2262 # Try to setchannel in order to raise expected error.
2263 # To reduce false positive flakes, only test if state is not NORMAL anymore.
2264 with pytest.raises(RpcError, match=r'-1.*'):
2265 # l2.rpc.setchannel(l3.info['id'], 10, 1)
2266 l2.rpc.setchannel(l3.info['id'], 10, 1)
2267
2268
2269def test_setchannel_routing(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 12

mine_funding_to_announceFunction · 0.90
get_nodesMethod · 0.80
setchannelMethod · 0.80
wait_for_routeMethod · 0.80
channel_stateMethod · 0.80
generate_blockMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
invoiceMethod · 0.45
dev_payMethod · 0.45
disconnectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected