Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_rawtransaction.py
Show All 16 Lines | |||||
from test_framework.txtools import pad_raw_tx | from test_framework.txtools import pad_raw_tx | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_greater_than, | assert_greater_than, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes_bi, | connect_nodes_bi, | ||||
) | ) | ||||
# Create one-input, one-output, no-fee transaction: | |||||
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: | |||||
class RawTransactionsTest(BitcoinTestFramework): | class RawTransactionsTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 3 | self.num_nodes = 3 | ||||
def setup_network(self, split=False): | def setup_network(self, split=False): | ||||
super().setup_network() | super().setup_network() | ||||
connect_nodes_bi(self.nodes[0], self.nodes[2]) | connect_nodes_bi(self.nodes[0], self.nodes[2]) | ||||
Show All 11 Lines | def run_test(self): | ||||
self.nodes[0].generate(5) | self.nodes[0].generate(5) | ||||
self.sync_all() | self.sync_all() | ||||
# Test getrawtransaction on genesis block coinbase returns an error | # Test getrawtransaction on genesis block coinbase returns an error | ||||
block = self.nodes[0].getblock(self.nodes[0].getblockhash(0)) | block = self.nodes[0].getblock(self.nodes[0].getblockhash(0)) | ||||
assert_raises_rpc_error(-5, "The genesis block coinbase is not considered an ordinary transaction", | assert_raises_rpc_error(-5, "The genesis block coinbase is not considered an ordinary transaction", | ||||
self.nodes[0].getrawtransaction, block['merkleroot']) | self.nodes[0].getrawtransaction, block['merkleroot']) | ||||
# 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, '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, vout must be a number", | |||||
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: {}".format( | |||||
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) | |||||
# | # | ||||
# sendrawtransaction with missing input # | # sendrawtransaction with missing input # | ||||
# | # | ||||
inputs = [ | inputs = [ | ||||
{'txid': "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout': 1}] | {'txid': "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout': 1}] | ||||
# won't exists | # won't exists | ||||
outputs = {self.nodes[0].getnewaddress(): 4.998} | outputs = {self.nodes[0].getnewaddress(): 4.998} | ||||
rawtx = self.nodes[2].createrawtransaction(inputs, outputs) | rawtx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines |