diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/rpc_misc.py | 8 | ||||
-rwxr-xr-x | test/functional/test_framework/test_framework.py | 19 | ||||
-rwxr-xr-x | test/functional/test_runner.py | 8 | ||||
-rwxr-xr-x | test/functional/wallet_import_rescan.py | 25 | ||||
-rwxr-xr-x | test/lint/lint-all.sh | 8 |
5 files changed, 46 insertions, 22 deletions
diff --git a/test/functional/rpc_misc.py b/test/functional/rpc_misc.py index 7bf8e68176..8a3f8c6f06 100755 --- a/test/functional/rpc_misc.py +++ b/test/functional/rpc_misc.py @@ -46,5 +46,13 @@ class RpcMiscTest(BitcoinTestFramework): assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar") + self.log.info("test logging") + assert_equal(node.logging()['qt'], True) + node.logging(exclude=['qt']) + assert_equal(node.logging()['qt'], False) + node.logging(include=['qt']) + assert_equal(node.logging()['qt'], True) + + if __name__ == '__main__': RpcMiscTest().main() diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 555d55d97f..2187bf5f5f 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -10,6 +10,7 @@ import logging import argparse import os import pdb +import random import shutil import sys import tempfile @@ -129,6 +130,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): help="use bitcoin-cli instead of RPC for all commands") parser.add_argument("--perf", dest="perf", default=False, action="store_true", help="profile running nodes with perf for the duration of the test") + parser.add_argument("--randomseed", type=int, + help="set a random seed for deterministically reproducing a previous test run") self.add_options(parser) self.options = parser.parse_args() @@ -158,6 +161,22 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): self.options.tmpdir = tempfile.mkdtemp(prefix=TMPDIR_PREFIX) self._start_logging() + # Seed the PRNG. Note that test runs are reproducible if and only if + # a single thread accesses the PRNG. For more information, see + # https://docs.python.org/3/library/random.html#notes-on-reproducibility. + # The network thread shouldn't access random. If we need to change the + # network thread to access randomness, it should instantiate its own + # random.Random object. + seed = self.options.randomseed + + if seed is None: + seed = random.randrange(sys.maxsize) + else: + self.log.debug("User supplied random seed {}".format(seed)) + + random.seed(seed) + self.log.debug("PRNG seed is: {}".format(seed)) + self.log.debug('Setting up network thread') self.network_thread = NetworkThread() self.network_thread.start() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index ec5d6f1715..ece0059f74 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -401,16 +401,18 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage= print_results(test_results, max_len_name, (int(time.time() - start_time))) if coverage: - coverage.report_rpc_coverage() + coverage_passed = coverage.report_rpc_coverage() logging.debug("Cleaning up coverage data") coverage.cleanup() + else: + coverage_passed = True # Clear up the temp directory if all subdirectories are gone if not os.listdir(tmpdir): os.rmdir(tmpdir) - all_passed = all(map(lambda test_result: test_result.was_successful, test_results)) + all_passed = all(map(lambda test_result: test_result.was_successful, test_results)) and coverage_passed # This will be a no-op unless failfast is True in which case there may be dangling # processes which need to be killed. @@ -612,8 +614,10 @@ class RPCCoverage(): if uncovered: print("Uncovered RPC commands:") print("".join((" - %s\n" % command) for command in sorted(uncovered))) + return False else: print("All RPC commands covered.") + return True def cleanup(self): return shutil.rmtree(self.dir) diff --git a/test/functional/wallet_import_rescan.py b/test/functional/wallet_import_rescan.py index 9de30d0374..47c97f62bf 100755 --- a/test/functional/wallet_import_rescan.py +++ b/test/functional/wallet_import_rescan.py @@ -21,7 +21,6 @@ happened previously. from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( - assert_raises_rpc_error, connect_nodes, assert_equal, set_node_times, @@ -39,23 +38,17 @@ Rescan = enum.Enum("Rescan", "no yes late_timestamp") class Variant(collections.namedtuple("Variant", "call data rescan prune")): """Helper for importing one key and verifying scanned transactions.""" - def try_rpc(self, func, *args, **kwargs): - if self.expect_disabled: - assert_raises_rpc_error(-4, "Rescan is disabled in pruned mode", func, *args, **kwargs) - else: - return func(*args, **kwargs) - def do_import(self, timestamp): """Call one key import RPC.""" rescan = self.rescan == Rescan.yes if self.call == Call.single: if self.data == Data.address: - response = self.try_rpc(self.node.importaddress, address=self.address["address"], label=self.label, rescan=rescan) + response = self.node.importaddress(address=self.address["address"], label=self.label, rescan=rescan) elif self.data == Data.pub: - response = self.try_rpc(self.node.importpubkey, pubkey=self.address["pubkey"], label=self.label, rescan=rescan) + response = self.node.importpubkey(pubkey=self.address["pubkey"], label=self.label, rescan=rescan) elif self.data == Data.priv: - response = self.try_rpc(self.node.importprivkey, privkey=self.key, label=self.label, rescan=rescan) + response = self.node.importprivkey(privkey=self.key, label=self.label, rescan=rescan) assert_equal(response, None) elif self.call in (Call.multiaddress, Call.multiscript): @@ -172,8 +165,7 @@ class ImportRescanTest(BitcoinTestFramework): # check the results from getbalance and listtransactions. for variant in IMPORT_VARIANTS: self.log.info('Run import for variant {}'.format(variant)) - variant.expect_disabled = variant.rescan == Rescan.yes and variant.prune and variant.call == Call.single - expect_rescan = variant.rescan == Rescan.yes and not variant.expect_disabled + expect_rescan = variant.rescan == Rescan.yes variant.node = self.nodes[2 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))] variant.do_import(timestamp) if expect_rescan: @@ -198,12 +190,9 @@ class ImportRescanTest(BitcoinTestFramework): # Check the latest results from getbalance and listtransactions. for variant in IMPORT_VARIANTS: self.log.info('Run check for variant {}'.format(variant)) - if not variant.expect_disabled: - variant.expected_balance += variant.sent_amount - variant.expected_txs += 1 - variant.check(variant.sent_txid, variant.sent_amount, 1) - else: - variant.check() + variant.expected_balance += variant.sent_amount + variant.expected_txs += 1 + variant.check(variant.sent_txid, variant.sent_amount, 1) if __name__ == "__main__": ImportRescanTest().main() diff --git a/test/lint/lint-all.sh b/test/lint/lint-all.sh index 7c4f96cb3b..fabc24c91b 100755 --- a/test/lint/lint-all.sh +++ b/test/lint/lint-all.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Copyright (c) 2017 The Bitcoin Core developers +# Copyright (c) 2017-2019 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # @@ -16,11 +16,15 @@ set -u SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") LINTALL=$(basename "${BASH_SOURCE[0]}") +EXIT_CODE=0 + for f in "${SCRIPTDIR}"/lint-*.sh; do if [ "$(basename "$f")" != "$LINTALL" ]; then if ! "$f"; then echo "^---- failure generated from $f" - exit 1 + EXIT_CODE=1 fi fi done + +exit ${EXIT_CODE} |