Skip to content

Commit

Permalink
rpc: Improve getblock error message for invalid data type.
Browse files Browse the repository at this point in the history
  • Loading branch information
klementtan committed Apr 18, 2021
1 parent f5e8bcf commit a411494
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,11 @@ static RPCHelpMan getblock()

int verbosity = 1;
if (!request.params[1].isNull()) {
if(request.params[1].isNum())
verbosity = request.params[1].get_int();
else
if (request.params[1].isBool()) {
verbosity = request.params[1].get_bool() ? 1 : 0;
} else {
verbosity = request.params[1].get_int();
}
}

CBlock block;
Expand Down
3 changes: 3 additions & 0 deletions test/functional/rpc_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ def _test_getblock(self):
self.log.info("Test that getblock with verbosity 2 still works with pruned Undo data")
datadir = get_datadir_path(self.options.tmpdir, 0)

self.log.info("Test that getblock with invalid verbosity type returns proper error message")
assert_raises_rpc_error(-1, "JSON value is not an integer as expected", node.getblock, blockhash, "2")

def move_block_file(old, new):
old_path = os.path.join(datadir, self.chain, 'blocks', old)
new_path = os.path.join(datadir, self.chain, 'blocks', new)
Expand Down

0 comments on commit a411494

Please sign in to comment.