Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Use FUNDING_CONFIRMS instead of 1 #92

Open
wants to merge 1 commit into
base: 2023-04-remote-hsmd-v23.05rc2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion contrib/pyln-testing/pyln/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(',')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bookkeeper.py
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 542, the onchain_fee is missing for `FUNDING_CONFIRMS > 1. But why is it there even when FUNDING_CONFIRMS == 1?

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand Down
6 changes: 3 additions & 3 deletions tests/test_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down