mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Adjust RPCTypeCheckObj error string
This commit is contained in:
parent
9ca39d69df
commit
2dede9f675
6 changed files with 9 additions and 12 deletions
|
@ -65,11 +65,8 @@ void RPCTypeCheckObj(const UniValue& o,
|
||||||
if (!fAllowNull && v.isNull())
|
if (!fAllowNull && v.isNull())
|
||||||
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
|
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
|
||||||
|
|
||||||
if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) {
|
if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull())))
|
||||||
std::string err = strprintf("Expected type %s for %s, got %s",
|
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("JSON value of type %s for field %s is not of expected type %s", uvTypeName(v.type()), t.first, uvTypeName(t.second.type)));
|
||||||
uvTypeName(t.second.type), t.first, uvTypeName(v.type()));
|
|
||||||
throw JSONRPCError(RPC_TYPE_ERROR, err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fStrict)
|
if (fStrict)
|
||||||
|
|
|
@ -793,7 +793,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.log.info("Test fundrawtxn with invalid estimate_mode settings")
|
self.log.info("Test fundrawtxn with invalid estimate_mode settings")
|
||||||
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
|
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
|
||||||
assert_raises_rpc_error(-3, "Expected type string for estimate_mode, got {}".format(k),
|
assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string",
|
||||||
node.fundrawtransaction, rawtx, {"estimate_mode": v, "conf_target": 0.1, "add_inputs": True})
|
node.fundrawtransaction, rawtx, {"estimate_mode": v, "conf_target": 0.1, "add_inputs": True})
|
||||||
for mode in ["", "foo", Decimal("3.141592")]:
|
for mode in ["", "foo", Decimal("3.141592")]:
|
||||||
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
|
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
|
||||||
|
@ -803,7 +803,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
for mode in ["unset", "economical", "conservative"]:
|
for mode in ["unset", "economical", "conservative"]:
|
||||||
self.log.debug("{}".format(mode))
|
self.log.debug("{}".format(mode))
|
||||||
for k, v in {"string": "", "object": {"foo": "bar"}}.items():
|
for k, v in {"string": "", "object": {"foo": "bar"}}.items():
|
||||||
assert_raises_rpc_error(-3, "Expected type number for conf_target, got {}".format(k),
|
assert_raises_rpc_error(-3, f"JSON value of type {k} for field conf_target is not of expected type number",
|
||||||
node.fundrawtransaction, rawtx, {"estimate_mode": mode, "conf_target": v, "add_inputs": True})
|
node.fundrawtransaction, rawtx, {"estimate_mode": mode, "conf_target": v, "add_inputs": True})
|
||||||
for n in [-1, 0, 1009]:
|
for n in [-1, 0, 1009]:
|
||||||
assert_raises_rpc_error(-8, "Invalid conf_target, must be between 1 and 1008", # max value of 1008 per src/policy/fees.h
|
assert_raises_rpc_error(-8, "Invalid conf_target, must be between 1 and 1008", # max value of 1008 per src/policy/fees.h
|
||||||
|
|
|
@ -84,7 +84,7 @@ class RPCMempoolInfoTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-8, "Invalid parameter, vout cannot be negative", self.nodes[0].gettxspendingprevout, [{'txid' : txidA, 'vout' : -1}])
|
assert_raises_rpc_error(-8, "Invalid parameter, vout cannot be negative", self.nodes[0].gettxspendingprevout, [{'txid' : txidA, 'vout' : -1}])
|
||||||
|
|
||||||
self.log.info("Invalid txid provided")
|
self.log.info("Invalid txid provided")
|
||||||
assert_raises_rpc_error(-3, "Expected type string for txid, got number", self.nodes[0].gettxspendingprevout, [{'txid' : 42, 'vout' : 0}])
|
assert_raises_rpc_error(-3, "JSON value of type number for field txid is not of expected type string", self.nodes[0].gettxspendingprevout, [{'txid' : 42, 'vout' : 0}])
|
||||||
|
|
||||||
self.log.info("Missing outputs")
|
self.log.info("Missing outputs")
|
||||||
assert_raises_rpc_error(-8, "Invalid parameter, outputs are missing", self.nodes[0].gettxspendingprevout, [])
|
assert_raises_rpc_error(-8, "Invalid parameter, outputs are missing", self.nodes[0].gettxspendingprevout, [])
|
||||||
|
|
|
@ -272,7 +272,7 @@ class PSBTTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.log.info("- raises RPC error with invalid estimate_mode settings")
|
self.log.info("- raises RPC error with invalid estimate_mode settings")
|
||||||
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
|
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
|
||||||
assert_raises_rpc_error(-3, "Expected type string for estimate_mode, got {}".format(k),
|
assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string",
|
||||||
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"estimate_mode": v, "conf_target": 0.1, "add_inputs": True})
|
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"estimate_mode": v, "conf_target": 0.1, "add_inputs": True})
|
||||||
for mode in ["", "foo", Decimal("3.141592")]:
|
for mode in ["", "foo", Decimal("3.141592")]:
|
||||||
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
|
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
|
||||||
|
@ -282,7 +282,7 @@ class PSBTTest(BitcoinTestFramework):
|
||||||
for mode in ["unset", "economical", "conservative"]:
|
for mode in ["unset", "economical", "conservative"]:
|
||||||
self.log.debug("{}".format(mode))
|
self.log.debug("{}".format(mode))
|
||||||
for k, v in {"string": "", "object": {"foo": "bar"}}.items():
|
for k, v in {"string": "", "object": {"foo": "bar"}}.items():
|
||||||
assert_raises_rpc_error(-3, "Expected type number for conf_target, got {}".format(k),
|
assert_raises_rpc_error(-3, f"JSON value of type {k} for field conf_target is not of expected type number",
|
||||||
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"estimate_mode": mode, "conf_target": v, "add_inputs": True})
|
self.nodes[1].walletcreatefundedpsbt, inputs, outputs, 0, {"estimate_mode": mode, "conf_target": v, "add_inputs": True})
|
||||||
for n in [-1, 0, 1009]:
|
for n in [-1, 0, 1009]:
|
||||||
assert_raises_rpc_error(-8, "Invalid conf_target, must be between 1 and 1008", # max value of 1008 per src/policy/fees.h
|
assert_raises_rpc_error(-8, "Invalid conf_target, must be between 1 and 1008", # max value of 1008 per src/policy/fees.h
|
||||||
|
|
|
@ -151,7 +151,7 @@ class BumpFeeTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.log.info("Test invalid estimate_mode settings")
|
self.log.info("Test invalid estimate_mode settings")
|
||||||
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
|
for k, v in {"number": 42, "object": {"foo": "bar"}}.items():
|
||||||
assert_raises_rpc_error(-3, "Expected type string for estimate_mode, got {}".format(k),
|
assert_raises_rpc_error(-3, f"JSON value of type {k} for field estimate_mode is not of expected type string",
|
||||||
rbf_node.bumpfee, rbfid, {"estimate_mode": v})
|
rbf_node.bumpfee, rbfid, {"estimate_mode": v})
|
||||||
for mode in ["foo", Decimal("3.1415"), "sat/B", "BTC/kB"]:
|
for mode in ["foo", Decimal("3.1415"), "sat/B", "BTC/kB"]:
|
||||||
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
|
assert_raises_rpc_error(-8, 'Invalid estimate_mode parameter, must be one of: "unset", "economical", "conservative"',
|
||||||
|
|
|
@ -362,7 +362,7 @@ class WalletSendTest(BitcoinTestFramework):
|
||||||
for mode in ["economical", "conservative"]:
|
for mode in ["economical", "conservative"]:
|
||||||
for k, v in {"string": "true", "bool": True, "object": {"foo": "bar"}}.items():
|
for k, v in {"string": "true", "bool": True, "object": {"foo": "bar"}}.items():
|
||||||
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
|
self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=v, estimate_mode=mode,
|
||||||
expect_error=(-3, f"Expected type number for conf_target, got {k}"))
|
expect_error=(-3, f"JSON value of type {k} for field conf_target is not of expected type number"))
|
||||||
|
|
||||||
# Test setting explicit fee rate just below the minimum of 1 sat/vB.
|
# Test setting explicit fee rate just below the minimum of 1 sat/vB.
|
||||||
self.log.info("Explicit fee rate raises RPC error 'fee rate too low' if fee_rate of 0.99999999 is passed")
|
self.log.info("Explicit fee rate raises RPC error 'fee rate too low' if fee_rate of 0.99999999 is passed")
|
||||||
|
|
Loading…
Add table
Reference in a new issue