aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/mempool_persist.py41
-rwxr-xr-xtest/functional/sendheaders.py16
-rwxr-xr-xtest/functional/test_framework/mininode.py2
3 files changed, 30 insertions, 29 deletions
diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py
index c22b7ff020..7b15476ea2 100755
--- a/test/functional/mempool_persist.py
+++ b/test/functional/mempool_persist.py
@@ -6,11 +6,11 @@
By default, bitcoind will dump mempool on shutdown and
then reload it on startup. This can be overridden with
-the -persistmempool=false command line option.
+the -persistmempool=0 command line option.
Test is as follows:
- - start node0, node1 and node2. node1 has -persistmempool=false
+ - start node0, node1 and node2. node1 has -persistmempool=0
- create 5 transactions on node2 to its own address. Note that these
are not sent to node0 or node1 addresses because we don't want
them to be saved in the wallet.
@@ -20,17 +20,19 @@ Test is as follows:
in its mempool. Shutdown node0. This tests that by default the
mempool is persistent.
- startup node1. Verify that its mempool is empty. Shutdown node1.
- This tests that with -persistmempool=false, the mempool is not
+ This tests that with -persistmempool=0, the mempool is not
dumped to disk when the node is shut down.
- - Restart node0 with -persistmempool=false. Verify that its mempool is
- empty. Shutdown node0. This tests that with -persistmempool=false,
+ - Restart node0 with -persistmempool=0. Verify that its mempool is
+ empty. Shutdown node0. This tests that with -persistmempool=0,
the mempool is not loaded from disk on start up.
- - Restart node0 with -persistmempool=true. Verify that it has 5
- transactions in its mempool. This tests that -persistmempool=false
+ - Restart node0 with -persistmempool. Verify that it has 5
+ transactions in its mempool. This tests that -persistmempool=0
does not overwrite a previously valid mempool stored on disk.
"""
+import time
+from test_framework.mininode import wait_until
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
@@ -38,18 +40,10 @@ class MempoolPersistTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
+ # We need 3 nodes for this test. Node1 does not have a persistent mempool.
self.num_nodes = 3
self.setup_clean_chain = False
-
- def setup_network(self):
- # We need 3 nodes for this test. Node1 does not have a persistent mempool.
- self.nodes = []
- self.nodes.append(start_node(0, self.options.tmpdir))
- self.nodes.append(start_node(1, self.options.tmpdir, ["-persistmempool=false"]))
- self.nodes.append(start_node(2, self.options.tmpdir))
- connect_nodes_bi(self.nodes, 0, 2)
- connect_nodes_bi(self.nodes, 1, 2)
- self.is_network_split = False
+ self.extra_args = [[], ["-persistmempool=0"], []]
def run_test(self):
chain_height = self.nodes[0].getblockcount()
@@ -57,6 +51,7 @@ class MempoolPersistTest(BitcoinTestFramework):
self.log.debug("Mine a single block to get out of IBD")
self.nodes[0].generate(1)
+ self.sync_all()
self.log.debug("Send 5 transactions from node2 (to its own address)")
for i in range(5):
@@ -72,20 +67,24 @@ class MempoolPersistTest(BitcoinTestFramework):
self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir))
self.nodes.append(start_node(1, self.options.tmpdir))
- assert_equal(len(self.nodes[0].getrawmempool()), 5)
+ # Give bitcoind a second to reload the mempool
+ time.sleep(1)
+ assert wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
assert_equal(len(self.nodes[1].getrawmempool()), 0)
- self.log.debug("Stop-start node0 with -persistmempool=false. Verify that it doesn't load its mempool.dat file.")
+ self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
stop_nodes(self.nodes)
self.nodes = []
- self.nodes.append(start_node(0, self.options.tmpdir, ["-persistmempool=false"]))
+ self.nodes.append(start_node(0, self.options.tmpdir, ["-persistmempool=0"]))
+ # Give bitcoind a second to reload the mempool
+ time.sleep(1)
assert_equal(len(self.nodes[0].getrawmempool()), 0)
self.log.debug("Stop-start node0. Verify that it has the transactions in its mempool.")
stop_nodes(self.nodes)
self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir))
- assert_equal(len(self.nodes[0].getrawmempool()), 5)
+ assert wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
if __name__ == '__main__':
MempoolPersistTest().main()
diff --git a/test/functional/sendheaders.py b/test/functional/sendheaders.py
index 97d64c0d98..44c357c6db 100755
--- a/test/functional/sendheaders.py
+++ b/test/functional/sendheaders.py
@@ -243,7 +243,7 @@ class SendHeadersTest(BitcoinTestFramework):
if i == 0:
# first request the block
test_node.get_data([tip])
- test_node.wait_for_block(tip, timeout=5)
+ test_node.wait_for_block(tip)
elif i == 1:
# next try requesting header and block
test_node.get_headers(locator=[old_tip], hashstop=tip)
@@ -258,7 +258,7 @@ class SendHeadersTest(BitcoinTestFramework):
new_block = create_block(tip, create_coinbase(height+1), block_time)
new_block.solve()
test_node.send_header_for_blocks([new_block])
- test_node.wait_for_getdata([new_block.sha256], timeout=5)
+ test_node.wait_for_getdata([new_block.sha256])
test_node.send_message(msg_block(new_block))
test_node.sync_with_ping() # make sure this block is processed
inv_node.clear_last_announcement()
@@ -297,18 +297,18 @@ class SendHeadersTest(BitcoinTestFramework):
if j == 0:
# Announce via inv
test_node.send_block_inv(tip)
- test_node.wait_for_getheaders(timeout=5)
+ test_node.wait_for_getheaders()
# Should have received a getheaders now
test_node.send_header_for_blocks(blocks)
# Test that duplicate inv's won't result in duplicate
# getdata requests, or duplicate headers announcements
[ inv_node.send_block_inv(x.sha256) for x in blocks ]
- test_node.wait_for_getdata([x.sha256 for x in blocks], timeout=5)
+ test_node.wait_for_getdata([x.sha256 for x in blocks])
inv_node.sync_with_ping()
else:
# Announce via headers
test_node.send_header_for_blocks(blocks)
- test_node.wait_for_getdata([x.sha256 for x in blocks], timeout=5)
+ test_node.wait_for_getdata([x.sha256 for x in blocks])
# Test that duplicate headers won't result in duplicate
# getdata requests (the check is further down)
inv_node.send_header_for_blocks(blocks)
@@ -495,7 +495,7 @@ class SendHeadersTest(BitcoinTestFramework):
with mininode_lock:
test_node.last_message.pop("getheaders", None)
test_node.send_header_for_blocks([blocks[1]])
- test_node.wait_for_getheaders(timeout=1)
+ test_node.wait_for_getheaders()
test_node.send_header_for_blocks(blocks)
test_node.wait_for_getdata([x.sha256 for x in blocks])
[ test_node.send_message(msg_block(x)) for x in blocks ]
@@ -518,7 +518,7 @@ class SendHeadersTest(BitcoinTestFramework):
with mininode_lock:
test_node.last_message.pop("getheaders", None)
test_node.send_header_for_blocks([blocks[i]])
- test_node.wait_for_getheaders(timeout=1)
+ test_node.wait_for_getheaders()
# Next header will connect, should re-set our count:
test_node.send_header_for_blocks([blocks[0]])
@@ -533,7 +533,7 @@ class SendHeadersTest(BitcoinTestFramework):
with mininode_lock:
test_node.last_message.pop("getheaders", None)
test_node.send_header_for_blocks([blocks[i%len(blocks)]])
- test_node.wait_for_getheaders(timeout=1)
+ test_node.wait_for_getheaders()
# Eventually this stops working.
test_node.send_header_for_blocks([blocks[-1]])
diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py
index 70bba566c7..fb3ed1473a 100755
--- a/test/functional/test_framework/mininode.py
+++ b/test/functional/test_framework/mininode.py
@@ -1358,6 +1358,8 @@ class msg_reject(object):
# Helper function
def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf')):
+ if attempts == float('inf') and timeout == float('inf'):
+ timeout = 60
attempt = 0
elapsed = 0