MCPcopy Create free account
hub / github.com/ElementsProject/elements / manual_test

Method manual_test

test/functional/feature_pruning.py:273–352  ·  view source on GitHub ↗
(self, node_number, use_timestamp)

Source from the content-addressed store, hash-verified

271 assert_equal(self.nodes[2].getblock(self.forkhash)["height"], self.forkheight)
272
273 def manual_test(self, node_number, use_timestamp):
274 # at this point, node has 995 blocks and has not yet run in prune mode
275 self.start_node(node_number)
276 node = self.nodes[node_number]
277 assert_equal(node.getblockcount(), 995)
278 assert_raises_rpc_error(-1, "Cannot prune blocks because node is not in prune mode", node.pruneblockchain, 500)
279
280 # now re-start in manual pruning mode
281 self.restart_node(node_number, extra_args=["-prune=1"])
282 node = self.nodes[node_number]
283 assert_equal(node.getblockcount(), 995)
284
285 def height(index):
286 if use_timestamp:
287 return node.getblockheader(node.getblockhash(index))["time"] + TIMESTAMP_WINDOW
288 else:
289 return index
290
291 def prune(index):
292 ret = node.pruneblockchain(height=height(index))
293 assert_equal(ret, node.getblockchaininfo()['pruneheight'])
294
295 def has_block(index):
296 return os.path.isfile(os.path.join(self.nodes[node_number].datadir, self.chain, "blocks", f"blk{index:05}.dat"))
297
298 # should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000)
299 assert_raises_rpc_error(-1, "Blockchain is too short for pruning", node.pruneblockchain, height(500))
300
301 # Save block transaction count before pruning, assert value
302 block1_details = node.getblock(node.getblockhash(1))
303 assert_equal(block1_details["nTx"], len(block1_details["tx"]))
304
305 # mine 6 blocks so we are at height 1001 (i.e., above PruneAfterHeight)
306 self.generate(node, 6, sync_fun=self.no_op)
307 assert_equal(node.getblockchaininfo()["blocks"], 1001)
308
309 # prune parameter in the future (block or timestamp) should raise an exception
310 future_parameter = height(1001) + 5
311 if use_timestamp:
312 assert_raises_rpc_error(-8, "Could not find block with at least the specified timestamp", node.pruneblockchain, future_parameter)
313 else:
314 assert_raises_rpc_error(-8, "Blockchain is shorter than the attempted prune height", node.pruneblockchain, future_parameter)
315
316 # Pruned block should still know the number of transactions
317 assert_equal(node.getblockheader(node.getblockhash(1))["nTx"], block1_details["nTx"])
318
319 # negative heights should raise an exception
320 assert_raises_rpc_error(-8, "Negative block height", node.pruneblockchain, -10)
321
322 # height=100 too low to prune first block file so this is a no-op
323 prune(100)
324 assert has_block(0), "blk00000.dat is missing when should still be there"
325
326 # Does nothing
327 node.pruneblockchain(height(0))
328 assert has_block(0), "blk00000.dat is missing when should still be there"
329
330 # height=500 should prune first file

Callers 1

run_testMethod · 0.95

Calls 6

assert_equalFunction · 0.90
assert_raises_rpc_errorFunction · 0.90
infoMethod · 0.80
start_nodeMethod · 0.45
restart_nodeMethod · 0.45
generateMethod · 0.45

Tested by

no test coverage detected