aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/p2p-acceptblock.py
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2017-02-09 16:39:18 -0500
committerJohn Newbery <john@johnnewbery.com>2017-03-07 16:45:09 -0500
commitc1190963b388590dc0a346bf625c7e84f69cee8d (patch)
treed7e1ebf7427eb93770d37ac516b66cbd65c703f8 /qa/rpc-tests/p2p-acceptblock.py
parent6d07c62322f60eb2702c6654e994fc353bcfcf8c (diff)
downloadbitcoin-c1190963b388590dc0a346bf625c7e84f69cee8d.tar.xz
Return correct error codes in blockchain.cpp.
RPCs in blockchain.cpp were returning misleading or incorrect error codes (for example getblock() returning RPC_INTERNAL_ERROR when the block had been pruned). This commit fixes those error codes: - RPC_INTERNAL_ERROR should not be returned for application-level errors, only for genuine internal errors such as corrupted data. - RPC_METHOD_NOT_FOUND should not be returned in response to a JSON request for an existing method. Those error codes have been replaced with RPC_MISC_ERROR or RPC_INVALID_PARAMETER as appropriate.
Diffstat (limited to 'qa/rpc-tests/p2p-acceptblock.py')
-rwxr-xr-xqa/rpc-tests/p2p-acceptblock.py30
1 files changed, 9 insertions, 21 deletions
diff --git a/qa/rpc-tests/p2p-acceptblock.py b/qa/rpc-tests/p2p-acceptblock.py
index 2f21fa149a..4767dd8fe2 100755
--- a/qa/rpc-tests/p2p-acceptblock.py
+++ b/qa/rpc-tests/p2p-acceptblock.py
@@ -197,11 +197,8 @@ class AcceptBlockTest(BitcoinTestFramework):
assert_equal(x['status'], "headers-only")
# But this block should be accepted by node0 since it has more work.
- try:
- self.nodes[0].getblock(blocks_h3[0].hash)
- print("Unrequested more-work block accepted from non-whitelisted peer")
- except:
- raise AssertionError("Unrequested more work block was not processed")
+ self.nodes[0].getblock(blocks_h3[0].hash)
+ print("Unrequested more-work block accepted from non-whitelisted peer")
# Node1 should have accepted and reorged.
assert_equal(self.nodes[1].getblockcount(), 3)
@@ -225,26 +222,17 @@ class AcceptBlockTest(BitcoinTestFramework):
tips[j] = next_block
time.sleep(2)
- for x in all_blocks:
- try:
- self.nodes[0].getblock(x.hash)
- if x == all_blocks[287]:
- raise AssertionError("Unrequested block too far-ahead should have been ignored")
- except:
- if x == all_blocks[287]:
- print("Unrequested block too far-ahead not processed")
- else:
- raise AssertionError("Unrequested block with more work should have been accepted")
+ # Blocks 1-287 should be accepted, block 288 should be ignored because it's too far ahead
+ for x in all_blocks[:-1]:
+ self.nodes[0].getblock(x.hash)
+ assert_raises_jsonrpc(-1, "Block not found on disk", self.nodes[0].getblock, all_blocks[-1].hash)
headers_message.headers.pop() # Ensure the last block is unrequested
white_node.send_message(headers_message) # Send headers leading to tip
white_node.send_message(msg_block(tips[1])) # Now deliver the tip
- try:
- white_node.sync_with_ping()
- self.nodes[1].getblock(tips[1].hash)
- print("Unrequested block far ahead of tip accepted from whitelisted peer")
- except:
- raise AssertionError("Unrequested block from whitelisted peer not accepted")
+ white_node.sync_with_ping()
+ self.nodes[1].getblock(tips[1].hash)
+ print("Unrequested block far ahead of tip accepted from whitelisted peer")
# 5. Test handling of unrequested block on the node that didn't process
# Should still not be processed (even though it has a child that has more