Skip to content

Commit 7202ae2

Browse files
committed
Merge #14926: test: consensus: Check that final transactions are valid
aaaa8eb test: consensus: Check that final transactions are valid (MarcoFalke) fae3617 test: Correctly deserialize without witness (MarcoFalke) Pull request description: There is no check that checks that final transactions are valid, i.e. the consensus rules could be changed (accidentally) with none of the tests failing. Tree-SHA512: 48f4c24bfcc525ddbc1bfe8c37131953b464823428c1f7a278ba6d98b98827b6b84a8eb2b33396bfb5b8cc4012b7cc1cd771637f405ea20beddae001c22aa290
2 parents 57c9556 + aaaa8eb commit 7202ae2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

test/functional/mempool_accept.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from io import BytesIO
88
import math
9+
910
from test_framework.test_framework import BitcoinTestFramework
1011
from test_framework.messages import (
1112
BIP125_SEQUENCE_NUMBER,
@@ -71,6 +72,7 @@ def run_test(self):
7172
))['hex']
7273
txid_in_block = node.sendrawtransaction(hexstring=raw_tx_in_block, allowhighfees=True)
7374
node.generate(1)
75+
self.mempool_size = 0
7476
self.check_mempool_result(
7577
result_expected=[{'txid': txid_in_block, 'allowed': False, 'reject-reason': '18: txn-already-known'}],
7678
rawtxs=[raw_tx_in_block],
@@ -90,9 +92,25 @@ def run_test(self):
9092
rawtxs=[raw_tx_0],
9193
)
9294

95+
self.log.info('A final transaction not in the mempool')
96+
coin = node.listunspent()[0] # Pick a random coin(base) to spend
97+
raw_tx_final = node.signrawtransactionwithwallet(node.createrawtransaction(
98+
inputs=[{'txid': coin['txid'], 'vout': coin['vout'], "sequence": 0xffffffff}], # SEQUENCE_FINAL
99+
outputs=[{node.getnewaddress(): 0.025}],
100+
locktime=node.getblockcount() + 2000, # Can be anything
101+
))['hex']
102+
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_final)))
103+
self.check_mempool_result(
104+
result_expected=[{'txid': tx.rehash(), 'allowed': True}],
105+
rawtxs=[bytes_to_hex_str(tx.serialize())],
106+
allowhighfees=True,
107+
)
108+
node.sendrawtransaction(hexstring=raw_tx_final, allowhighfees=True)
109+
self.mempool_size += 1
110+
93111
self.log.info('A transaction in the mempool')
94112
node.sendrawtransaction(hexstring=raw_tx_0)
95-
self.mempool_size = 1
113+
self.mempool_size += 1
96114
self.check_mempool_result(
97115
result_expected=[{'txid': txid_0, 'allowed': False, 'reject-reason': '18: txn-already-in-mempool'}],
98116
rawtxs=[raw_tx_0],

test/functional/test_framework/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ def deserialize(self, f):
450450
if flags != 0:
451451
self.wit.vtxinwit = [CTxInWitness() for i in range(len(self.vin))]
452452
self.wit.deserialize(f)
453+
else:
454+
self.wit = CTxWitness()
453455
self.nLockTime = struct.unpack("<I", f.read(4))[0]
454456
self.sha256 = None
455457
self.hash = None

0 commit comments

Comments
 (0)