mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Merge bitcoin/bitcoin#23796: test: check that pruneblockchain RPC fails for future block or timestamp
140a49ce5e547a1b520a7cd063af8308184e7cbf test: check that pruneblockchain RPC fails for future block or timestamp (Sebastian Falbesoner) Pull request description: This PR adds missing test coverage for the `pruneblockchain` RPC for the case that a future block or timestamp is passed:8c0bd871fc/src/rpc/blockchain.cpp (L1101)
8c0bd871fc/src/rpc/blockchain.cpp (L1111)
Note that the test method `manual_test` gets called twice, once each with `use_timestamp` set to True/False, respectively. Depending on that, the helper function `height` either converts the passed block height to the timestamp of that block, or just returns it without modification. The other tests for failures in this RPC are also changed to be more detailled ("Cannot prune blocks because node is not in prune mode", "Negative block height"), as I don't think there is any value in just checking a sub-string. If there is ever an error with the same sub-string is introduced, it's not clear which error is exactly checked with the test, so it makes sense to be as specific as possible. ACKs for top commit: brunoerg: tACK 140a49ce5e547a1b520a7cd063af8308184e7cbf Tree-SHA512: bee3cee9f35c2a63a1839d7ec1f83e354d9d3c0c2ca32d300dca2de8b755d555f769ba2b80ac37d31df6ee7e2b8eaefb8134c4727a7144e47c0f5e34f2cc5822
This commit is contained in:
parent
95204d3fa0
commit
b8ae487139
@ -252,7 +252,7 @@ class PruneTest(BitcoinTestFramework):
|
||||
self.start_node(node_number, extra_args=["-dip3params=2000:2000", "-dip8params=2000", "-disablegovernance", "-txindex=0"])
|
||||
node = self.nodes[node_number]
|
||||
assert_equal(node.getblockcount(), 995)
|
||||
assert_raises_rpc_error(-1, "not in prune mode", node.pruneblockchain, 500)
|
||||
assert_raises_rpc_error(-1, "Cannot prune blocks because node is not in prune mode", node.pruneblockchain, 500)
|
||||
|
||||
# now re-start in manual pruning mode
|
||||
self.stop_node(node_number, expected_stderr='Warning: You are starting with governance validation disabled.')
|
||||
@ -284,11 +284,18 @@ class PruneTest(BitcoinTestFramework):
|
||||
node.generate(6)
|
||||
assert_equal(node.getblockchaininfo()["blocks"], 1001)
|
||||
|
||||
# prune parameter in the future (block or timestamp) should raise an exception
|
||||
future_parameter = height(1001) + 5
|
||||
if use_timestamp:
|
||||
assert_raises_rpc_error(-8, "Could not find block with at least the specified timestamp", node.pruneblockchain, future_parameter)
|
||||
else:
|
||||
assert_raises_rpc_error(-8, "Blockchain is shorter than the attempted prune height", node.pruneblockchain, future_parameter)
|
||||
|
||||
# Pruned block should still know the number of transactions
|
||||
assert_equal(node.getblockheader(node.getblockhash(1))["nTx"], block1_details["nTx"])
|
||||
|
||||
# negative heights should raise an exception
|
||||
assert_raises_rpc_error(-8, "Negative", node.pruneblockchain, -10)
|
||||
assert_raises_rpc_error(-8, "Negative block height", node.pruneblockchain, -10)
|
||||
|
||||
# height=100 too low to prune first block file so this is a no-op
|
||||
prune(100)
|
||||
|
Loading…
Reference in New Issue
Block a user