66
77import configparser
88from enum import Enum
9- import logging
109import argparse
10+ import logging
1111import os
1212import pdb
1313import random
14+ import re
1415import shutil
1516import subprocess
1617import sys
@@ -185,10 +186,11 @@ def setup(self):
185186 self .options .bitcoind = os .getenv ("BITCOIND" , default = config ["environment" ]["BUILDDIR" ] + '/src/elementsd' + config ["environment" ]["EXEEXT" ])
186187 self .options .bitcoincli = os .getenv ("BITCOINCLI" , default = config ["environment" ]["BUILDDIR" ] + '/src/elements-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, chain=None, bin
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, chain=None, bin
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 , 'elementsd' , 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 , 'elements-cli' , self .options .bitcoincli ) for v in versions ]
403424 if chain is None :
404425 chain = [self .chain ] * num_nodes
405426 if chain_in_args is None :
@@ -647,6 +668,25 @@ def skip_if_no_cli(self):
647668 if not self .is_cli_compiled ():
648669 raise SkipTest ("bitcoin-cli has not been compiled." )
649670
671+ def skip_if_no_previous_releases (self ):
672+ """Skip the running test if previous releases are not available."""
673+ if not self .has_previous_releases ():
674+ raise SkipTest ("previous releases not available or disabled" )
675+
676+ def has_previous_releases (self ):
677+ """Checks whether previous releases are present and enabled."""
678+ if os .getenv ("TEST_PREVIOUS_RELEASES" ) == "false" :
679+ # disabled
680+ return False
681+
682+ if not os .path .isdir (self .options .previous_releases_path ):
683+ if os .getenv ("TEST_PREVIOUS_RELEASES" ) == "true" :
684+ raise AssertionError ("TEST_PREVIOUS_RELEASES=true but releases missing: {}" .format (
685+ self .options .previous_releases_path ))
686+ # missing
687+ return False
688+ return True
689+
650690 def is_cli_compiled (self ):
651691 """Checks whether bitcoin-cli was compiled."""
652692 return self .config ["components" ].getboolean ("ENABLE_CLI" )
0 commit comments