Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_rawtransaction.py
Show All 10 Lines | Test the following RPCs: | ||||
- decoderawtransaction | - decoderawtransaction | ||||
- getrawtransaction | - getrawtransaction | ||||
""" | """ | ||||
from decimal import Decimal | from decimal import Decimal | ||||
from collections import OrderedDict | from collections import OrderedDict | ||||
from io import BytesIO | from io import BytesIO | ||||
from test_framework.messages import CTransaction, ToHex | from test_framework.messages import ( | ||||
COutPoint, | |||||
CTransaction, | |||||
CTxIn, | |||||
CTxOut, | |||||
ToHex, | |||||
) | |||||
from test_framework.script import CScript | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
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, | ||||
hex_str_to_bytes, | hex_str_to_bytes, | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Test the maximum transaction version number that fits in a signed 32-bit integer. | # Test the maximum transaction version number that fits in a signed 32-bit integer. | ||||
tx = CTransaction() | tx = CTransaction() | ||||
tx.nVersion = 0x7fffffff | tx.nVersion = 0x7fffffff | ||||
rawtx = ToHex(tx) | rawtx = ToHex(tx) | ||||
decrawtx = self.nodes[0].decoderawtransaction(rawtx) | decrawtx = self.nodes[0].decoderawtransaction(rawtx) | ||||
assert_equal(decrawtx['version'], 0x7fffffff) | assert_equal(decrawtx['version'], 0x7fffffff) | ||||
########################################## | |||||
# Decoding weird scripts in transactions # | |||||
########################################## | |||||
self.log.info('Decode correctly-formatted but weird transactions') | |||||
tx = CTransaction() | |||||
# empty | |||||
self.nodes[0].decoderawtransaction(ToHex(tx)) | |||||
# truncated push | |||||
tx.vin.append(CTxIn(COutPoint(42, 0), b'\x4e\x00\x00')) | |||||
tx.vin.append(CTxIn(COutPoint(42, 0), b'\x4c\x10TRUNC')) | |||||
tx.vout.append(CTxOut(0, b'\x4e\x00\x00')) | |||||
tx.vout.append(CTxOut(0, b'\x4c\x10TRUNC')) | |||||
self.nodes[0].decoderawtransaction(ToHex(tx)) | |||||
# giant pushes and long scripts | |||||
tx.vin.append(CTxIn(COutPoint(42, 0), CScript([b'giant push'*10000]))) | |||||
tx.vout.append(CTxOut(0, CScript([b'giant push'*10000]))) | |||||
self.nodes[0].decoderawtransaction(ToHex(tx)) | |||||
self.log.info('Refuse garbage after transaction') | |||||
assert_raises_rpc_error(-22, 'TX decode failed', | |||||
self.nodes[0].decoderawtransaction, ToHex(tx) + '00') | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
RawTransactionsTest().main() | RawTransactionsTest().main() |