Skip to content

Commit 844d207

Browse files
author
MarcoFalke
committed
Merge #18828: test: Strip down previous releases boilerplate
fa359d1 test: Strip down previous releases boilerplate (MarcoFalke) Pull request description: Reduces code bloat and mental load to write compatibility tests ACKs for top commit: Sjors: tACK fa359d1 on macOS Tree-SHA512: dc66286b24b2f137e5bca99412850ec7eee8cc61cf9cdc7ab532d529220808189baea8d1b077f8b7f40d3e8881d981e1ffc5a877adb394816f1225b1186253e4
2 parents 608359b + fa359d1 commit 844d207

File tree

3 files changed

+56
-50
lines changed

3 files changed

+56
-50
lines changed

test/functional/feature_backwards_compatibility.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
import os
1919
import shutil
2020

21-
from test_framework.test_framework import BitcoinTestFramework, SkipTest
21+
from test_framework.test_framework import BitcoinTestFramework
2222
from test_framework.descriptors import descsum_create
2323

2424
from test_framework.util import (
2525
assert_equal,
2626
sync_blocks,
27-
sync_mempools
27+
sync_mempools,
2828
)
2929

30+
3031
class BackwardsCompatibilityTest(BitcoinTestFramework):
3132
def set_test_params(self):
3233
self.setup_clean_chain = True
@@ -42,35 +43,15 @@ def set_test_params(self):
4243

4344
def skip_test_if_missing_module(self):
4445
self.skip_if_no_wallet()
46+
self.skip_if_no_previous_releases()
4547

4648
def setup_nodes(self):
47-
if os.getenv("TEST_PREVIOUS_RELEASES") == "false":
48-
raise SkipTest("backwards compatibility tests")
49-
50-
releases_path = os.getenv("PREVIOUS_RELEASES_DIR") or os.getcwd() + "/releases"
51-
if not os.path.isdir(releases_path):
52-
if os.getenv("TEST_PREVIOUS_RELEASES") == "true":
53-
raise AssertionError("TEST_PREVIOUS_RELEASES=1 but releases missing: " + releases_path)
54-
raise SkipTest("This test requires binaries for previous releases")
55-
5649
self.add_nodes(self.num_nodes, extra_args=self.extra_args, versions=[
5750
None,
5851
None,
59-
190000,
52+
190001,
6053
180100,
61-
170100
62-
], binary=[
63-
self.options.bitcoind,
64-
self.options.bitcoind,
65-
releases_path + "/v0.19.0.1/bin/bitcoind",
66-
releases_path + "/v0.18.1/bin/bitcoind",
67-
releases_path + "/v0.17.1/bin/bitcoind"
68-
], binary_cli=[
69-
self.options.bitcoincli,
70-
self.options.bitcoincli,
71-
releases_path + "/v0.19.0.1/bin/bitcoin-cli",
72-
releases_path + "/v0.18.1/bin/bitcoin-cli",
73-
releases_path + "/v0.17.1/bin/bitcoin-cli"
54+
170100,
7455
])
7556

7657
self.start_nodes()

test/functional/test_framework/test_framework.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import configparser
88
from enum import Enum
9-
import logging
109
import argparse
10+
import logging
1111
import os
1212
import pdb
1313
import random
14+
import re
1415
import shutil
1516
import subprocess
1617
import sys
@@ -185,10 +186,11 @@ def setup(self):
185186
self.options.bitcoind = os.getenv("BITCOIND", default=config["environment"]["BUILDDIR"] + '/src/bitcoind' + config["environment"]["EXEEXT"])
186187
self.options.bitcoincli = os.getenv("BITCOINCLI", default=config["environment"]["BUILDDIR"] + '/src/bitcoin-cli' + config["environment"]["EXEEXT"])
187188

189+
self.options.previous_releases_path = os.getenv("PREVIOUS_RELEASES_DIR") or os.getcwd() + "/releases"
190+
188191
os.environ['PATH'] = os.pathsep.join([
189192
os.path.join(config['environment']['BUILDDIR'], 'src'),
190-
os.path.join(config['environment']['BUILDDIR'], 'src', 'qt'),
191-
os.environ['PATH']
193+
os.path.join(config['environment']['BUILDDIR'], 'src', 'qt'), os.environ['PATH']
192194
])
193195

