mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 02:11:24 +02:00
univalue: Return more detailed type check error messages
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 a boolean", self.nodes[n].getrawtransaction, txid=txId, verbose=value)
|
||||
assert_raises_rpc_error(-1, "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 a boolean", self.nodes[n].getrawtransaction, txId, [])
|
||||
assert_raises_rpc_error(-1, "not of expected type bool", self.nodes[n].getrawtransaction, txId, [])
|
||||
|
||||
# 8. invalid parameters - supply txid and empty dict
|
||||
assert_raises_rpc_error(-1, "not a boolean", self.nodes[n].getrawtransaction, txId, {})
|
||||
assert_raises_rpc_error(-1, "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 is not a string as expected", self.nodes[n].getrawtransaction, txid=tx, blockhash=True)
|
||||
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(-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, "Expected type array", self.nodes[0].createrawtransaction, 'foo', {})
|
||||
assert_raises_rpc_error(-1, "JSON value is not an object as expected", self.nodes[0].createrawtransaction, ['foo'], {})
|
||||
assert_raises_rpc_error(-1, "JSON value is not a string as expected", self.nodes[0].createrawtransaction, [{}], {})
|
||||
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(-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 is not an array as expected", self.nodes[0].createrawtransaction, [], 'foo')
|
||||
assert_raises_rpc_error(-1, "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