From 368a330a873cdedf533413175840fbe998df30bd Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Thu, 4 May 2023 19:35:57 -0700 Subject: [PATCH] tests: Use FUNDING_CONFIRMS instead of 1 --- contrib/pyln-testing/pyln/testing/utils.py | 9 ++++++++- tests/test_bookkeeper.py | 4 ++-- tests/test_closing.py | 6 +++--- tests/test_connection.py | 19 ++++++++++--------- tests/test_misc.py | 4 ++-- tests/test_opening.py | 6 +++--- tests/test_pay.py | 4 ++-- tests/test_plugin.py | 4 ++-- tests/utils.py | 2 +- 9 files changed, 33 insertions(+), 25 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 31718c1aaa57..6c670dc193a0 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -82,6 +82,7 @@ def env(name, default=None): TIMEOUT = int(env("TIMEOUT", 180 if SLOW_MACHINE else 60)) SUBDAEMON = env("SUBDAEMON", "") EXPERIMENTAL_DUAL_FUND = env("EXPERIMENTAL_DUAL_FUND", "0") == "1" +FUNDING_CONFIRMS = int(env("FUNDING_CONFIRMS", "1")) def wait_for(success, timeout=TIMEOUT): @@ -703,6 +704,9 @@ def __init__( if grpc_port is not None: opts['grpc-port'] = grpc_port + if FUNDING_CONFIRMS > 1: + opts['funding-confirms'] = FUNDING_CONFIRMS + if SUBDAEMON: assert node_id > 0 subdaemons = SUBDAEMON.split(',') @@ -1198,6 +1202,9 @@ def has_funds_on_addr(addr): scid = "{}x{}x{}".format(self.bitcoin.rpc.getblockcount(), txnum, res['outnum']) + if FUNDING_CONFIRMS > 1: + self.bitcoin.generate_block(FUNDING_CONFIRMS - 1) + if wait_for_active: self.wait_channel_active(scid) l2.wait_channel_active(scid) @@ -1723,7 +1730,7 @@ def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_an txids.append(src.rpc.fundchannel(dst.info['id'], fundamount, announce=announce_channels)['txid']) # Confirm all channels and wait for them to become usable - bitcoind.generate_block(1, wait_for_mempool=txids) + bitcoind.generate_block(FUNDING_CONFIRMS, wait_for_mempool=txids) scids = [] for src, dst in connections: wait_for(lambda: src.channel_state(dst) == 'CHANNELD_NORMAL') diff --git a/tests/test_bookkeeper.py b/tests/test_bookkeeper.py index 6d0435e97c40..be7c4c1d40af 100644 --- a/tests/test_bookkeeper.py +++ b/tests/test_bookkeeper.py @@ -5,7 +5,7 @@ from fixtures import TEST_NETWORK from utils import ( sync_blockheight, wait_for, only_one, first_channel_id, TIMEOUT, - anchor_expected + anchor_expected, FUNDING_CONFIRMS ) from pathlib import Path @@ -501,7 +501,7 @@ def test_bookkeeping_missed_chans_pay_after(node_factory, bitcoind): l1.fundwallet(200000000) l1.rpc.connect(l2.info['id'], 'localhost', l2.port) txid = l1.rpc.fundchannel(l2.info['id'], open_amt)['txid'] - bitcoind.generate_block(1, wait_for_mempool=[txid]) + bitcoind.generate_block(FUNDING_CONFIRMS, wait_for_mempool=[txid]) wait_for(lambda: l1.channel_state(l2) == 'CHANNELD_NORMAL') scid = l1.get_channel_scid(l2) l1.wait_channel_active(scid) diff --git a/tests/test_closing.py b/tests/test_closing.py index 44644014e35f..22126936ed15 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -8,7 +8,7 @@ scriptpubkey_addr, calc_lease_fee, EXPERIMENTAL_FEATURES, check_utxos_channel, anchor_expected, check_coin_moves, check_balance_snaps, mine_funding_to_announce, check_inspect_channel, - first_scid + first_scid, FUNDING_CONFIRMS ) import os @@ -1726,7 +1726,7 @@ def test_onchain_first_commit(node_factory, bitcoind): l1.rpc.fundchannel(l2.info['id'], 10**6) l1.daemon.wait_for_log('sendrawtx exit 0') - bitcoind.generate_block(1) + bitcoind.generate_block(FUNDING_CONFIRMS) # l1 will drop to chain. l1.daemon.wait_for_log('permfail') @@ -3483,7 +3483,7 @@ def test_segwit_anyshutdown(node_factory, bitcoind, executor): # If we don't actually make a payment, two of the above cases fail # because the resulting tx is too small! Balance channel so close # has two outputs. - bitcoind.generate_block(1, wait_for_mempool=1) + bitcoind.generate_block(FUNDING_CONFIRMS, wait_for_mempool=1) wait_for(lambda: any([c['state'] == 'CHANNELD_NORMAL' for c in l1.rpc.listpeerchannels()['channels']])) l1.pay(l2, 10**9 // 2) l1.rpc.close(l2.info['id'], destination=addr) diff --git a/tests/test_connection.py b/tests/test_connection.py index 45eff96dfa72..da9c37c4efc9 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -12,7 +12,7 @@ EXPERIMENTAL_FEATURES, mine_funding_to_announce, first_scid, anchor_expected, CHANNEL_SIZE ) -from pyln.testing.utils import SLOW_MACHINE, VALGRIND, EXPERIMENTAL_DUAL_FUND, FUNDAMOUNT +from pyln.testing.utils import SLOW_MACHINE, VALGRIND, EXPERIMENTAL_DUAL_FUND, FUNDAMOUNT, FUNDING_CONFIRMS import os import pytest @@ -989,7 +989,7 @@ def test_reconnect_remote_sends_no_sigs(node_factory): # When l1 restarts (with rescan=1), make it think it hasn't # reached announce_depth, so it wont re-send announcement_signatures def no_blocks_above(req): - if req['params'][0] > 107: + if req['params'][0] > 106 + FUNDING_CONFIRMS: return {"result": None, "error": {"code": -8, "message": "Block height out of range"}, "id": req['id']} else: @@ -3538,7 +3538,7 @@ def test_wumbo_channels(node_factory, bitcoind): l1.rpc.connect(l2.info['id'], 'localhost', port=l2.port) l1.rpc.fundchannel(l2.info['id'], 'all') - bitcoind.generate_block(1, wait_for_mempool=1) + bitcoind.generate_block(FUNDING_CONFIRMS, wait_for_mempool=1) wait_for(lambda: 'CHANNELD_NORMAL' in [c['state'] for c in l1.rpc.listpeerchannels(l2.info['id'])['channels']]) # Exact amount depends on fees, but it will be wumbo! @@ -3587,7 +3587,7 @@ def test_channel_features(node_factory, bitcoind): assert only_one(l2.rpc.listpeerchannels()['channels'])['features'] == chan['features'] # Confirm it. - bitcoind.generate_block(1) + bitcoind.generate_block(FUNDING_CONFIRMS) wait_for(lambda: only_one(l1.rpc.listpeerchannels()['channels'])['state'] == 'CHANNELD_NORMAL') wait_for(lambda: only_one(l2.rpc.listpeerchannels()['channels'])['state'] == 'CHANNELD_NORMAL') @@ -4168,7 +4168,7 @@ def test_multichan(node_factory, executor, bitcoind): assert(len(l2.rpc.listpeerchannels(l3.info['id'])['channels']) == 2) assert(len(l3.rpc.listpeerchannels(l2.info['id'])['channels']) == 2) - bitcoind.generate_block(1, wait_for_mempool=1) + bitcoind.generate_block(FUNDING_CONFIRMS, wait_for_mempool=1) sync_blockheight(bitcoind, [l1, l2, l3]) # Make sure new channel is also CHANNELD_NORMAL wait_for(lambda: [c['state'] for c in l2.rpc.listpeerchannels(l3.info['id'])['channels']] == ["CHANNELD_NORMAL", "CHANNELD_NORMAL"]) @@ -4287,30 +4287,31 @@ def test_multichan(node_factory, executor, bitcoind): l1htlcs = l1.rpc.listhtlcs()['htlcs'] assert l1htlcs == l1.rpc.listhtlcs(scid12)['htlcs'] + adjust = 0 if FUNDING_CONFIRMS == 1 else 1 # FIXME - why is this the case? assert l1htlcs == [{"short_channel_id": scid12, "id": 0, - "expiry": 117, + "expiry": 116 + FUNDING_CONFIRMS + adjust, "direction": "out", "amount_msat": Millisatoshi(100001001), "payment_hash": inv1['payment_hash'], "state": "RCVD_REMOVE_ACK_REVOCATION"}, {"short_channel_id": scid12, "id": 1, - "expiry": 117, + "expiry": 116 + FUNDING_CONFIRMS + adjust, "direction": "out", "amount_msat": Millisatoshi(100001001), "payment_hash": inv2['payment_hash'], "state": "RCVD_REMOVE_ACK_REVOCATION"}, {"short_channel_id": scid12, "id": 2, - "expiry": 135, + "expiry": 134 + FUNDING_CONFIRMS + adjust, "direction": "out", "amount_msat": Millisatoshi(100001001), "payment_hash": inv3['payment_hash'], "state": "RCVD_REMOVE_ACK_REVOCATION"}, {"short_channel_id": scid12, "id": 3, - "expiry": 135, + "expiry": 134 + FUNDING_CONFIRMS + adjust, "direction": "out", "amount_msat": Millisatoshi(100001001), "payment_hash": inv4['payment_hash'], diff --git a/tests/test_misc.py b/tests/test_misc.py index 30842130cc63..66dcc3096ad5 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -6,7 +6,7 @@ from threading import Event from pyln.testing.utils import ( DEVELOPER, TIMEOUT, VALGRIND, DEPRECATED_APIS, sync_blockheight, only_one, - wait_for, TailableProc, env, mine_funding_to_announce + wait_for, TailableProc, env, mine_funding_to_announce, FUNDING_CONFIRMS ) from utils import ( account_balance, scriptpubkey_addr, check_coin_moves @@ -653,7 +653,7 @@ def test_io_logging(node_factory, executor): l1.rpc.fundchannel(l2.info['id'], 10**6)['tx'] l1.daemon.wait_for_log('sendrawtx exit 0') - l1.bitcoin.generate_block(1) + l1.bitcoin.generate_block(FUNDING_CONFIRMS) l1.daemon.wait_for_log(' to CHANNELD_NORMAL') l2.daemon.wait_for_log(' to CHANNELD_NORMAL') diff --git a/tests/test_opening.py b/tests/test_opening.py index c24ca160f9e7..462615fc965b 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -2,7 +2,7 @@ from fixtures import TEST_NETWORK from pyln.client import RpcError, Millisatoshi from utils import ( - only_one, wait_for, sync_blockheight, first_channel_id, calc_lease_fee, check_coin_moves, anchor_expected, EXPERIMENTAL_FEATURES + only_one, wait_for, sync_blockheight, first_channel_id, calc_lease_fee, check_coin_moves, anchor_expected, EXPERIMENTAL_FEATURES, FUNDING_CONFIRMS ) from pathlib import Path @@ -1713,7 +1713,7 @@ def test_scid_alias_private(node_factory, bitcoind): l2.fundwallet(5000000) l2.rpc.fundchannel(l3.info['id'], 'all', announce=False) - bitcoind.generate_block(1, wait_for_mempool=1) + bitcoind.generate_block(FUNDING_CONFIRMS, wait_for_mempool=1) wait_for(lambda: only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL') chan = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels']) @@ -1851,7 +1851,7 @@ def test_zeroreserve(node_factory, bitcoind): l1.rpc.fundchannel(l2.info['id'], 10**6, reserve='0sat') l2.rpc.fundchannel(l3.info['id'], 10**6) l3.rpc.fundchannel(l1.info['id'], 10**6, reserve='321sat') - bitcoind.generate_block(1, wait_for_mempool=3) + bitcoind.generate_block(FUNDING_CONFIRMS, wait_for_mempool=3) wait_for(lambda: l1.channel_state(l2) == 'CHANNELD_NORMAL') wait_for(lambda: l2.channel_state(l3) == 'CHANNELD_NORMAL') wait_for(lambda: l3.channel_state(l1) == 'CHANNELD_NORMAL') diff --git a/tests/test_pay.py b/tests/test_pay.py index 09caca7ea8a3..c8b2bf123756 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -7,7 +7,7 @@ from pyln.testing.utils import EXPERIMENTAL_DUAL_FUND, FUNDAMOUNT, scid_to_int from utils import ( DEVELOPER, wait_for, only_one, sync_blockheight, TIMEOUT, - EXPERIMENTAL_FEATURES, VALGRIND, mine_funding_to_announce, first_scid + EXPERIMENTAL_FEATURES, VALGRIND, mine_funding_to_announce, first_scid, FUNDING_CONFIRMS ) import copy import os @@ -3020,7 +3020,7 @@ def serialize_payload_final_tlv(n, payment_secret: str): l1.rpc.waitsendpay(payment_hash=payment_hash) except RpcError as e: assert(e.error['code'] == 204) - assert(e.error['data']['raw_message'] == "400f00000000000003e80000006c") + assert(e.error['data']['raw_message'] == "400f00000000000003e8000000{:x}".format(107 + FUNDING_CONFIRMS)) @pytest.mark.developer("needs dev-disable-commit-after, dev-no-htlc-timeout") diff --git a/tests/test_plugin.py b/tests/test_plugin.py index b8868f9c1b7e..919198a0647f 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -9,7 +9,7 @@ DEPRECATED_APIS, expected_peer_features, expected_node_features, expected_channel_features, account_balance, check_coin_moves, first_channel_id, EXPERIMENTAL_DUAL_FUND, - mine_funding_to_announce + mine_funding_to_announce, FUNDING_CONFIRMS ) import ast @@ -980,7 +980,7 @@ def wait_for_event(node): assert(event1['message'] == "channeld: received ERROR error channel {}: Forcibly closed by `close` command timeout".format(cid)) # settle the channel closure - bitcoind.generate_block(100) + bitcoind.generate_block(101 - FUNDING_CONFIRMS) event2 = wait_for_event(l2) assert(event2['old_state'] == "AWAITING_UNILATERAL") diff --git a/tests/utils.py b/tests/utils.py index c93f6b024ec5..a2346708641e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,7 +2,7 @@ from pyln.testing.utils import env, only_one, wait_for, write_config, TailableProc, sync_blockheight, wait_channel_quiescent, get_tx_p2wsh_outnum, mine_funding_to_announce, scid_to_int # noqa: F401 import bitstring from pyln.client import Millisatoshi -from pyln.testing.utils import EXPERIMENTAL_DUAL_FUND +from pyln.testing.utils import EXPERIMENTAL_DUAL_FUND, FUNDING_CONFIRMS import time EXPERIMENTAL_FEATURES = env("EXPERIMENTAL_FEATURES", "0") == "1"