Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_rawtransaction.py
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
rawtx = self.nodes[2].createrawtransaction(inputs, outputs) | rawtx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
rawtx = pad_raw_tx(rawtx) | rawtx = pad_raw_tx(rawtx) | ||||
rawtx = self.nodes[2].signrawtransactionwithwallet(rawtx) | rawtx = self.nodes[2].signrawtransactionwithwallet(rawtx) | ||||
# This will raise an exception since there are missing inputs | # This will raise an exception since there are missing inputs | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-25, "Missing inputs", self.nodes[2].sendrawtransaction, rawtx['hex']) | -25, "Missing inputs", self.nodes[2].sendrawtransaction, rawtx['hex']) | ||||
##################################### | |||||
# getrawtransaction with block hash # | |||||
##################################### | |||||
# make a tx by sending then generate 2 blocks; block1 has the tx in it | |||||
tx = self.nodes[2].sendtoaddress(self.nodes[1].getnewaddress(), 1) | |||||
block1, block2 = self.nodes[2].generate(2) | |||||
self.sync_all() | |||||
# We should be able to get the raw transaction by providing the correct block | |||||
gottx = self.nodes[0].getrawtransaction(tx, True, block1) | |||||
assert_equal(gottx['txid'], tx) | |||||
assert_equal(gottx['in_active_chain'], True) | |||||
# We should not have the 'in_active_chain' flag when we don't provide a block | |||||
gottx = self.nodes[0].getrawtransaction(tx, True) | |||||
assert_equal(gottx['txid'], tx) | |||||
assert 'in_active_chain' not in gottx | |||||
# We should not get the tx if we provide an unrelated block | |||||
assert_raises_rpc_error(-5, "No such transaction found", | |||||
self.nodes[0].getrawtransaction, tx, True, block2) | |||||
# An invalid block hash should raise the correct errors | |||||
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", | |||||
self.nodes[0].getrawtransaction, tx, True, True) | |||||
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", | |||||
self.nodes[0].getrawtransaction, tx, True, "foobar") | |||||
assert_raises_rpc_error(-8, "parameter 3 must be of length 64", | |||||
self.nodes[0].getrawtransaction, tx, True, "abcd1234") | |||||
assert_raises_rpc_error(-5, "Block hash not found", self.nodes[0].getrawtransaction, | |||||
tx, True, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") | |||||
# | # | ||||
# RAW TX MULTISIG TESTS # | # RAW TX MULTISIG TESTS # | ||||
# | # | ||||
# 2of2 test | # 2of2 test | ||||
addr1 = self.nodes[2].getnewaddress() | addr1 = self.nodes[2].getnewaddress() | ||||
addr2 = self.nodes[2].getnewaddress() | addr2 = self.nodes[2].getnewaddress() | ||||
addr1Obj = self.nodes[2].validateaddress(addr1) | addr1Obj = self.nodes[2].validateaddress(addr1) | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
txHash, 1)["hex"], rawTxSigned['hex']) | txHash, 1)["hex"], rawTxSigned['hex']) | ||||
# 5. valid parameters - supply txid and True for non-verbose | # 5. valid parameters - supply txid and True for non-verbose | ||||
assert_equal(self.nodes[0].getrawtransaction( | assert_equal(self.nodes[0].getrawtransaction( | ||||
txHash, True)["hex"], rawTxSigned['hex']) | txHash, True)["hex"], rawTxSigned['hex']) | ||||
# 6. invalid parameters - supply txid and string "Flase" | # 6. invalid parameters - supply txid and string "Flase" | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-3, "Invalid type", self.nodes[0].getrawtransaction, txHash, "False") | -1, "not a boolean", self.nodes[0].getrawtransaction, txHash, "False") | ||||
# 7. invalid parameters - supply txid and empty array | # 7. invalid parameters - supply txid and empty array | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-3, "Invalid type", self.nodes[0].getrawtransaction, txHash, []) | -1, "not a boolean", self.nodes[0].getrawtransaction, txHash, []) | ||||
# 8. invalid parameters - supply txid and empty dict | # 8. invalid parameters - supply txid and empty dict | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-3, "Invalid type", self.nodes[0].getrawtransaction, txHash, {}) | -1, "not a boolean", self.nodes[0].getrawtransaction, txHash, {}) | ||||
# Sanity checks on verbose getrawtransaction output | # Sanity checks on verbose getrawtransaction output | ||||
rawTxOutput = self.nodes[0].getrawtransaction(txHash, True) | rawTxOutput = self.nodes[0].getrawtransaction(txHash, True) | ||||
assert_equal(rawTxOutput["hex"], rawTxSigned["hex"]) | assert_equal(rawTxOutput["hex"], rawTxSigned["hex"]) | ||||
assert_equal(rawTxOutput["txid"], txHash) | assert_equal(rawTxOutput["txid"], txHash) | ||||
assert_equal(rawTxOutput["hash"], txHash) | assert_equal(rawTxOutput["hash"], txHash) | ||||
assert_greater_than(rawTxOutput["size"], 300) | assert_greater_than(rawTxOutput["size"], 300) | ||||
assert_equal(rawTxOutput["version"], 0x02) | assert_equal(rawTxOutput["version"], 0x02) | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |