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

Function test_funding_close_upfront

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

Source from the content-addressed store, hash-verified

1635@pytest.mark.openchannel('v2')
1636@unittest.skipIf(TEST_NETWORK != 'regtest', "External wallet support doesn't work with elements yet.")
1637def test_funding_close_upfront(node_factory, bitcoind):
1638 opts = {'plugin': os.path.join(os.getcwd(), 'tests/plugins/openchannel_hook_accepter.py')}
1639
1640 l1 = node_factory.get_node()
1641 l2 = node_factory.get_node(options=opts)
1642
1643 # The 'accepter_close_to' plugin uses the channel funding amount
1644 # to determine whether or not to include a 'close_to' address
1645 amt_normal = 100000 # continues without returning a close_to
1646 amt_addr = 100003 # returns valid regtest address
1647
1648 remote_valid_addr = 'bcrt1q7gtnxmlaly9vklvmfj06amfdef3rtnrdazdsvw'
1649
1650 def has_normal_channels(l1, l2):
1651 if l1.rpc.listpeers(l2.info['id'])['peers'] == []:
1652 return False
1653 return any([c['state'] == 'CHANNELD_AWAITING_LOCKIN'
1654 or c['state'] == 'CHANNELD_NORMAL'
1655 for c in l1.rpc.listpeerchannels(l2.info['id'])['channels']])
1656
1657 def _fundchannel(l1, l2, amount, close_to):
1658 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1659 assert(l1.rpc.listpeers()['peers'][0]['id'] == l2.info['id'])
1660
1661 # Make sure both consider any previous channels closed.
1662 wait_for(lambda: not has_normal_channels(l1, l2))
1663 wait_for(lambda: not has_normal_channels(l2, l1))
1664
1665 _, resp = l1.fundchannel(l2, amount, close_to=close_to)
1666 if close_to:
1667 assert resp['close_to']
1668 else:
1669 assert 'close_to' not in resp
1670
1671 for node in [l1, l2]:
1672 channel = node.rpc.listpeerchannels()['channels'][-1]
1673 assert amount * 1000 == channel['total_msat']
1674
1675 def _close(src, dst, addr=None):
1676 """Close the channel from src to dst, with the specified address.
1677
1678 Returns the address of the outputs in the close tx. Raises an
1679 error if some expectations are not met.
1680
1681 """
1682 r = l1.rpc.close(l2.info['id'], destination=addr)
1683 assert r['type'] == 'mutual'
1684 tx = bitcoind.rpc.decoderawtransaction(only_one(r['txs']))
1685
1686 addrs = [scriptpubkey_addr(vout['scriptPubKey']) for vout in tx['vout']]
1687 bitcoind.generate_block(1, wait_for_mempool=[only_one(r['txids'])])
1688 sync_blockheight(bitcoind, [l1, l2])
1689 return addrs
1690
1691 # check that normal peer close works
1692 _fundchannel(l1, l2, amt_normal, None)
1693 _close(l1, l2)
1694

Callers

nothing calls this directly

Calls 10

_fundchannelFunction · 0.85
_closeFunction · 0.85
joinMethod · 0.80
listpeerchannelsMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
getnewaddressMethod · 0.45
xpayMethod · 0.45
invoiceMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected