Merge #11877: Improve createrawtransaction functional tests
88af502
test: Add createrawtransaction functional tests (João Barbosa)27c6199
test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa)320669a
rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
This commit is contained in:
commit
d4991c0cbb
2 changed files with 55 additions and 1 deletions
|
@ -349,7 +349,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
|
||||||
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"}\"")
|
+ HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"}\"")
|
||||||
);
|
);
|
||||||
|
|
||||||
RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VOBJ, UniValue::VNUM}, true);
|
RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VOBJ, UniValue::VNUM, UniValue::VBOOL}, true);
|
||||||
if (request.params[0].isNull() || request.params[1].isNull())
|
if (request.params[0].isNull() || request.params[1].isNull())
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,25 @@ Test the following RPCs:
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import *
|
from test_framework.util import *
|
||||||
|
|
||||||
|
|
||||||
|
class multidict(dict):
|
||||||
|
"""Dictionary that allows duplicate keys.
|
||||||
|
|
||||||
|
Constructed with a list of (key, value) tuples. When dumped by the json module,
|
||||||
|
will output invalid json with repeated keys, eg:
|
||||||
|
>>> json.dumps(multidict([(1,2),(1,2)])
|
||||||
|
'{"1": 2, "1": 2}'
|
||||||
|
|
||||||
|
Used to test calls to rpc methods with repeated keys in the json object."""
|
||||||
|
|
||||||
|
def __init__(self, x):
|
||||||
|
dict.__init__(self, x)
|
||||||
|
self.x = x
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return self.x
|
||||||
|
|
||||||
|
|
||||||
# Create one-input, one-output, no-fee transaction:
|
# Create one-input, one-output, no-fee transaction:
|
||||||
class RawTransactionsTest(BitcoinTestFramework):
|
class RawTransactionsTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -39,6 +58,41 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
self.nodes[0].generate(5)
|
self.nodes[0].generate(5)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
|
# Test `createrawtransaction` required parameters
|
||||||
|
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction)
|
||||||
|
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, [])
|
||||||
|
|
||||||
|
# Test `createrawtransaction` invalid extra parameters
|
||||||
|
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, [], {}, 0, False, 'foo')
|
||||||
|
|
||||||
|
# Test `createrawtransaction` invalid `inputs`
|
||||||
|
txid = '1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000'
|
||||||
|
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(-8, "txid must be hexadecimal string", self.nodes[0].createrawtransaction, [{}], {})
|
||||||
|
assert_raises_rpc_error(-8, "txid must be hexadecimal string", self.nodes[0].createrawtransaction, [{'txid': 'foo'}], {})
|
||||||
|
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid}], {})
|
||||||
|
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 'foo'}], {})
|
||||||
|
assert_raises_rpc_error(-8, "Invalid parameter, vout must be positive", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': -1}], {})
|
||||||
|
assert_raises_rpc_error(-8, "Invalid parameter, sequence number is out of range", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 0, 'sequence': -1}], {})
|
||||||
|
|
||||||
|
# Test `createrawtransaction` invalid `outputs`
|
||||||
|
address = self.nodes[0].getnewaddress()
|
||||||
|
assert_raises_rpc_error(-3, "Expected type object", self.nodes[0].createrawtransaction, [], 'foo')
|
||||||
|
assert_raises_rpc_error(-8, "Data must be hexadecimal string", self.nodes[0].createrawtransaction, [], {'data': 'foo'})
|
||||||
|
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})
|
||||||
|
assert_raises_rpc_error(-8, "Invalid parameter, duplicated address: %s" % address, self.nodes[0].createrawtransaction, [], multidict([(address, 1), (address, 1)]))
|
||||||
|
|
||||||
|
# Test `createrawtransaction` invalid `locktime`
|
||||||
|
assert_raises_rpc_error(-3, "Expected type number", self.nodes[0].createrawtransaction, [], {}, 'foo')
|
||||||
|
assert_raises_rpc_error(-8, "Invalid parameter, locktime out of range", self.nodes[0].createrawtransaction, [], {}, -1)
|
||||||
|
assert_raises_rpc_error(-8, "Invalid parameter, locktime out of range", self.nodes[0].createrawtransaction, [], {}, 4294967296)
|
||||||
|
|
||||||
|
# Test `createrawtransaction` invalid `replaceable`
|
||||||
|
assert_raises_rpc_error(-3, "Expected type bool", self.nodes[0].createrawtransaction, [], {}, 0, 'foo')
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
# sendrawtransaction with missing input #
|
# sendrawtransaction with missing input #
|
||||||
#########################################
|
#########################################
|
||||||
|
|
Loading…
Reference in a new issue