Skip to content

Commit faae5a9

Browse files
author
MarcoFalke
committed
test: Add bad-txns-*-toolarge test cases to invalid_txs
1 parent ac5c5d0 commit faae5a9

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

test/functional/data/invalid_txs.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
"""
2222
import abc
2323

24-
from test_framework.messages import CTransaction, CTxIn, CTxOut, COutPoint
24+
from test_framework.messages import (
25+
COutPoint,
26+
CTransaction,
27+
CTxIn,
28+
CTxOut,
29+
MAX_MONEY,
30+
)
2531
from test_framework import script as sc
2632
from test_framework.blocktools import create_tx_with_script, MAX_BLOCK_SIGOPS
2733
from test_framework.script import (
@@ -166,14 +172,33 @@ def get_tx(self):
166172
self.spend_tx, 0, script_pub_key=basic_p2sh, amount=(self.spend_avail + 1))
167173

168174

169-
class SpendNegative(BadTxTemplate):
175+
class CreateNegative(BadTxTemplate):
170176
reject_reason = 'bad-txns-vout-negative'
171177
expect_disconnect = True
172178

173179
def get_tx(self):
174180
return create_tx_with_script(self.spend_tx, 0, amount=-1)
175181

176182

183+
class CreateTooLarge(BadTxTemplate):
184+
reject_reason = 'bad-txns-vout-toolarge'
185+
expect_disconnect = True
186+
187+
def get_tx(self):
188+
return create_tx_with_script(self.spend_tx, 0, amount=MAX_MONEY + 1)
189+
190+
191+
class CreateSumTooLarge(BadTxTemplate):
192+
reject_reason = 'bad-txns-txouttotal-toolarge'
193+
expect_disconnect = True
194+
195+
def get_tx(self):
196+
tx = create_tx_with_script(self.spend_tx, 0, amount=MAX_MONEY)
197+
tx.vout = [tx.vout[0]] * 2
198+
tx.calc_sha256()
199+
return tx
200+
201+
177202
class InvalidOPIFConstruction(BadTxTemplate):
178203
reject_reason = "mandatory-script-verify-flag-failed (Invalid OP_IF construction)"
179204
expect_disconnect = True
@@ -237,4 +262,3 @@ def get_tx(self):
237262
def iter_all_templates():
238263
"""Iterate through all bad transaction template types."""
239264
return BadTxTemplate.__subclasses__()
240-

test/functional/mempool_accept.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CTransaction,
1717
CTxOut,
1818
MAX_BLOCK_BASE_SIZE,
19+
MAX_MONEY,
1920
)
2021
from test_framework.script import (
2122
hash160,
@@ -220,7 +221,7 @@ def run_test(self):
220221
# The following two validations prevent overflow of the output amounts (see CVE-2010-5139).
221222
self.log.info('A transaction with too large output value')
222223
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
223-
tx.vout[0].nValue = 21000000 * COIN + 1
224+
tx.vout[0].nValue = MAX_MONEY + 1
224225
self.check_mempool_result(
225226
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}],
226227
rawtxs=[tx.serialize().hex()],
@@ -229,7 +230,7 @@ def run_test(self):
229230
self.log.info('A transaction with too large sum of output values')
230231
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
231232
tx.vout = [tx.vout[0]] * 2
232-
tx.vout[0].nValue = 21000000 * COIN
233+
tx.vout[0].nValue = MAX_MONEY
233234
self.check_mempool_result(
234235
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}],
235236
rawtxs=[tx.serialize().hex()],

test/functional/test_framework/messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
MAX_BLOCK_BASE_SIZE = 1000000
4040

4141
COIN = 100000000 # 1 btc in satoshis
42+
MAX_MONEY = 21000000 * COIN
4243

4344
BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out
4445

0 commit comments

Comments
 (0)