For a non-string type, this now fails with Data must be hexadecimal string (not ''). Seems better to align ParseHexV with ParseHashV and more explicitly fail when an incorrect type is passed?
<details>
<summary>git diff on f0518a30af</summary>
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index e2cf363a97..b4c8da9dd9 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -135,9 +135,7 @@ uint256 ParseHashO(const UniValue& o, std::string_view strKey)
}
std::vector<unsigned char> ParseHexV(const UniValue& v, std::string_view name)
{
- std::string strHex;
- if (v.isStr())
- strHex = v.get_str();
+ const std::string& strHex{v.get_str()};
if (!IsHex(strHex))
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be hexadecimal string (not '%s')", name, strHex));
return ParseHex(strHex);
diff --git a/src/test/fuzz/parse_univalue.cpp b/src/test/fuzz/parse_univalue.cpp
index 1f26f903a8..6f8667dc4e 100644
--- a/src/test/fuzz/parse_univalue.cpp
+++ b/src/test/fuzz/parse_univalue.cpp
@@ -54,10 +54,12 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue)
try {
(void)ParseHexO(univalue, "A");
} catch (const UniValue&) {
+ } catch (const std::runtime_error&) {
}
try {
(void)ParseHexO(univalue, random_string);
} catch (const UniValue&) {
+ } catch (const std::runtime_error&) {
}
try {
(void)ParseHexV(univalue, "A");
diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py
index a6e5a90bd1..d88729c62b 100755
--- a/test/functional/rpc_rawtransaction.py
+++ b/test/functional/rpc_rawtransaction.py
@@ -314,8 +314,8 @@ class RawTransactionsTest(BitcoinTestFramework):
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=[])
- for invalid_data in ('foo', 99):
- assert_raises_rpc_error(-8, "Data must be hexadecimal string", self.nodes[0].createrawtransaction, [], {'data': invalid_data})
+ assert_raises_rpc_error(-8, "Data must be hexadecimal string (not 'foo')", self.nodes[0].createrawtransaction, [], {'data': 'foo'})
+ assert_raises_rpc_error(-3, "JSON value of type number is not of expected type string", self.nodes[0].createrawtransaction, [], {'data': 99})
assert_raises_rpc_error(-5, "Invalid Bitcoin address", self.nodes[0].createrawtransaction, [], {'foo': 0})
assert_raises_rpc_error(-3, "Invalid amount", self.nodes[0].createrawtransaction, [], {address: 'foo'})
assert_raises_rpc_error(-3, "Amount out of range", self.nodes[0].createrawtransaction, [], {address: -1})
</details>