From cfebd400ef4b26f5b6c1d8b31c6f5e0f09184dba Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Tue, 20 Feb 2018 13:20:36 +0900 Subject: [PATCH 1/9] [test] Round target fee to 8 decimals in assert_fee_amount The output would produce arbitrary number of decimal points, sometimes resulting in 9 decimals: AssertionError: Fee of 0.00000415 BTC too low! (Should be 0.000006175 BTC) The above looks like the expected fee is 6175 sats when in reality it's 618. Github-Pull: #12486 Rebased-From: 42e1b5d9797b65d3ce13a7cbace15fbedbcd4018 --- test/functional/test_framework/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 7fdc17133..644f2d868 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -26,7 +26,7 @@ logger = logging.getLogger("TestFramework.utils") def assert_fee_amount(fee, tx_size, fee_per_kB): """Assert the fee was in range""" - target_fee = tx_size * fee_per_kB / 1000 + target_fee = round(tx_size * fee_per_kB / 1000, 8) if fee < target_fee: raise AssertionError("Fee of %s BTC too low! (Should be %s BTC)" % (str(fee), str(target_fee))) # allow the wallet's estimation to be at most 2 bytes off From 1286f3e49a7bdae72ae022ff4f83d0a77e832891 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 20 Feb 2018 21:25:02 -0800 Subject: [PATCH 2/9] test: Use wait_until to ensure ping goes out Intermittent failure evident here: https://travis-ci.org/bitcoin/bitcoin/jobs/344021180 Github-Pull: #12545 Rebased-From: 0eb84f30d80847b7392ad42b2d916eaf5923a63c --- test/functional/rpc_net.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 16e4f6adb..5f34b35bf 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -15,6 +15,7 @@ from test_framework.util import ( assert_raises_rpc_error, connect_nodes_bi, p2p_port, + wait_until, ) class NetTest(BitcoinTestFramework): @@ -47,14 +48,13 @@ class NetTest(BitcoinTestFramework): # the bytes sent/received should change # note ping and pong are 32 bytes each self.nodes[0].ping() - time.sleep(0.1) + wait_until(lambda: (net_totals['totalbytessent'] + 32*2) == self.nodes[0].getnettotals()['totalbytessent'], timeout=1) + wait_until(lambda: (net_totals['totalbytesrecv'] + 32*2) == self.nodes[0].getnettotals()['totalbytesrecv'], timeout=1) + peer_info_after_ping = self.nodes[0].getpeerinfo() - net_totals_after_ping = self.nodes[0].getnettotals() for before, after in zip(peer_info, peer_info_after_ping): assert_equal(before['bytesrecv_per_msg']['pong'] + 32, after['bytesrecv_per_msg']['pong']) assert_equal(before['bytessent_per_msg']['ping'] + 32, after['bytessent_per_msg']['ping']) - assert_equal(net_totals['totalbytesrecv'] + 32*2, net_totals_after_ping['totalbytesrecv']) - assert_equal(net_totals['totalbytessent'] + 32*2, net_totals_after_ping['totalbytessent']) def _test_getnetworkinginfo(self): assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) From 0e98f96e42357ac24322a96f0864b6bfd5e55ffe Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 26 Feb 2018 14:04:41 -0800 Subject: [PATCH 3/9] test: Use wait_until in tests where time was used for polling Github-Pull: #12553 Rebased-From: 81b0822772169cb697b5994f49398e619d61a12d --- test/functional/feature_pruning.py | 15 ++++----------- test/functional/feature_reindex.py | 7 ++----- test/functional/rpc_net.py | 10 ++-------- test/functional/test_framework/util.py | 11 +++-------- test/functional/wallet_basic.py | 4 ++-- 5 files changed, 13 insertions(+), 34 deletions(-) diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index 49ad7f838..cb2dd1f6a 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -11,7 +11,6 @@ This test takes 30 mins or more (up to 2 hours) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import * -import time import os MIN_BLOCKS_TO_KEEP = 288 @@ -79,11 +78,8 @@ class PruneTest(BitcoinTestFramework): for i in range(25): mine_large_block(self.nodes[0], self.utxo_cache_0) - waitstart = time.time() - while os.path.isfile(self.prunedir+"blk00000.dat"): - time.sleep(0.1) - if time.time() - waitstart > 30: - raise AssertionError("blk00000.dat not pruned when it should be") + # Wait for blk00000.dat to be pruned + wait_until(lambda: not os.path.isfile(self.prunedir+"blk00000.dat"), timeout=30) self.log.info("Success") usage = calc_usage(self.prunedir) @@ -218,11 +214,8 @@ class PruneTest(BitcoinTestFramework): goalbestheight = first_reorg_height + 1 self.log.info("Verify node 2 reorged back to the main chain, some blocks of which it had to redownload") - waitstart = time.time() - while self.nodes[2].getblockcount() < goalbestheight: - time.sleep(0.1) - if time.time() - waitstart > 900: - raise AssertionError("Node 2 didn't reorg to proper height") + # Wait for Node 2 to reorg to proper height + wait_until(lambda: self.nodes[2].getblockcount() >= goalbestheight, timeout=900) assert(self.nodes[2].getbestblockhash() == goalbesthash) # Verify we can now have the data for a block previously pruned assert(self.nodes[2].getblock(self.forkhash)["height"] == self.forkheight) diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py index ac67e6e9b..d1d3f1d7f 100755 --- a/test/functional/feature_reindex.py +++ b/test/functional/feature_reindex.py @@ -10,8 +10,7 @@ """ from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal -import time +from test_framework.util import wait_until class ReindexTest(BitcoinTestFramework): @@ -25,9 +24,7 @@ class ReindexTest(BitcoinTestFramework): self.stop_nodes() extra_args = [["-reindex-chainstate" if justchainstate else "-reindex", "-checkblockindex=1"]] self.start_nodes(extra_args) - while self.nodes[0].getblockcount() < blockcount: - time.sleep(0.1) - assert_equal(self.nodes[0].getblockcount(), blockcount) + wait_until(lambda: self.nodes[0].getblockcount() == blockcount) self.log.info("Success") def run_test(self): diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 5f34b35bf..d8348432a 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -7,8 +7,6 @@ Tests correspond to code in rpc/net.cpp. """ -import time - from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -62,12 +60,8 @@ class NetTest(BitcoinTestFramework): self.nodes[0].setnetworkactive(False) assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False) - timeout = 3 - while self.nodes[0].getnetworkinfo()['connections'] != 0: - # Wait a bit for all sockets to close - assert timeout > 0, 'not all connections closed in time' - timeout -= 0.1 - time.sleep(0.1) + # Wait a bit for all sockets to close + wait_until(lambda: self.nodes[0].getnetworkinfo()['connections'] == 0, timeout=3) self.nodes[0].setnetworkactive(True) connect_nodes_bi(self.nodes, 0, 1) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 644f2d868..db259db8e 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -334,20 +334,15 @@ def disconnect_nodes(from_connection, node_num): for peer_id in [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']]: from_connection.disconnectnode(nodeid=peer_id) - for _ in range(50): - if [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == []: - break - time.sleep(0.1) - else: - raise AssertionError("timed out waiting for disconnect") + # wait to disconnect + wait_until(lambda: [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == [], timeout=5) def connect_nodes(from_connection, node_num): ip_port = "127.0.0.1:" + str(p2p_port(node_num)) from_connection.addnode(ip_port, "onetry") # poll until version handshake complete to avoid race conditions # with transaction relaying - while any(peer['version'] == 0 for peer in from_connection.getpeerinfo()): - time.sleep(0.1) + wait_until(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo())) def connect_nodes_bi(nodes, a, b): connect_nodes(nodes[a], b) diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index a90dbc8ad..06300d3de 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -379,9 +379,9 @@ class WalletTest(BitcoinTestFramework): self.start_node(0, [m, "-limitancestorcount="+str(chainlimit)]) self.start_node(1, [m, "-limitancestorcount="+str(chainlimit)]) self.start_node(2, [m, "-limitancestorcount="+str(chainlimit)]) - while m == '-reindex' and [block_count] * 3 != [self.nodes[i].getblockcount() for i in range(3)]: + if m == '-reindex': # reindex will leave rpc warm up "early"; Wait for it to finish - time.sleep(0.1) + wait_until(lambda: [block_count] * 3 == [self.nodes[i].getblockcount() for i in range(3)]) assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)]) # Exercise listsinceblock with the last two blocks From 4bdb0ce5172b511c1426f5ae839c6b66706d8b62 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 27 Mar 2018 17:18:01 -0400 Subject: [PATCH 4/9] [tests] Fix intermittent rpc_net.py failure. rpc_net.py would intermittently fail on Travis, probably due to assuming that two consecutive RPC calls were atomic. Fix this by only testing that amounts are bounded above and below rather than equal. Github-Pull: #12804 Rebased-From: 5a67c0524e5dc98d0e387f189545bc99863916d4 --- test/functional/rpc_net.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index d8348432a..72b5f4748 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -10,6 +10,7 @@ Tests correspond to code in rpc/net.cpp. from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, + assert_greater_than_or_equal, assert_raises_rpc_error, connect_nodes_bi, p2p_port, @@ -33,26 +34,34 @@ class NetTest(BitcoinTestFramework): assert_equal(self.nodes[0].getconnectioncount(), 2) def _test_getnettotals(self): - # check that getnettotals totalbytesrecv and totalbytessent - # are consistent with getpeerinfo + # getnettotals totalbytesrecv and totalbytessent should be + # consistent with getpeerinfo. Since the RPC calls are not atomic, + # and messages might have been recvd or sent between RPC calls, call + # getnettotals before and after and verify that the returned values + # from getpeerinfo are bounded by those values. + net_totals_before = self.nodes[0].getnettotals() peer_info = self.nodes[0].getpeerinfo() + net_totals_after = self.nodes[0].getnettotals() assert_equal(len(peer_info), 2) - net_totals = self.nodes[0].getnettotals() - assert_equal(sum([peer['bytesrecv'] for peer in peer_info]), - net_totals['totalbytesrecv']) - assert_equal(sum([peer['bytessent'] for peer in peer_info]), - net_totals['totalbytessent']) + peers_recv = sum([peer['bytesrecv'] for peer in peer_info]) + peers_sent = sum([peer['bytessent'] for peer in peer_info]) + + assert_greater_than_or_equal(peers_recv, net_totals_before['totalbytesrecv']) + assert_greater_than_or_equal(net_totals_after['totalbytesrecv'], peers_recv) + assert_greater_than_or_equal(peers_sent, net_totals_before['totalbytessent']) + assert_greater_than_or_equal(net_totals_after['totalbytessent'], peers_sent) + # test getnettotals and getpeerinfo by doing a ping # the bytes sent/received should change # note ping and pong are 32 bytes each self.nodes[0].ping() - wait_until(lambda: (net_totals['totalbytessent'] + 32*2) == self.nodes[0].getnettotals()['totalbytessent'], timeout=1) - wait_until(lambda: (net_totals['totalbytesrecv'] + 32*2) == self.nodes[0].getnettotals()['totalbytesrecv'], timeout=1) + wait_until(lambda: (self.nodes[0].getnettotals()['totalbytessent'] >= net_totals_after['totalbytessent'] + 32 * 2), timeout=1) + wait_until(lambda: (self.nodes[0].getnettotals()['totalbytesrecv'] >= net_totals_after['totalbytesrecv'] + 32 * 2), timeout=1) peer_info_after_ping = self.nodes[0].getpeerinfo() for before, after in zip(peer_info, peer_info_after_ping): - assert_equal(before['bytesrecv_per_msg']['pong'] + 32, after['bytesrecv_per_msg']['pong']) - assert_equal(before['bytessent_per_msg']['ping'] + 32, after['bytessent_per_msg']['ping']) + assert_greater_than_or_equal(after['bytesrecv_per_msg']['pong'], before['bytesrecv_per_msg']['pong'] + 32) + assert_greater_than_or_equal(after['bytessent_per_msg']['ping'], before['bytessent_per_msg']['ping'] + 32) def _test_getnetworkinginfo(self): assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) @@ -78,8 +87,7 @@ class NetTest(BitcoinTestFramework): assert_equal(len(added_nodes), 1) assert_equal(added_nodes[0]['addednode'], ip_port) # check that a non-existent node returns an error - assert_raises_rpc_error(-24, "Node has not been added", - self.nodes[0].getaddednodeinfo, '1.1.1.1') + assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1') def _test_getpeerinfo(self): peer_info = [x.getpeerinfo() for x in self.nodes] From df38b130d957afbeda8be34a649f6e406f4c79b3 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 30 Mar 2018 11:36:38 -0400 Subject: [PATCH 5/9] [tests] Test starting bitcoind with -h and -version Github-Pull: #12843 Rebased-From: 63048ec73d790ecbcfe3186f2520dac4460f56e3 --- test/functional/feature_help.py | 42 +++++++++++++++++++++++++++++++++ test/functional/test_runner.py | 1 + 2 files changed, 43 insertions(+) create mode 100755 test/functional/feature_help.py diff --git a/test/functional/feature_help.py b/test/functional/feature_help.py new file mode 100755 index 000000000..1e62d7a40 --- /dev/null +++ b/test/functional/feature_help.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# Copyright (c) 2018 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Verify that starting bitcoin with -h works as expected.""" +import subprocess + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal + +class HelpTest(BitcoinTestFramework): + def set_test_params(self): + self.setup_clean_chain = True + self.num_nodes = 1 + + def setup_network(self): + self.add_nodes(self.num_nodes) + # Don't start the node + + def run_test(self): + self.log.info("Start bitcoin with -h for help text") + self.nodes[0].start(extra_args=['-h'], stderr=subprocess.PIPE, stdout=subprocess.PIPE) + # Node should exit immediately and output help to stdout. + ret_code = self.nodes[0].process.wait(timeout=1) + assert_equal(ret_code, 0) + output = self.nodes[0].process.stdout.read() + assert b'Options' in output + self.log.info("Help text received: {} (...)".format(output[0:60])) + self.nodes[0].running = False + + self.log.info("Start bitcoin with -version for version information") + self.nodes[0].start(extra_args=['-version'], stderr=subprocess.PIPE, stdout=subprocess.PIPE) + # Node should exit immediately and output version to stdout. + ret_code = self.nodes[0].process.wait(timeout=1) + assert_equal(ret_code, 0) + output = self.nodes[0].process.stdout.read() + assert b'version' in output + self.log.info("Version text received: {} (...)".format(output[0:60])) + self.nodes[0].running = False + +if __name__ == '__main__': + HelpTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 98944685e..fbd155438 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -133,6 +133,7 @@ BASE_SCRIPTS= [ 'feature_logging.py', 'p2p_node_network_limited.py', 'feature_config_args.py', + 'feature_help.py', # Don't append tests at the end to avoid merge conflicts # Put them in a random line within the section that fits their approximate run-time ] From 6c26df06adc55ef7c27891a52a8feccec58b4aea Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Fri, 6 Apr 2018 10:53:35 -0400 Subject: [PATCH 6/9] [qa] Ensure bitcoind processes are cleaned up when tests end Github-Pull: #12904 Rebased-From: e36a0c08529bccc695ec71a7ec1df89367cc1628 --- test/functional/feature_help.py | 4 ++++ test/functional/test_framework/test_framework.py | 2 ++ test/functional/test_framework/test_node.py | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/test/functional/feature_help.py b/test/functional/feature_help.py index 1e62d7a40..fd4a72f62 100755 --- a/test/functional/feature_help.py +++ b/test/functional/feature_help.py @@ -36,7 +36,11 @@ class HelpTest(BitcoinTestFramework): output = self.nodes[0].process.stdout.read() assert b'version' in output self.log.info("Version text received: {} (...)".format(output[0:60])) + # Clean up TestNode state self.nodes[0].running = False + self.nodes[0].process = None + self.nodes[0].rpc_connected = False + self.nodes[0].rpc = None if __name__ == '__main__': HelpTest().main() diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index f8d66def6..9dc2e5a08 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -145,6 +145,8 @@ class BitcoinTestFramework(): if self.nodes: self.stop_nodes() else: + for node in self.nodes: + node.cleanup_on_exit = False self.log.info("Note: bitcoinds were not stopped and may still be running") if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED: diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 1054e6d02..19db11d8a 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -70,9 +70,20 @@ class TestNode(): self.rpc = None self.url = None self.log = logging.getLogger('TestFramework.node%d' % i) + self.cleanup_on_exit = True # Whether to kill the node when this object goes away self.p2ps = [] + def __del__(self): + # Ensure that we don't leave any bitcoind processes lying around after + # the test ends + if self.process and self.cleanup_on_exit: + # Should only happen on test failure + # Avoid using logger, as that may have already been shutdown when + # this destructor is called. + print("Cleaning up leftover process") + self.process.kill() + def __getattr__(self, name): """Dispatches any unrecognised messages to the RPC connection or a CLI instance.""" if self.use_cli: From 0a76ed232a6c448a8666234a2c190db37e3498e7 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 7 Mar 2018 13:49:44 -0500 Subject: [PATCH 7/9] qa: Cache only chain and wallet for regtest datadir Github-Pull: #12638 Rebased-From: fa2310572f4cfcd3322409ce7e37dde155fc4bc9 --- .../test_framework/test_framework.py | 23 +++++++++++-------- test/functional/test_framework/util.py | 3 --- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 9dc2e5a08..59ec5117e 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -24,8 +24,8 @@ from .util import ( check_json_precision, connect_nodes_bi, disconnect_nodes, + get_datadir_path, initialize_datadir, - log_filename, p2p_port, set_node_times, sync_blocks, @@ -374,7 +374,7 @@ class BitcoinTestFramework(): assert self.num_nodes <= MAX_NODES create_cache = False for i in range(MAX_NODES): - if not os.path.isdir(os.path.join(self.options.cachedir, 'node' + str(i))): + if not os.path.isdir(get_datadir_path(self.options.cachedir, i)): create_cache = True break @@ -383,8 +383,8 @@ class BitcoinTestFramework(): # find and delete old cache directories if any exist for i in range(MAX_NODES): - if os.path.isdir(os.path.join(self.options.cachedir, "node" + str(i))): - shutil.rmtree(os.path.join(self.options.cachedir, "node" + str(i))) + if os.path.isdir(get_datadir_path(self.options.cachedir, i)): + shutil.rmtree(get_datadir_path(self.options.cachedir, i)) # Create cache directories, run bitcoinds: for i in range(MAX_NODES): @@ -422,15 +422,18 @@ class BitcoinTestFramework(): self.stop_nodes() self.nodes = [] self.disable_mocktime() + + def cache_path(n, *paths): + return os.path.join(get_datadir_path(self.options.cachedir, n), "regtest", *paths) + for i in range(MAX_NODES): - os.remove(log_filename(self.options.cachedir, i, "debug.log")) - os.remove(log_filename(self.options.cachedir, i, "wallets/db.log")) - os.remove(log_filename(self.options.cachedir, i, "peers.dat")) - os.remove(log_filename(self.options.cachedir, i, "fee_estimates.dat")) + for entry in os.listdir(cache_path(i)): + if entry not in ['wallets', 'chainstate', 'blocks']: + os.remove(cache_path(i, entry)) for i in range(self.num_nodes): - from_dir = os.path.join(self.options.cachedir, "node" + str(i)) - to_dir = os.path.join(self.options.tmpdir, "node" + str(i)) + from_dir = get_datadir_path(self.options.cachedir, i) + to_dir = get_datadir_path(self.options.tmpdir, i) shutil.copytree(from_dir, to_dir) initialize_datadir(self.options.tmpdir, i) # Overwrite port/rpcport in bitcoin.conf diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index db259db8e..538ae7691 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -319,9 +319,6 @@ def get_auth_cookie(datadir): raise ValueError("No RPC credentials") return user, password -def log_filename(dirname, n_node, logname): - return os.path.join(dirname, "node" + str(n_node), "regtest", logname) - def get_bip9_status(node, key): info = node.getblockchaininfo() return info['bip9_softforks'][key] From 7460945e0b663585a7af3cde6c8675cbe21b4111 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Mon, 9 Apr 2018 14:07:47 -0400 Subject: [PATCH 8/9] [qa] Delete cookie file before starting node If a cookie file exists in a datadir prior to node startup, it must have been leftover from a prior unclean shutdown. As bitcoind will overwrite it anyway, delete it before starting up to prevent the test framework from inadvertently trying to connect using stale credentials. Github-Pull: #12902 Rebased-From: 75d0e4c5444249f0cf81ed0494e2c2717170b695 --- test/functional/test_framework/test_node.py | 5 +++++ test/functional/test_framework/util.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 19db11d8a..f6e487129 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -17,6 +17,7 @@ import time from .authproxy import JSONRPCException from .util import ( assert_equal, + delete_cookie_file, get_rpc_proxy, rpc_url, wait_until, @@ -98,6 +99,10 @@ class TestNode(): extra_args = self.extra_args if stderr is None: stderr = self.stderr + # Delete any existing cookie file -- if such a file exists (eg due to + # unclean shutdown), it will get overwritten anyway by bitcoind, and + # potentially interfere with our attempt to authenticate + delete_cookie_file(self.datadir) self.process = subprocess.Popen(self.args + extra_args, stderr=stderr, *args, **kwargs) self.running = True self.log.debug("bitcoind started, waiting for RPC to come up") diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 538ae7691..ead1f844f 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -319,6 +319,12 @@ def get_auth_cookie(datadir): raise ValueError("No RPC credentials") return user, password +# If a cookie file exists in the given datadir, delete it. +def delete_cookie_file(datadir): + if os.path.isfile(os.path.join(datadir, "regtest", ".cookie")): + logger.debug("Deleting leftover cookie file") + os.remove(os.path.join(datadir, "regtest", ".cookie")) + def get_bip9_status(node, key): info = node.getblockchaininfo() return info['bip9_softforks'][key] From 41c29f6d1df0f78cfeb0b688a0a1750c8b2e5c03 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sat, 17 Feb 2018 19:27:21 -0500 Subject: [PATCH 9/9] qa: Fix python TypeError in script.py Github-Pull: #12475 Rebased-From: fa41d68a2e3f2148c3539a11b61ff835e3141c0d --- test/functional/test_framework/script.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py index dae8a4e56..6fe0b445d 100644 --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -526,11 +526,9 @@ class CScript(bytes): yield CScriptOp(opcode) def __repr__(self): - # For Python3 compatibility add b before strings so testcases don't - # need to change def _repr(o): if isinstance(o, bytes): - return b"x('%s')" % hexlify(o).decode('ascii') + return "x('%s')" % hexlify(o).decode('ascii') else: return repr(o)