diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py index 98c7e803af..93309d4c2b 100755 --- a/contrib/devtools/github-merge.py +++ b/contrib/devtools/github-merge.py @@ -14,7 +14,6 @@ # In case of a clean merge that is accepted by the user, the local branch with # name $BRANCH is overwritten with the merged result, and optionally pushed. -from __future__ import division,print_function,unicode_literals import os from sys import stdin,stdout,stderr import argparse @@ -23,10 +22,7 @@ import subprocess import sys import json import codecs -try: - from urllib.request import Request,urlopen -except: - from urllib2 import Request,urlopen +from urllib.request import Request, urlopen # External tools (can be overridden using environment) GIT = os.getenv('GIT','git') diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py index 108058ac83..55c807432b 100755 --- a/contrib/linearize/linearize-data.py +++ b/contrib/linearize/linearize-data.py @@ -7,7 +7,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. # -from __future__ import print_function, division import struct import re import os diff --git a/contrib/linearize/linearize-hashes.py b/contrib/linearize/linearize-hashes.py index 9eefeb6dd8..ba33cb3f83 100755 --- a/contrib/linearize/linearize-hashes.py +++ b/contrib/linearize/linearize-hashes.py @@ -7,11 +7,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. # -from __future__ import print_function -try: # Python 3 - import http.client as httplib -except ImportError: # Python 2 - import httplib +from http.client import HttpConnection import json import re import base64 @@ -31,7 +27,7 @@ class BitcoinRPC: authpair = "%s:%s" % (username, password) authpair = authpair.encode('utf-8') self.authhdr = b"Basic " + base64.b64encode(authpair) - self.conn = httplib.HTTPConnection(host, port=port, timeout=30) + self.conn = HttpConnection(host, port=port, timeout=30) def execute(self, obj): try: diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index 789e158a12..bfb62fbc2d 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) static void AddRandomOutboundPeer(std::vector &vNodes, PeerLogicValidation &peerLogic, CConnmanTest* connman) { - CAddress addr(ip(insecure_rand_ctx.randbits(32)), NODE_NONE); + CAddress addr(ip(g_insecure_rand_ctx.randbits(32)), NODE_NONE); vNodes.emplace_back(new CNode(id++, ServiceFlags(NODE_NETWORK), 0, INVALID_SOCKET, addr, 0, 0, CAddress(), "", /*fInboundIn=*/ false)); CNode &node = *vNodes.back(); node.SetSendVersion(PROTOCOL_VERSION); diff --git a/src/test/test_dash.cpp b/src/test/test_dash.cpp index 4b8c568a7f..bacd35b8c7 100644 --- a/src/test/test_dash.cpp +++ b/src/test/test_dash.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -30,10 +31,7 @@ const std::function G_TRANSLATION_FUN = nullptr; -FastRandomContext insecure_rand_ctx; - -extern bool fPrintToConsole; -extern void noui_connect(); +thread_local FastRandomContext g_insecure_rand_ctx; std::ostream& operator<<(std::ostream& os, const uint256& num) { @@ -116,23 +114,23 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha TestingSetup::~TestingSetup() { - llmq::InterruptLLMQSystem(); - llmq::StopLLMQSystem(); - g_txindex->Interrupt(); - g_txindex->Stop(); - g_txindex.reset(); - threadGroup.interrupt_all(); - threadGroup.join_all(); - StopScriptCheckWorkerThreads(); - GetMainSignals().FlushBackgroundCallbacks(); - GetMainSignals().UnregisterBackgroundSignalScheduler(); - g_connman.reset(); - g_banman.reset(); - UnloadBlockIndex(); - pcoinsTip.reset(); - llmq::DestroyLLMQSystem(); - pcoinsdbview.reset(); - pblocktree.reset(); + llmq::InterruptLLMQSystem(); + llmq::StopLLMQSystem(); + g_txindex->Interrupt(); + g_txindex->Stop(); + g_txindex.reset(); + threadGroup.interrupt_all(); + threadGroup.join_all(); + StopScriptCheckWorkerThreads(); + GetMainSignals().FlushBackgroundCallbacks(); + GetMainSignals().UnregisterBackgroundSignalScheduler(); + g_connman.reset(); + g_banman.reset(); + UnloadBlockIndex(); + pcoinsTip.reset(); + llmq::DestroyLLMQSystem(); + pcoinsdbview.reset(); + pblocktree.reset(); } TestChainSetup::TestChainSetup(int blockCount) : TestingSetup(CBaseChainParams::REGTEST) diff --git a/src/test/test_dash.h b/src/test/test_dash.h index 41f25abf6f..2e9f0c7251 100644 --- a/src/test/test_dash.h +++ b/src/test/test_dash.h @@ -19,7 +19,7 @@ #include -extern FastRandomContext insecure_rand_ctx; +thread_local extern FastRandomContext g_insecure_rand_ctx; /** * Flag to make GetRand in random.h return the same number @@ -28,14 +28,14 @@ extern bool g_mock_deterministic_tests; static inline void SeedInsecureRand(bool deterministic = false) { - insecure_rand_ctx = FastRandomContext(deterministic); + g_insecure_rand_ctx = FastRandomContext(deterministic); } -static inline uint32_t InsecureRand32() { return insecure_rand_ctx.rand32(); } -static inline uint256 InsecureRand256() { return insecure_rand_ctx.rand256(); } -static inline uint64_t InsecureRandBits(int bits) { return insecure_rand_ctx.randbits(bits); } -static inline uint64_t InsecureRandRange(uint64_t range) { return insecure_rand_ctx.randrange(range); } -static inline bool InsecureRandBool() { return insecure_rand_ctx.randbool(); } +static inline uint32_t InsecureRand32() { return g_insecure_rand_ctx.rand32(); } +static inline uint256 InsecureRand256() { return g_insecure_rand_ctx.rand256(); } +static inline uint64_t InsecureRandBits(int bits) { return g_insecure_rand_ctx.randbits(bits); } +static inline uint64_t InsecureRandRange(uint64_t range) { return g_insecure_rand_ctx.randrange(range); } +static inline bool InsecureRandBool() { return g_insecure_rand_ctx.randbool(); } static constexpr CAmount CENT{1000000}; @@ -61,7 +61,7 @@ class CConnman; class CNode; class PeerLogicValidation; -struct TestingSetup: public BasicTestingSetup { +struct TestingSetup : public BasicTestingSetup { boost::thread_group threadGroup; CScheduler scheduler; diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 6184a33ecb..7e0f73e9fb 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -319,9 +319,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): assert_equal(len(extra_confs), num_nodes) assert_equal(len(extra_args), num_nodes) assert_equal(len(binary), num_nodes) - old_num_nodes = len(self.nodes) for i in range(num_nodes): - self.nodes.append(TestNode(old_num_nodes + i, get_datadir_path(self.options.tmpdir, old_num_nodes + i), self.extra_args_from_options, chain=self.chain, rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli)) + numnode = len(self.nodes) + self.nodes.append(TestNode(numnode, get_datadir_path(self.options.tmpdir, numnode), self.extra_args_from_options, chain=self.chain, rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli)) def start_node(self, i, *args, **kwargs): """Start a dashd""" diff --git a/test/util/bitcoin-util-test.py b/test/util/bitcoin-util-test.py index 268d1d7a41..4d89233291 100755 --- a/test/util/bitcoin-util-test.py +++ b/test/util/bitcoin-util-test.py @@ -9,14 +9,9 @@ Runs automatically during `make check`. Can also be run manually.""" -from __future__ import division,print_function,unicode_literals - import argparse import binascii -try: - import configparser -except ImportError: - import ConfigParser as configparser +import configparser import difflib import json import logging