Skip to content

Commit

Permalink
qa: Actually test assertions in pruning.py
Browse files Browse the repository at this point in the history
Also refactor to use wrapper for stop_node
  • Loading branch information
MarcoFalke committed Jan 26, 2017
1 parent 9b4d267 commit fab035f
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions qa/rpc-tests/pruning.py
Expand Up @@ -103,7 +103,7 @@ def create_chain_with_staleblocks(self):
# Disconnect node 0 so it can mine a longer reorg chain without knowing about node 1's soon-to-be-stale chain
# Node 2 stays connected, so it hears about the stale blocks and then reorg's when node0 reconnects
# Stopping node 0 also clears its mempool, so it doesn't have node1's transactions to accidentally mine
stop_node(self.nodes[0],0)
self.stop_node(0)
self.nodes[0]=start_node(0, self.options.tmpdir, ["-debug","-maxreceivebuffer=20000","-blockmaxsize=999000", "-checkblocks=5"], timewait=900)
# Mine 24 blocks in node 1
for i in range(24):
Expand All @@ -128,7 +128,7 @@ def reorg_test(self):
# This will cause Node 2 to do a reorg requiring 288 blocks of undo data to the reorg_test chain
# Reboot node 1 to clear its mempool (hopefully make the invalidate faster)
# Lower the block max size so we don't keep mining all our big mempool transactions (from disconnected blocks)
stop_node(self.nodes[1],1)
self.stop_node(1)
self.nodes[1]=start_node(1, self.options.tmpdir, ["-debug","-maxreceivebuffer=20000","-blockmaxsize=5000", "-checkblocks=5", "-disablesafemode"], timewait=900)

height = self.nodes[1].getblockcount()
Expand All @@ -151,7 +151,7 @@ def reorg_test(self):
print("New best height", self.nodes[1].getblockcount())

# Reboot node1 to clear those giant tx's from mempool
stop_node(self.nodes[1],1)
self.stop_node(1)
self.nodes[1]=start_node(1, self.options.tmpdir, ["-debug","-maxreceivebuffer=20000","-blockmaxsize=5000", "-checkblocks=5", "-disablesafemode"], timewait=900)

print("Generating new longer chain of 300 more blocks")
Expand Down Expand Up @@ -231,7 +231,7 @@ def manual_test(self, node_number, use_timestamp):
node = self.nodes[node_number] = start_node(node_number, self.options.tmpdir, ["-debug=0"], timewait=900)
assert_equal(node.getblockcount(), 995)
assert_raises_message(JSONRPCException, "not in prune mode", node.pruneblockchain, 500)
stop_node(node, node_number)
self.stop_node(node_number)

# now re-start in manual pruning mode
node = self.nodes[node_number] = start_node(node_number, self.options.tmpdir, ["-debug=0","-prune=1"], timewait=900)
Expand Down Expand Up @@ -266,25 +266,21 @@ def has_block(index):

# mine 6 blocks so we are at height 1001 (i.e., above PruneAfterHeight)
node.generate(6)
assert_equal(node.getblockchaininfo()["blocks"], 1001)

# negative and zero inputs should raise an exception
try:
node.pruneblockchain(-10)
raise AssertionError("pruneblockchain(-10) should have failed.")
except:
pass

try:
node.pruneblockchain(0)
raise AssertionError("pruneblockchain(0) should have failed.")
except:
pass
# negative heights should raise an exception
assert_raises_message(JSONRPCException, "Negative", node.pruneblockchain, -10)

# height=100 too low to prune first block file so this is a no-op
prune(100)
if not has_block(0):
raise AssertionError("blk00000.dat is missing when should still be there")

# Does nothing
node.pruneblockchain(height(0))
if not has_block(0):
raise AssertionError("blk00000.dat is missing when should still be there")

# height=500 should prune first file
prune(500)
if has_block(0):
Expand All @@ -311,7 +307,7 @@ def has_block(index):
raise AssertionError("blk00003.dat is still there, should be pruned by now")

# stop node, start back up with auto-prune at 550MB, make sure still runs
stop_node(node, node_number)
self.stop_node(node_number)
self.nodes[node_number] = start_node(node_number, self.options.tmpdir, ["-debug=0","-prune=550"], timewait=900)

print("Success")
Expand All @@ -320,7 +316,7 @@ def wallet_test(self):
# check that the pruning node's wallet is still in good shape
print("Stop and start pruning node to trigger wallet rescan")
try:
stop_node(self.nodes[2], 2)
self.stop_node(2)
start_node(2, self.options.tmpdir, ["-debug=1","-prune=550"])
print("Success")
except Exception as detail:
Expand All @@ -333,7 +329,7 @@ def wallet_test(self):
nds = [self.nodes[0], self.nodes[5]]
sync_blocks(nds, wait=5, timeout=300)
try:
stop_node(self.nodes[5],5) #stop and start to trigger rescan
self.stop_node(5) #stop and start to trigger rescan
start_node(5, self.options.tmpdir, ["-debug=1","-prune=550"])
print ("Success")
except Exception as detail:
Expand All @@ -353,8 +349,8 @@ def run_test(self):
# N0=N1=N2 **...*(995)

# stop manual-pruning node with 995 blocks
stop_node(self.nodes[3],3)
stop_node(self.nodes[4],4)
self.stop_node(3)
self.stop_node(4)

print("Check that we haven't started pruning yet because we're below PruneAfterHeight")
self.test_height_min()
Expand Down

0 comments on commit fab035f

Please sign in to comment.