(node_factory, bitcoind)
| 1580 | @pytest.mark.openchannel('v2') |
| 1581 | @unittest.skipIf(TEST_NETWORK != 'regtest', "External wallet support doesn't work with elements yet.") |
| 1582 | def test_funding_close_upfront(node_factory, bitcoind): |
| 1583 | opts = {'plugin': os.path.join(os.getcwd(), 'tests/plugins/openchannel_hook_accepter.py')} |
| 1584 | |
| 1585 | l1 = node_factory.get_node() |
| 1586 | l2 = node_factory.get_node(options=opts) |
| 1587 | |
| 1588 | # The 'accepter_close_to' plugin uses the channel funding amount |
| 1589 | # to determine whether or not to include a 'close_to' address |
| 1590 | amt_normal = 100000 # continues without returning a close_to |
| 1591 | amt_addr = 100003 # returns valid regtest address |
| 1592 | |
| 1593 | remote_valid_addr = 'bcrt1q7gtnxmlaly9vklvmfj06amfdef3rtnrdazdsvw' |
| 1594 | |
| 1595 | def has_normal_channels(l1, l2): |
| 1596 | if l1.rpc.listpeers(l2.info['id'])['peers'] == []: |
| 1597 | return False |
| 1598 | return any([c['state'] == 'CHANNELD_AWAITING_LOCKIN' |
| 1599 | or c['state'] == 'CHANNELD_NORMAL' |
| 1600 | for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels']]) |
| 1601 | |
| 1602 | def _fundchannel(l1, l2, amount, close_to): |
| 1603 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 1604 | assert(l1.rpc.listpeers()['peers'][0]['id'] == l2.info['id']) |
| 1605 | |
| 1606 | # Make sure both consider any previous channels closed. |
| 1607 | wait_for(lambda: not has_normal_channels(l1, l2)) |
| 1608 | wait_for(lambda: not has_normal_channels(l2, l1)) |
| 1609 | |
| 1610 | _, resp = l1.fundchannel(l2, amount, close_to=close_to) |
| 1611 | if close_to: |
| 1612 | assert resp['close_to'] |
| 1613 | else: |
| 1614 | assert 'close_to' not in resp |
| 1615 | |
| 1616 | for node in [l1, l2]: |
| 1617 | channel = node.rpc.listpeers()['peers'][0]['channels'][-1] |
| 1618 | assert amount * 1000 == channel['total_msat'] |
| 1619 | |
| 1620 | def _close(src, dst, addr=None): |
| 1621 | """Close the channel from src to dst, with the specified address. |
| 1622 | |
| 1623 | Returns the address of the outputs in the close tx. Raises an |
| 1624 | error if some expectations are not met. |
| 1625 | |
| 1626 | """ |
| 1627 | r = l1.rpc.close(l2.info['id'], destination=addr) |
| 1628 | assert r['type'] == 'mutual' |
| 1629 | tx = bitcoind.rpc.decoderawtransaction(r['tx']) |
| 1630 | |
| 1631 | addrs = [scriptpubkey_addr(vout['scriptPubKey']) for vout in tx['vout']] |
| 1632 | bitcoind.generate_block(1, wait_for_mempool=[r['txid']]) |
| 1633 | sync_blockheight(bitcoind, [l1, l2]) |
| 1634 | return addrs |
| 1635 | |
| 1636 | # check that normal peer close works |
| 1637 | _fundchannel(l1, l2, amt_normal, None) |
| 1638 | _close(l1, l2) |
| 1639 |
nothing calls this directly
no test coverage detected