Skip to content

Commit a7ea2f8

Browse files
committed
Merge #9638: qa: Actually test assertions in pruning.py
fab035f qa: Actually test assertions in pruning.py (MarcoFalke)
2 parents d9e4d1d + fab035f commit a7ea2f8

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

qa/rpc-tests/pruning.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def create_chain_with_staleblocks(self):
103103
# Disconnect node 0 so it can mine a longer reorg chain without knowing about node 1's soon-to-be-stale chain
104104
# Node 2 stays connected, so it hears about the stale blocks and then reorg's when node0 reconnects
105105
# Stopping node 0 also clears its mempool, so it doesn't have node1's transactions to accidentally mine
106-
stop_node(self.nodes[0],0)
106+
self.stop_node(0)
107107
self.nodes[0]=start_node(0, self.options.tmpdir, ["-debug","-maxreceivebuffer=20000","-blockmaxsize=999000", "-checkblocks=5"], timewait=900)
108108
# Mine 24 blocks in node 1
109109
for i in range(24):
@@ -128,7 +128,7 @@ def reorg_test(self):
128128
# This will cause Node 2 to do a reorg requiring 288 blocks of undo data to the reorg_test chain
129129
# Reboot node 1 to clear its mempool (hopefully make the invalidate faster)
130130
# Lower the block max size so we don't keep mining all our big mempool transactions (from disconnected blocks)
131-
stop_node(self.nodes[1],1)
131+
self.stop_node(1)
132132
self.nodes[1]=start_node(1, self.options.tmpdir, ["-debug","-maxreceivebuffer=20000","-blockmaxsize=5000", "-checkblocks=5", "-disablesafemode"], timewait=900)
133133

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

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

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

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

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

270-
# negative and zero inputs should raise an exception
271-
try:
272-
node.pruneblockchain(-10)
273-
raise AssertionError("pruneblockchain(-10) should have failed.")
274-
except:
275-
pass
276-
277-
try:
278-
node.pruneblockchain(0)
279-
raise AssertionError("pruneblockchain(0) should have failed.")
280-
except:
281-
pass
271+
# negative heights should raise an exception
272+
assert_raises_message(JSONRPCException, "Negative", node.pruneblockchain, -10)
282273

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

279+
# Does nothing
280+
node.pruneblockchain(height(0))
281+
if not has_block(0):
282+
raise AssertionError("blk00000.dat is missing when should still be there")
283+
288284
# height=500 should prune first file
289285
prune(500)
290286
if has_block(0):
@@ -311,7 +307,7 @@ def has_block(index):
311307
raise AssertionError("blk00003.dat is still there, should be pruned by now")
312308

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

317313
print("Success")
@@ -320,7 +316,7 @@ def wallet_test(self):
320316
# check that the pruning node's wallet is still in good shape
321317
print("Stop and start pruning node to trigger wallet rescan")
322318
try:
323-
stop_node(self.nodes[2], 2)
319+
self.stop_node(2)
324320
start_node(2, self.options.tmpdir, ["-debug=1","-prune=550"])
325321
print("Success")
326322
except Exception as detail:
@@ -333,7 +329,7 @@ def wallet_test(self):
333329
nds = [self.nodes[0], self.nodes[5]]
334330
sync_blocks(nds, wait=5, timeout=300)
335331
try:
336-
stop_node(self.nodes[5],5) #stop and start to trigger rescan
332+
self.stop_node(5) #stop and start to trigger rescan
337333
start_node(5, self.options.tmpdir, ["-debug=1","-prune=550"])
338334
print ("Success")
339335
except Exception as detail:
@@ -353,8 +349,8 @@ def run_test(self):
353349
# N0=N1=N2 **...*(995)
354350

355351
# stop manual-pruning node with 995 blocks
356-
stop_node(self.nodes[3],3)
357-
stop_node(self.nodes[4],4)
352+
self.stop_node(3)
353+
self.stop_node(4)
358354

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

0 commit comments

Comments
 (0)