Skip to content

Commit

Permalink
pytest: adapt tests to avoid deprecated APIs in close (tx and txid).
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Nov 17, 2024
1 parent 809f3b0 commit c79a89d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3906,8 +3906,8 @@ def test_closing_tx_valid(node_factory, bitcoind):
close = l1.rpc.close(l2.info['id'])

wait_for(lambda: len(bitcoind.rpc.getrawmempool()) == 1)
assert only_one(bitcoind.rpc.getrawmempool()) == close['txid']
assert bitcoind.rpc.getrawtransaction(close['txid']) == close['tx']
assert only_one(bitcoind.rpc.getrawmempool()) == only_one(close['txids'])
assert bitcoind.rpc.getrawtransaction(only_one(close['txids'])) == only_one(close['txs'])
bitcoind.generate_block(1)
# Change output and the closed channel output.
wait_for(lambda: [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed'] * 2)
Expand All @@ -3921,8 +3921,8 @@ def test_closing_tx_valid(node_factory, bitcoind):
close = l1.rpc.close(l2.info['id'], 1)

wait_for(lambda: len(bitcoind.rpc.getrawmempool()) == 1)
assert only_one(bitcoind.rpc.getrawmempool()) == close['txid']
assert bitcoind.rpc.getrawtransaction(close['txid']) == close['tx']
assert only_one(bitcoind.rpc.getrawmempool()) == only_one(close['txids'])
assert bitcoind.rpc.getrawtransaction(only_one(close['txids'])) == only_one(close['txs'])


@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd does not provide feerates on regtest')
Expand All @@ -3933,7 +3933,7 @@ def test_closing_minfee(node_factory, bitcoind):

wait_for(lambda: only_one(l1.rpc.listpeerchannels()['channels'])['htlcs'] == [])

txid = l1.rpc.close(l2.info['id'])['txid']
txid = only_one(l1.rpc.close(l2.info['id'])['txids'])
bitcoind.generate_block(1, wait_for_mempool=txid)


Expand Down Expand Up @@ -4014,7 +4014,7 @@ def test_closing_cpfp(node_factory, bitcoind):
l1.rpc.pay(l2.rpc.invoice(10000000, 'test', 'test')['bolt11'])

# Mutual close
close_txid = l1.rpc.close(l2.info['id'])['txid']
close_txid = only_one(l1.rpc.close(l2.info['id'])['txids'])

l1out = only_one([o for o in l1.rpc.listfunds()['outputs'] if o != change])
assert l1out['txid'] == close_txid
Expand Down Expand Up @@ -4093,7 +4093,7 @@ def test_anchorspend_using_to_remote(node_factory, bitcoind, anchors):

l4.rpc.disconnect(l2.info['id'], force=True)
close = l4.rpc.close(l2.info['id'], 1)
bitcoind.generate_block(1, wait_for_mempool=close['txid'])
bitcoind.generate_block(1, wait_for_mempool=only_one(close['txids']))
wait_for(lambda: len(l2.rpc.listfunds()['outputs']) == 1)
# Don't need l4 any more
l4.stop()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,10 +1683,10 @@ def _close(src, dst, addr=None):
"""
r = l1.rpc.close(l2.info['id'], destination=addr)
assert r['type'] == 'mutual'
tx = bitcoind.rpc.decoderawtransaction(r['tx'])
tx = bitcoind.rpc.decoderawtransaction(only_one(r['txs']))

addrs = [scriptpubkey_addr(vout['scriptPubKey']) for vout in tx['vout']]
bitcoind.generate_block(1, wait_for_mempool=[r['txid']])
bitcoind.generate_block(1, wait_for_mempool=[only_one(r['txids'])])
sync_blockheight(bitcoind, [l1, l2])
return addrs

Expand Down
4 changes: 2 additions & 2 deletions tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fixtures import * # noqa: F401,F403
from fixtures import TEST_NETWORK
from pyln.client import RpcError
from utils import wait_for, sync_blockheight, COMPAT, TIMEOUT, scid_to_int
from utils import wait_for, sync_blockheight, COMPAT, TIMEOUT, scid_to_int, only_one

import base64
import os
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_block_backfill(node_factory, bitcoind, chainparams):
l3.daemon.wait_for_log('seeker: state = NORMAL')

# Now close the channel and make sure `l3` cleans up correctly:
txid = l1.rpc.close(l2.info['id'])['txid']
txid = only_one(l1.rpc.close(l2.info['id'])['txids'])
bitcoind.generate_block(13, wait_for_mempool=txid)
wait_for(lambda: len(l3.rpc.listchannels()['channels']) == 0)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ def test_gossip_notices_close(node_factory, bitcoind):
channel_update = l1.daemon.is_in_log(r'\[IN\] 0102').split(' ')[-1][:-1]
node_announcement = l1.daemon.is_in_log(r'\[IN\] 0101').split(' ')[-1][:-1]

txid = l2.rpc.close(l3.info['id'])['txid']
txid = only_one(l2.rpc.close(l3.info['id'])['txids'])
wait_for(lambda: l2.rpc.listpeerchannels(l3.info['id'])['channels'][0]['state'] == 'CLOSINGD_COMPLETE')
bitcoind.generate_block(13, txid)

Expand Down Expand Up @@ -1894,7 +1894,7 @@ def test_topology_leak(node_factory, bitcoind):
wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4)

# Close and wait for gossip to catchup.
txid = l2.rpc.close(l3.info['id'])['txid']
txid = only_one(l2.rpc.close(l3.info['id'])['txids'])
bitcoind.generate_block(13, txid)

wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 2)
Expand Down Expand Up @@ -1926,14 +1926,14 @@ def test_close_12_block_delay(node_factory, bitcoind):
l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True)

# Close l1-l2
txid = l1.rpc.close(l2.info['id'])['txid']
txid = only_one(l1.rpc.close(l2.info['id'])['txids'])
bitcoind.generate_block(1, txid)

# But l4 doesn't believe it immediately.
l4.daemon.wait_for_log("channel .* closing soon due to the funding outpoint being spent")

# Close l2-l3 one block later.
txid = l2.rpc.close(l3.info['id'])['txid']
txid = only_one(l2.rpc.close(l3.info['id'])['txids'])
bitcoind.generate_block(1, txid)
l4.daemon.wait_for_log("channel .* closing soon due to the funding outpoint being spent")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3996,7 +3996,7 @@ def test_setconfig(node_factory, bitcoind):
l1.fundchannel(l2, 400000)

l1.fundchannel(l2, 10**6)
txid = l1.rpc.close(l2.info['id'])['txid']
txid = only_one(l1.rpc.close(l2.info['id'])['txids'])
# Make sure we're completely closed!
bitcoind.generate_block(1, wait_for_mempool=txid)
sync_blockheight(bitcoind, [l1, l2])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ def test_zeroreserve(node_factory, bitcoind):
# closing should result in the output being trimmed again since we
# dropped below dust again.
c = l2.rpc.close(l1.info['id'])
decoded = bitcoind.rpc.decoderawtransaction(c['tx'])
decoded = bitcoind.rpc.decoderawtransaction(only_one(c['txs']))
# Elements has a change output always
assert len(decoded['vout']) == 1 if TEST_NETWORK == 'regtest' else 2

Expand Down
2 changes: 1 addition & 1 deletion tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5753,7 +5753,7 @@ def test_offer_paths(node_factory, bitcoind):

# Make scid path invalid by closing it
close = l1.rpc.close(paths[0]['first_scid'])
bitcoind.generate_block(13, wait_for_mempool=close['txid'])
bitcoind.generate_block(13, wait_for_mempool=only_one(close['txids']))
wait_for(lambda: l5.rpc.listchannels(paths[0]['first_scid']) == {'channels': []})

# Now connect l5->l4, and it will be able to reach l3 via that, and join blinded path.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def test_openchannel_hook(node_factory, bitcoind):
assert l2.daemon.is_in_log('reject_odd_funding_amounts.py: {}={}'.format(k, v))

# Close it.
txid = l1.rpc.close(l2.info['id'])['txid']
txid = only_one(l1.rpc.close(l2.info['id'])['txids'])
bitcoind.generate_block(1, txid)
wait_for(lambda: [c['state'] for c in l1.rpc.listpeerchannels(l2.info['id'])['channels']] == ['ONCHAIN'])

Expand Down Expand Up @@ -4197,7 +4197,7 @@ def test_sql(node_factory, bitcoind):
l3.daemon.wait_for_log("Refreshing channel: {}".format(scid))

# This has to wait for the hold_invoice plugin to let go!
txid = l1.rpc.close(l2.info['id'])['txid']
txid = only_one(l1.rpc.close(l2.info['id'])['txids'])
bitcoind.generate_block(13, wait_for_mempool=txid)
wait_for(lambda: len(l3.rpc.listchannels(source=l1.info['id'])['channels']) == 0)
assert len(l3.rpc.sql("SELECT * FROM channels WHERE source = X'{}';".format(l1.info['id']))['rows']) == 0
Expand Down

0 comments on commit c79a89d

Please sign in to comment.