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

Function test_funding_external_wallet

tests/test_connection.py:1732–1786  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1730@unittest.skipIf(TEST_NETWORK != 'regtest', "External wallet support doesn't work with elements yet.")
1731@pytest.mark.openchannel('v1')
1732def test_funding_external_wallet(node_factory, bitcoind):
1733 l1, l2, l3 = node_factory.get_nodes(3, opts=[{'funding-confirms': 2},
1734 {'funding-confirms': 2}, {}])
1735
1736 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1737 assert(l1.rpc.listpeers()['peers'][0]['id'] == l2.info['id'])
1738
1739 amount = 2**24 - 1
1740 address = l1.rpc.fundchannel_start(l2.info['id'], amount)['funding_address']
1741 assert len(address) > 0
1742
1743 peer = l1.rpc.listpeers()['peers'][0]
1744 # Peer should still be connected and in state waiting for funding_txid
1745 assert peer['id'] == l2.info['id']
1746 r = re.compile('Funding channel start: awaiting funding_txid with output to .*')
1747
1748 channels = l1.rpc.listpeerchannels(peer['id'])['channels']
1749 assert len(channels) == 1, f"Channels for peer {peer['id']} need to be not empty"
1750 assert any(r.match(line) for line in channels[0]['status'])
1751 assert 'OPENINGD' in channels[0]['state']
1752
1753 # Trying to start a second funding should not work, it's in progress.
1754 with pytest.raises(RpcError, match=r'Already funding channel'):
1755 l1.rpc.fundchannel_start(l2.info['id'], amount)
1756
1757 # 'Externally' fund the address from fundchannel_start
1758 psbt = bitcoind.rpc.walletcreatefundedpsbt([], [{address: amount / 10**8}])['psbt']
1759 assert l1.rpc.fundchannel_complete(l2.info['id'], psbt)['commitments_secured']
1760
1761 # Broadcast the transaction manually
1762 process = bitcoind.rpc.walletprocesspsbt(psbt)
1763 assert process['complete'] is True
1764 tx = bitcoind.rpc.finalizepsbt(process['psbt'])
1765 txid = bitcoind.rpc.sendrawtransaction(tx['hex'])
1766 bitcoind.generate_block(1)
1767
1768 l1.daemon.wait_for_log(r'Funding tx {} depth 1 of 2'.format(txid))
1769
1770 # Check that tx is broadcast by a third party can be catched.
1771 # Only when the transaction (broadcast by a third pary) is onchain, we can catch it.
1772 with pytest.raises(RpcError, match=r'.* been broadcast.*'):
1773 l1.rpc.fundchannel_cancel(l2.info['id'])
1774
1775 # Confirm that channel locks in
1776 bitcoind.generate_block(1)
1777
1778 for node in [l1, l2]:
1779 node.daemon.wait_for_log(r'State changed from CHANNELD_AWAITING_LOCKIN to CHANNELD_NORMAL')
1780 channel = node.rpc.listpeerchannels()['channels'][0]
1781 assert amount * 1000 == channel['total_msat']
1782
1783 # Test that we don't crash if peer disconnects after fundchannel_start
1784 l2.connect(l3)
1785 l2.rpc.fundchannel_start(l3.info["id"], amount)
1786 l3.rpc.close(l2.info["id"])
1787
1788
1789@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')

Callers

nothing calls this directly

Calls 12

get_nodesMethod · 0.80
fundchannel_startMethod · 0.80
compileMethod · 0.80
listpeerchannelsMethod · 0.80
fundchannel_completeMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80
fundchannel_cancelMethod · 0.80
anyClass · 0.50
connectMethod · 0.45
listpeersMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected