mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-03 01:09:14 +01:00
rpc: treat univalue type check error as RPC_TYPE_ERROR, not RPC_MISC_ERROR
By throwing a custom exception from `Univalue::checkType` (instead of a plain std::runtime_error) and catching it on the RPC server request handler. So we properly return RPC_TYPE_ERROR (-3) on arg type errors and not the general RPC_MISC_ERROR (-1).
This commit is contained in:
@@ -124,13 +124,13 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
|
||||
# 6. invalid parameters - supply txid and invalid boolean values (strings) for verbose
|
||||
for value in ["True", "False"]:
|
||||
assert_raises_rpc_error(-1, "not of expected type bool", self.nodes[n].getrawtransaction, txid=txId, verbose=value)
|
||||
assert_raises_rpc_error(-3, "not of expected type bool", self.nodes[n].getrawtransaction, txid=txId, verbose=value)
|
||||
|
||||
# 7. invalid parameters - supply txid and empty array
|
||||
assert_raises_rpc_error(-1, "not of expected type bool", self.nodes[n].getrawtransaction, txId, [])
|
||||
assert_raises_rpc_error(-3, "not of expected type bool", self.nodes[n].getrawtransaction, txId, [])
|
||||
|
||||
# 8. invalid parameters - supply txid and empty dict
|
||||
assert_raises_rpc_error(-1, "not of expected type bool", self.nodes[n].getrawtransaction, txId, {})
|
||||
assert_raises_rpc_error(-3, "not of expected type bool", self.nodes[n].getrawtransaction, txId, {})
|
||||
|
||||
# Make a tx by sending, then generate 2 blocks; block1 has the tx in it
|
||||
tx = self.wallet.send_self_transfer(from_node=self.nodes[2])['txid']
|
||||
@@ -152,7 +152,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
# We should not get the tx if we provide an unrelated block
|
||||
assert_raises_rpc_error(-5, "No such transaction found", self.nodes[n].getrawtransaction, txid=tx, blockhash=block2)
|
||||
# An invalid block hash should raise the correct errors
|
||||
assert_raises_rpc_error(-1, "JSON value of type bool is not of expected type string", self.nodes[n].getrawtransaction, txid=tx, blockhash=True)
|
||||
assert_raises_rpc_error(-3, "JSON value of type bool is not of expected type string", self.nodes[n].getrawtransaction, txid=tx, blockhash=True)
|
||||
assert_raises_rpc_error(-8, "parameter 3 must be of length 64 (not 6, for 'foobar')", self.nodes[n].getrawtransaction, txid=tx, blockhash="foobar")
|
||||
assert_raises_rpc_error(-8, "parameter 3 must be of length 64 (not 8, for 'abcd1234')", self.nodes[n].getrawtransaction, txid=tx, blockhash="abcd1234")
|
||||
foo = "ZZZ0000000000000000000000000000000000000000000000000000000000000"
|
||||
@@ -181,8 +181,8 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
|
||||
# Test `createrawtransaction` invalid `inputs`
|
||||
assert_raises_rpc_error(-3, "JSON value of type string is not of expected type array", self.nodes[0].createrawtransaction, 'foo', {})
|
||||
assert_raises_rpc_error(-1, "JSON value of type string is not of expected type object", self.nodes[0].createrawtransaction, ['foo'], {})
|
||||
assert_raises_rpc_error(-1, "JSON value of type null is not of expected type string", self.nodes[0].createrawtransaction, [{}], {})
|
||||
assert_raises_rpc_error(-3, "JSON value of type string is not of expected type object", self.nodes[0].createrawtransaction, ['foo'], {})
|
||||
assert_raises_rpc_error(-3, "JSON value of type null is not of expected type string", self.nodes[0].createrawtransaction, [{}], {})
|
||||
assert_raises_rpc_error(-8, "txid must be of length 64 (not 3, for 'foo')", self.nodes[0].createrawtransaction, [{'txid': 'foo'}], {})
|
||||
txid = "ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844"
|
||||
assert_raises_rpc_error(-8, f"txid must be hexadecimal string (not '{txid}')", self.nodes[0].createrawtransaction, [{'txid': txid}], {})
|
||||
@@ -207,7 +207,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
|
||||
# Test `createrawtransaction` invalid `outputs`
|
||||
address = getnewdestination()[2]
|
||||
assert_raises_rpc_error(-1, "JSON value of type string is not of expected type array", self.nodes[0].createrawtransaction, [], 'foo')
|
||||
assert_raises_rpc_error(-3, "JSON value of type string is not of expected type array", self.nodes[0].createrawtransaction, [], 'foo')
|
||||
self.nodes[0].createrawtransaction(inputs=[], outputs={}) # Should not throw for backwards compatibility
|
||||
self.nodes[0].createrawtransaction(inputs=[], outputs=[])
|
||||
assert_raises_rpc_error(-8, "Data must be hexadecimal string", self.nodes[0].createrawtransaction, [], {'data': 'foo'})
|
||||
|
||||
Reference in New Issue
Block a user