Skip to content

Commit a141e1b

Browse files
petertoddinstagibbs
authored andcommitted
Add more OP_RETURN mempool acceptance functional tests
Credit: Sjors Provoost and Antoine Poinsot
1 parent 0b4048c commit a141e1b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/functional/mempool_accept.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import math
1010

1111
from test_framework.test_framework import BitcoinTestFramework
12+
from test_framework.blocktools import MAX_STANDARD_TX_WEIGHT
1213
from test_framework.messages import (
1314
MAX_BIP125_RBF_SEQUENCE,
1415
COIN,
@@ -327,6 +328,54 @@ def run_test(self):
327328
rawtxs=[tx.serialize().hex()],
328329
)
329330

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+
330379
self.log.info('A timelocked transaction')
331380
tx = tx_from_hex(raw_tx_reference)
332381
tx.vin[0].nSequence -= 1 # Should be non-max, so locktime is not ignored

0 commit comments

Comments
 (0)