6
6
7
7
import configparser
8
8
from enum import Enum
9
- import logging
10
9
import argparse
10
+ import logging
11
11
import os
12
12
import pdb
13
13
import random
14
+ import re
14
15
import shutil
15
16
import subprocess
16
17
import sys
@@ -185,10 +186,11 @@ def setup(self):
185
186
self .options .bitcoind = os .getenv ("BITCOIND" , default = config ["environment" ]["BUILDDIR" ] + '/src/bitcoind' + config ["environment" ]["EXEEXT" ])
186
187
self .options .bitcoincli = os .getenv ("BITCOINCLI" , default = config ["environment" ]["BUILDDIR" ] + '/src/bitcoin-cli' + config ["environment" ]["EXEEXT" ])
187
188
189
+ self .options .previous_releases_path = os .getenv ("PREVIOUS_RELEASES_DIR" ) or os .getcwd () + "/releases"
190
+
188
191
os .environ ['PATH' ] = os .pathsep .join ([
189
192
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' ]
192
194
])
193
195
194
196
# 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
388
390
389
391
Should only be called once after the nodes have been specified in
390
392
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
+
391
412
if self .bind_to_localhost_only :
392
413
extra_confs = [["bind=127.0.0.1" ]] * num_nodes
393
414
else :
@@ -397,9 +418,9 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None, bi
397
418
if versions is None :
398
419
versions = [None ] * num_nodes
399
420
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 ]
401
422
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 ]
403
424
assert_equal (len (extra_confs ), num_nodes )
404
425
assert_equal (len (extra_args ), num_nodes )
405
426
assert_equal (len (versions ), num_nodes )
@@ -640,6 +661,25 @@ def skip_if_no_cli(self):
640
661
if not self .is_cli_compiled ():
641
662
raise SkipTest ("bitcoin-cli has not been compiled." )
642
663
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
+
643
683
def is_cli_compiled (self ):
644
684
"""Checks whether bitcoin-cli was compiled."""
645
685
return self .config ["components" ].getboolean ("ENABLE_CLI" )
0 commit comments