2022-02-09 17:10:09 +01:00
|
|
|
from utils import DEVELOPER, TEST_NETWORK, VALGRIND # noqa: F401,F403
|
2021-05-26 07:47:01 +02:00
|
|
|
from pyln.testing.fixtures import directory, test_base_dir, test_name, chainparams, node_factory, bitcoind, teardown_checks, throttler, db_provider, executor, setup_logging, jsonschemas # noqa: F401,F403
|
2019-10-30 11:50:16 +01:00
|
|
|
from pyln.testing import utils
|
2020-06-08 17:51:28 +02:00
|
|
|
from utils import COMPAT
|
2022-02-09 17:10:09 +01:00
|
|
|
from pathlib import Path
|
2019-10-30 11:50:16 +01:00
|
|
|
|
2020-06-08 17:51:28 +02:00
|
|
|
import os
|
2019-10-30 11:50:16 +01:00
|
|
|
import pytest
|
2020-06-08 17:51:28 +02:00
|
|
|
import re
|
2019-10-30 11:50:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def node_cls():
|
|
|
|
return LightningNode
|
|
|
|
|
|
|
|
|
|
|
|
class LightningNode(utils.LightningNode):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
utils.LightningNode.__init__(self, *args, **kwargs)
|
|
|
|
|
2022-02-09 17:10:09 +01:00
|
|
|
# We have some valgrind suppressions in the `tests/`
|
|
|
|
# directory, so we can add these to the valgrind configuration
|
|
|
|
# (not generally true when running pyln-testing, hence why
|
|
|
|
# it's being done in this specialization, and not in the
|
|
|
|
# library).
|
|
|
|
if self.daemon.cmd_line[0] == 'valgrind':
|
|
|
|
suppressions_path = Path(__file__).parent / "valgrind-suppressions.txt"
|
|
|
|
self.daemon.cmd_prefix += [
|
|
|
|
f"--suppressions={suppressions_path}",
|
|
|
|
"--gen-suppressions=all"
|
|
|
|
]
|
|
|
|
|
2020-09-24 15:54:41 +02:00
|
|
|
# If we opted into checking the DB statements we will attach the dblog
|
|
|
|
# plugin before starting the node
|
2020-12-21 15:06:07 +01:00
|
|
|
check_dblog = os.environ.get("TEST_CHECK_DBSTMTS", None) == "1"
|
2020-09-24 15:54:41 +02:00
|
|
|
db = os.environ.get("TEST_DB_PROVIDER", "sqlite3")
|
|
|
|
if db == 'sqlite3' and check_dblog:
|
|
|
|
dblog = os.path.join(os.path.dirname(__file__), 'plugins', 'dblog.py')
|
|
|
|
has_dblog = len([o for o in self.daemon.cmd_line if 'dblog.py' in o]) > 0
|
|
|
|
if not has_dblog:
|
|
|
|
# Add as an expanded option so we don't clobber other options.
|
|
|
|
self.daemon.opts['plugin={}'.format(dblog)] = None
|
|
|
|
|
2019-10-30 11:50:16 +01:00
|
|
|
# Yes, we really want to test the local development version, not
|
|
|
|
# something in out path.
|
|
|
|
self.daemon.executable = 'lightningd/lightningd'
|
2020-06-08 17:51:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CompatLevel(object):
|
|
|
|
"""An object that encapsulates the compat-level of our build.
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
makefile = os.path.join(os.path.dirname(__file__), "..", "Makefile")
|
|
|
|
lines = [l for l in open(makefile, 'r') if l.startswith('COMPAT_CFLAGS')]
|
|
|
|
assert(len(lines) == 1)
|
|
|
|
line = lines[0]
|
|
|
|
flags = re.findall(r'COMPAT_V([0-9]+)=1', line)
|
|
|
|
self.compat_flags = flags
|
|
|
|
|
|
|
|
def __call__(self, version):
|
|
|
|
return COMPAT and version in self.compat_flags
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def compat():
|
|
|
|
return CompatLevel()
|
|
|
|
|
|
|
|
|
|
|
|
def is_compat(version):
|
|
|
|
compat = CompatLevel()
|
|
|
|
return compat(version)
|