194196
# Set up temp directory and start logging
@@ -388,6 +390,25 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None, bi
388390
389391
Should only be called once after the nodes have been specified in
390392
set_test_params()."""
393+
def get_bin_from_version(version, bin_name, bin_default):
394+
if not version:
395+
return bin_default
396+
return os.path.join(
397+
self.options.previous_releases_path,
398+
re.sub(
399+
r'\.0$',
400+
'', # remove trailing .0 for point releases
401+
'v{}.{}.{}.{}'.format(
402+
(version % 100000000) // 1000000,
403+
(version % 1000000) // 10000,
404+
(version % 10000) // 100,
405+
(version % 100) // 1,
406+
),
407+
),
408+
'bin',
409+
bin_name,
410+
)
411+
391412
if self.bind_to_localhost_only:
392413
extra_confs = [["bind=127.0.0.1"]] * num_nodes
393414
else:
@@ -397,9 +418,9 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None, bi
397418
if versions is None:
398419
versions = [None] * num_nodes
399420
if binary is None:
400-
binary = [self.options.bitcoind] * num_nodes
421+
binary = [get_bin_from_version(v, 'bitcoind', self.options.bitcoind) for v in versions]
401422
if binary_cli is None:
402-
binary_cli = [self.options.bitcoincli] * num_nodes
423+
binary_cli = [get_bin_from_version(v, 'bitcoin-cli', self.options.bitcoincli) for v in versions]
403424
assert_equal(len(extra_confs), num_nodes)
404425
assert_equal(len(extra_args), num_nodes)
405426
assert_equal(len(versions), num_nodes)
@@ -640,6 +661,25 @@ def skip_if_no_cli(self):
640661
if not self.is_cli_compiled():
641662
raise SkipTest("bitcoin-cli has not been compiled.")
642663

664+
def skip_if_no_previous_releases(self):
665+
"""Skip the running test if previous releases are not available."""
666+
if not self.has_previous_releases():
667+
raise SkipTest("previous releases not available or disabled")
668+
669+
def has_previous_releases(self):
670+
"""Checks whether previous releases are present and enabled."""
671+
if os.getenv("TEST_PREVIOUS_RELEASES") == "false":
672+
# disabled
673+
return False
674+
675+
if not os.path.isdir(self.options.previous_releases_path):
676+
if os.getenv("TEST_PREVIOUS_RELEASES") == "true":
677+
raise AssertionError("TEST_PREVIOUS_RELEASES=true but releases missing: {}".format(
678+
self.options.previous_releases_path))
679+
# missing
680+
return False
681+
return True
682+
643683
def is_cli_compiled(self):
644684
"""Checks whether bitcoin-cli was compiled."""
645685
return self.config["components"].getboolean("ENABLE_CLI")

test/functional/wallet_upgradewallet.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import os
1313
import shutil
1414

15-
from test_framework.test_framework import BitcoinTestFramework, SkipTest
15+
from test_framework.test_framework import BitcoinTestFramework
1616
from test_framework.util import (
1717
adjust_bitcoin_conf_for_pre_17,
1818
assert_equal,
1919
assert_greater_than,
20-
assert_is_hex_string
20+
assert_is_hex_string,
2121
)
2222

23+
2324
class UpgradeWalletTest(BitcoinTestFramework):
2425
def set_test_params(self):
2526
self.setup_clean_chain = True
@@ -32,32 +33,16 @@ def set_test_params(self):
3233

3334
def skip_test_if_missing_module(self):
3435
self.skip_if_no_wallet()
36+
self.skip_if_no_previous_releases()
3537

3638
def setup_network(self):
3739
self.setup_nodes()
3840

3941
def setup_nodes(self):
40-
if os.getenv("TEST_PREVIOUS_RELEASES") == "false":
41-
raise SkipTest("upgradewallet RPC tests")
42-
43-
releases_path = os.getenv("PREVIOUS_RELEASES_DIR") or os.getcwd() + "/releases"
44-
if not os.path.isdir(releases_path):
45-
if os.getenv("TEST_PREVIOUS_RELEASES") == "true":
46-
raise AssertionError("TEST_PREVIOUS_RELEASES=1 but releases missing: " + releases_path)
47-
raise SkipTest("This test requires binaries for previous releases")
48-
4942
self.add_nodes(self.num_nodes, extra_args=self.extra_args, versions=[
5043
None,
5144
160300,
52-
150200
53-
], binary=[
54-
self.options.bitcoind,
55-
releases_path + "/v0.16.3/bin/bitcoind",
56-
releases_path + "/v0.15.2/bin/bitcoind",
57-
], binary_cli=[
58-
self.options.bitcoincli,
59-
releases_path + "/v0.16.3/bin/bitcoin-cli",
60-
releases_path + "/v0.15.2/bin/bitcoin-cli",
45+
150200,
6146
])
6247
# adapt bitcoin.conf, because older bitcoind's don't recognize config sections
6348
adjust_bitcoin_conf_for_pre_17(self.nodes[1].bitcoinconf)

0 commit comments

Comments
 (0)