|
9 | 9 | import math
|
10 | 10 |
|
11 | 11 | from test_framework.test_framework import BitcoinTestFramework
|
| 12 | +from test_framework.blocktools import MAX_STANDARD_TX_WEIGHT |
12 | 13 | from test_framework.messages import (
|
13 | 14 | MAX_BIP125_RBF_SEQUENCE,
|
14 | 15 | COIN,
|
@@ -327,6 +328,54 @@ def run_test(self):
|
327 | 328 | rawtxs=[tx.serialize().hex()],
|
328 | 329 | )
|
329 | 330 |
|
| 331 | + # OP_RETURN followed by non-push |
| 332 | + tx = tx_from_hex(raw_tx_reference) |
| 333 | + tx.vout[0].scriptPubKey = CScript([OP_RETURN, OP_HASH160]) |
| 334 | + self.check_mempool_result( |
| 335 | + result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptpubkey'}], |
| 336 | + rawtxs=[tx.serialize().hex()], |
| 337 | + ) |
| 338 | + |
| 339 | + # Multiple OP_RETURN and more than 83 bytes, even if over MAX_SCRIPT_ELEMENT_SIZE |
| 340 | + # are standard since v30 |
| 341 | + tx = tx_from_hex(raw_tx_reference) |
| 342 | + tx.vout.append(CTxOut(0, CScript([OP_RETURN, b'\xff']))) |
| 343 | + tx.vout.append(CTxOut(0, CScript([OP_RETURN, b'\xff' * 50000]))) |
| 344 | + |
| 345 | + self.check_mempool_result( |
| 346 | + result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal('0.05')}}], |
| 347 | + rawtxs=[tx.serialize().hex()], |
| 348 | + maxfeerate=0 |
| 349 | + ) |
| 350 | + |
| 351 | + self.log.info("A transaction with several OP_RETURN outputs.") |
| 352 | + tx = tx_from_hex(raw_tx_reference) |
| 353 | + op_return_count = 42 |
| 354 | + tx.vout[0].nValue = int(tx.vout[0].nValue / op_return_count) |
| 355 | + tx.vout[0].scriptPubKey = CScript([OP_RETURN, b'\xff']) |
| 356 | + tx.vout = [tx.vout[0]] * op_return_count |
| 357 | + self.check_mempool_result( |
| 358 | + result_expected=[{"txid": tx.rehash(), "allowed": True, "vsize": tx.get_vsize(), "fees": {"base": Decimal("0.05000026")}}], |
| 359 | + rawtxs=[tx.serialize().hex()], |
| 360 | + ) |
| 361 | + |
| 362 | + self.log.info("A transaction with an OP_RETURN output that bumps into the max standardness tx size.") |
| 363 | + tx = tx_from_hex(raw_tx_reference) |
| 364 | + tx.vout[0].scriptPubKey = CScript([OP_RETURN]) |
| 365 | + data_len = int(MAX_STANDARD_TX_WEIGHT / 4) - tx.get_vsize() - 5 - 4 # -5 for PUSHDATA4 and -4 for script size |
| 366 | + tx.vout[0].scriptPubKey = CScript([OP_RETURN, b"\xff" * (data_len)]) |
| 367 | + assert_equal(tx.get_vsize(), int(MAX_STANDARD_TX_WEIGHT / 4)) |
| 368 | + self.check_mempool_result( |
| 369 | + result_expected=[{"txid": tx.rehash(), "allowed": True, "vsize": tx.get_vsize(), "fees": {"base": Decimal("0.1") - Decimal("0.05")}}], |
| 370 | + rawtxs=[tx.serialize().hex()], |
| 371 | + ) |
| 372 | + tx.vout[0].scriptPubKey = CScript([OP_RETURN, b"\xff" * (data_len + 1)]) |
| 373 | + assert_greater_than(tx.get_vsize(), int(MAX_STANDARD_TX_WEIGHT / 4)) |
| 374 | + self.check_mempool_result( |
| 375 | + result_expected=[{"txid": tx.rehash(), "allowed": False, "reject-reason": "tx-size"}], |
| 376 | + rawtxs=[tx.serialize().hex()], |
| 377 | + ) |
| 378 | + |
330 | 379 | self.log.info('A timelocked transaction')
|
331 | 380 | tx = tx_from_hex(raw_tx_reference)
|
332 | 381 | tx.vin[0].nSequence -= 1 # Should be non-max, so locktime is not ignored
|
|
0 commit comments