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

Function test_onchain_middleman_simple

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

Source from the content-addressed store, hash-verified

2085
2086@pytest.mark.parametrize("anchors", [False, True])
2087def test_onchain_middleman_simple(node_factory, bitcoind, chainparams, anchors):
2088 if chainparams['elements'] and anchors:
2089 pytest.skip('elementsd anchors unsupported')
2090
2091 # We track channel balances, to verify that accounting is ok.
2092 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
2093
2094 opts = {'plugin': coin_mvt_plugin}
2095 if anchors is False:
2096 opts['dev-force-features'] = "-23"
2097
2098 # HTLC 1->2->3, 1->2 goes down after 2 gets preimage from 3.
2099 disconnects = ['-WIRE_UPDATE_FULFILL_HTLC', 'permfail']
2100 l1, l2, l3 = node_factory.get_nodes(3, opts=[opts,
2101 {**opts, **{'disconnect': disconnects}},
2102 opts])
2103
2104 # l2 connects to both, so l1 can't reconnect and thus l2 drops to chain
2105 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
2106 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
2107 l2.fundchannel(l1, 10**6)
2108 c23, _ = l2.fundchannel(l3, 10**6)
2109 channel_id = first_channel_id(l1, l2)
2110
2111 # Make sure routes finalized.
2112 mine_funding_to_announce(bitcoind, [l1, l2, l3])
2113 l1.wait_channel_active(c23)
2114
2115 # Give l1 some money to play with.
2116 l2.pay(l1, 2 * 10**8)
2117
2118 # Must be bigger than dust!
2119 inv = l3.rpc.invoice(10**8, 'middleman', 'desc')
2120 rhash = inv['payment_hash']
2121
2122 route = l1.single_route(l3.info['id'], 10**8)
2123 assert len(route) == 2
2124
2125 q = queue.Queue()
2126
2127 def try_pay():
2128 try:
2129 l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
2130 l1.rpc.waitsendpay(rhash)
2131 q.put(None)
2132 except Exception as err:
2133 q.put(err)
2134
2135 t = threading.Thread(target=try_pay)
2136 t.daemon = True
2137 t.start()
2138
2139 # l2 will drop to chain.
2140 l2.daemon.wait_for_log('sendrawtx exit 0')
2141 # If anchors, we will spend anchor to push it along, so wait for that too!
2142 if anchors:
2143 l1.bitcoin.generate_block(1, wait_for_mempool=2)
2144 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