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

Function test_onchain_middleman_simple

tests/test_closing.py:2328–2455  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams, anchors)

Source from the content-addressed store, hash-verified

2326
2327@pytest.mark.parametrize("anchors", [False, True])
2328def test_onchain_middleman_simple(node_factory, bitcoind, chainparams, anchors):
2329 if chainparams['elements'] and anchors:
2330 pytest.skip('elementsd anchors unsupported')
2331
2332 # We track channel balances, to verify that accounting is ok.
2333 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
2334
2335 opts = {'plugin': coin_mvt_plugin}
2336 if anchors is False:
2337 opts['dev-force-features'] = "-23"
2338
2339 # HTLC 1->2->3, 1->2 goes down after 2 gets preimage from 3.
2340 disconnects = ['-WIRE_UPDATE_FULFILL_HTLC', 'permfail']
2341 l1, l2, l3 = node_factory.get_nodes(3, opts=[opts,
2342 {**opts, **{'disconnect': disconnects}},
2343 opts])
2344
2345 # l2 connects to both, so l1 can't reconnect and thus l2 drops to chain
2346 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
2347 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
2348 l2.fundchannel(l1, 10**6)
2349 c23, _ = l2.fundchannel(l3, 10**6)
2350 channel_id = first_channel_id(l1, l2)
2351
2352 # Make sure routes finalized.
2353 mine_funding_to_announce(bitcoind, [l1, l2, l3])
2354 l1.wait_channel_active(c23)
2355
2356 # Give l1 some money to play with.
2357 l2.pay(l1, 2 * 10**8)
2358
2359 # Must be bigger than dust!
2360 inv = l3.rpc.invoice(10**8, 'middleman', 'desc')
2361 rhash = inv['payment_hash']
2362
2363 route = l1.single_route(l3.info['id'], 10**8)
2364 assert len(route) == 2
2365
2366 q = queue.Queue()
2367
2368 def try_pay():
2369 try:
2370 l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
2371 l1.rpc.waitsendpay(rhash)
2372 q.put(None)
2373 except Exception as err:
2374 q.put(err)
2375
2376 t = threading.Thread(target=try_pay)
2377 t.daemon = True
2378 t.start()
2379
2380 # l2 will drop to chain.
2381 l2.daemon.wait_for_log('sendrawtx exit 0')
2382 # If anchors, we will spend anchor to push it along, so wait for that too!
2383 if anchors:
2384 l1.bitcoin.generate_block(1, wait_for_mempool=2)
2385 else:

Callers

nothing calls this directly

Calls 15

first_channel_idFunction · 0.90
mine_funding_to_announceFunction · 0.90
account_balanceFunction · 0.90
check_utxos_channelFunction · 0.90
joinMethod · 0.80
get_nodesMethod · 0.80
wait_channel_activeMethod · 0.80
single_routeMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80
wait_for_onchaind_txsMethod · 0.80
wait_for_onchaind_txMethod · 0.80

Tested by

no test coverage detected