Skip to content

Commit 2f79786

Browse files
committed
test: refactor: add constant for sequence number SEQUENCE_FINAL
1 parent c561f2f commit 2f79786

File tree

8 files changed

+32
-20
lines changed

8 files changed

+32
-20
lines changed

test/functional/data/invalid_txs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
CTxIn,
2929
CTxOut,
3030
MAX_MONEY,
31+
SEQUENCE_FINAL,
3132
)
3233
from test_framework.blocktools import create_tx_with_script, MAX_BLOCK_SIGOPS
3334
from test_framework.script import (
@@ -77,7 +78,7 @@ class BadTxTemplate:
7778
def __init__(self, *, spend_tx=None, spend_block=None):
7879
self.spend_tx = spend_block.vtx[0] if spend_block else spend_tx
7980
self.spend_avail = sum(o.nValue for o in self.spend_tx.vout)
80-
self.valid_txin = CTxIn(COutPoint(self.spend_tx.sha256, 0), b"", 0xffffffff)
81+
self.valid_txin = CTxIn(COutPoint(self.spend_tx.sha256, 0), b"", SEQUENCE_FINAL)
8182

8283
@abc.abstractmethod
8384
def get_tx(self, *args, **kwargs):
@@ -137,7 +138,7 @@ def get_tx(self):
137138
bad_idx = num_indices + 100
138139

139140
tx = CTransaction()
140-
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256, bad_idx), b"", 0xffffffff))
141+
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256, bad_idx), b"", SEQUENCE_FINAL))
141142
tx.vout.append(CTxOut(0, basic_p2sh))
142143
tx.calc_sha256()
143144
return tx
@@ -175,7 +176,7 @@ class NonexistentInput(BadTxTemplate):
175176

176177
def get_tx(self):
177178
tx = CTransaction()
178-
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256 + 1, 0), b"", 0xffffffff))
179+
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256 + 1, 0), b"", SEQUENCE_FINAL))
179180
tx.vin.append(self.valid_txin)
180181
tx.vout.append(CTxOut(1, basic_p2sh))
181182
tx.calc_sha256()

test/functional/feature_block.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
CTxIn,
2424
CTxOut,
2525
MAX_BLOCK_WEIGHT,
26+
SEQUENCE_FINAL,
2627
uint256_from_compact,
2728
uint256_from_str,
2829
)
@@ -50,9 +51,13 @@
5051
script_to_p2sh_script,
5152
)
5253
from test_framework.test_framework import BitcoinTestFramework
53-
from test_framework.util import assert_equal
54+
from test_framework.util import (
55+
assert_equal,
56+
assert_greater_than,
57+
)
5458
from data import invalid_txs
5559

60+
5661
# Use this class for tests that require behavior other than normal p2p behavior.
5762
# For now, it is used to serialize a bloated varint (b64).
5863
class CBrokenBlock(CBlock):
@@ -801,7 +806,7 @@ def run_test(self):
801806
b58 = self.next_block(58, spend=out[17])
802807
tx = CTransaction()
803808
assert len(out[17].vout) < 42
804-
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), 0xffffffff))
809+
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
805810
tx.vout.append(CTxOut(0, b""))
806811
tx.calc_sha256()
807812
b58 = self.update_block(58, [tx])
@@ -876,7 +881,7 @@ def run_test(self):
876881
tx.nLockTime = 0xffffffff # this locktime is non-final
877882
tx.vin.append(CTxIn(COutPoint(out[18].sha256, 0))) # don't set nSequence
878883
tx.vout.append(CTxOut(0, CScript([OP_TRUE])))
879-
assert tx.vin[0].nSequence < 0xffffffff
884+
assert_greater_than(SEQUENCE_FINAL, tx.vin[0].nSequence)
880885
tx.calc_sha256()
881886
b62 = self.update_block(62, [tx])
882887
self.send_blocks([b62], success=False, reject_reason='bad-txns-nonfinal', reconnect=True)
@@ -1024,7 +1029,7 @@ def run_test(self):
10241029
bogus_tx = CTransaction()
10251030
bogus_tx.sha256 = uint256_from_str(b"23c70ed7c0506e9178fc1a987f40a33946d4ad4c962b5ae3a52546da53af0c5c")
10261031
tx = CTransaction()
1027-
tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", 0xffffffff))
1032+
tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", SEQUENCE_FINAL))
10281033
tx.vout.append(CTxOut(1, b""))
10291034
b70 = self.update_block(70, [tx])
10301035
self.send_blocks([b70], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)

test/functional/feature_cltv.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from test_framework.messages import (
1515
CTransaction,
16+
SEQUENCE_FINAL,
1617
msg_block,
1718
)
1819
from test_framework.p2p import P2PInterface
@@ -53,7 +54,7 @@ def cltv_invalidate(tx, failure_reason):
5354
# 3) the lock-time type (height vs. timestamp) of the top stack item and the
5455
# nLockTime field are not the same
5556
# 4) the top stack item is greater than the transaction's nLockTime field
56-
# 5) the nSequence field of the txin is 0xffffffff
57+
# 5) the nSequence field of the txin is 0xffffffff (SEQUENCE_FINAL)
5758
assert failure_reason in range(5)
5859
scheme = [
5960
# | Script to prepend to scriptSig | nSequence | nLockTime |
@@ -62,7 +63,7 @@ def cltv_invalidate(tx, failure_reason):
6263
[[OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP], None, None],
6364
[[CScriptNum(100), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0, 1296688602], # timestamp of genesis block
6465
[[CScriptNum(100), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0, 50],
65-
[[CScriptNum(50), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0xffffffff, 50],
66+
[[CScriptNum(50), OP_CHECKLOCKTIMEVERIFY, OP_DROP], SEQUENCE_FINAL, 50],
6667
][failure_reason]
6768

6869
cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])

test/functional/feature_rbf.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
CTransaction,
1515
CTxIn,
1616
CTxOut,
17+
SEQUENCE_FINAL,
1718
)
1819
from test_framework.script import CScript, OP_DROP
1920
from test_framework.test_framework import BitcoinTestFramework
@@ -402,7 +403,7 @@ def test_opt_in(self):
402403

403404
# Create a non-opting in transaction
404405
tx1a = CTransaction()
405-
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0xffffffff)]
406+
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=SEQUENCE_FINAL)]
406407
tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT)]
407408
tx1a_hex = tx1a.serialize().hex()
408409
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, 0)
@@ -445,7 +446,7 @@ def test_opt_in(self):
445446
tx2a_txid = int(tx2a_txid, 16)
446447

447448
tx3a = CTransaction()
448-
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0xffffffff),
449+
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=SEQUENCE_FINAL),
449450
CTxIn(COutPoint(tx2a_txid, 0), nSequence=0xfffffffd)]
450451
tx3a.vout = [CTxOut(int(0.9 * COIN), CScript([b'c'])), CTxOut(int(0.9 * COIN), CScript([b'd']))]
451452
tx3a_hex = tx3a.serialize().hex()
@@ -579,7 +580,7 @@ def test_no_inherited_signaling(self):
579580
optout_child_tx = self.wallet.send_self_transfer(
580581
from_node=self.nodes[0],
581582
utxo_to_spend=parent_utxo,
582-
sequence=0xffffffff,
583+
sequence=SEQUENCE_FINAL,
583584
fee_rate=Decimal('0.01'),
584585
)
585586

@@ -589,7 +590,7 @@ def test_no_inherited_signaling(self):
589590
replacement_child_tx = self.wallet.create_self_transfer(
590591
from_node=self.nodes[0],
591592
utxo_to_spend=parent_utxo,
592-
sequence=0xffffffff,
593+
sequence=SEQUENCE_FINAL,
593594
fee_rate=Decimal('0.02'),
594595
mempool_valid=False,
595596
)
@@ -608,7 +609,7 @@ def test_no_inherited_signaling(self):
608609
replacement_parent_tx = self.wallet.send_self_transfer(
609610
from_node=self.nodes[0],
610611
utxo_to_spend=confirmed_utxo,
611-
sequence=0xffffffff,
612+
sequence=SEQUENCE_FINAL,
612613
fee_rate=Decimal('0.03'),
613614
)
614615
# Check that child is removed and update wallet utxo state

test/functional/feature_taproot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
CTxIn,
2020
CTxInWitness,
2121
CTxOut,
22+
SEQUENCE_FINAL,
2223
)
2324
from test_framework.script import (
2425
ANNEX_TAG,
@@ -1516,7 +1517,7 @@ def gen_test_vectors(self):
15161517
assert self.nodes[1].getblockcount() == 0
15171518
coinbase = CTransaction()
15181519
coinbase.nVersion = 1
1519-
coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), 0xffffffff)]
1520+
coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), SEQUENCE_FINAL)]
15201521
coinbase.vout = [CTxOut(5000000000, CScript([OP_1]))]
15211522
coinbase.nLockTime = 0
15221523
coinbase.rehash()
@@ -1604,7 +1605,7 @@ def gen_test_vectors(self):
16041605
val = 42000000 * (i + 7)
16051606
tx = CTransaction()
16061607
tx.nVersion = 1
1607-
tx.vin = [CTxIn(COutPoint(lasttxid, i & 1), CScript([]), 0xffffffff)]
1608+
tx.vin = [CTxIn(COutPoint(lasttxid, i & 1), CScript([]), SEQUENCE_FINAL)]
16081609
tx.vout = [CTxOut(val, spk), CTxOut(amount - val, CScript([OP_1]))]
16091610
if i & 1:
16101611
tx.vout = list(reversed(tx.vout))
@@ -1664,7 +1665,7 @@ def pr(node):
16641665
tx.vin = []
16651666
inputs = []
16661667
input_spks = [tap_spks[0], tap_spks[1], old_spks[0], tap_spks[2], tap_spks[5], old_spks[2], tap_spks[6], tap_spks[3], tap_spks[4]]
1667-
sequences = [0, 0xffffffff, 0xffffffff, 0xfffffffe, 0xfffffffe, 0, 0, 0xffffffff, 0xffffffff]
1668+
sequences = [0, SEQUENCE_FINAL, SEQUENCE_FINAL, 0xfffffffe, 0xfffffffe, 0, 0, SEQUENCE_FINAL, SEQUENCE_FINAL]
16681669
hashtypes = [SIGHASH_SINGLE, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, SIGHASH_ALL, SIGHASH_ALL, SIGHASH_DEFAULT, SIGHASH_ALL, SIGHASH_NONE, SIGHASH_NONE|SIGHASH_ANYONECANPAY, SIGHASH_ALL|SIGHASH_ANYONECANPAY]
16691670
for i, spk in enumerate(input_spks):
16701671
tx.vin.append(CTxIn(spend_info[spk]['prevout'], CScript(), sequences[i]))

test/functional/mempool_accept.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
CTxOut,
1818
MAX_BLOCK_WEIGHT,
1919
MAX_MONEY,
20+
SEQUENCE_FINAL,
2021
tx_from_hex,
2122
)
2223
from test_framework.script import (
@@ -100,7 +101,7 @@ def run_test(self):
100101
coin = coins.pop() # Pick a random coin(base) to spend
101102
output_amount = Decimal('0.025')
102103
raw_tx_final = node.signrawtransactionwithwallet(node.createrawtransaction(
103-
inputs=[{'txid': coin['txid'], 'vout': coin['vout'], "sequence": 0xffffffff}], # SEQUENCE_FINAL
104+
inputs=[{'txid': coin['txid'], 'vout': coin['vout'], "sequence": SEQUENCE_FINAL}],
104105
outputs=[{node.getnewaddress(): output_amount}],
105106
locktime=node.getblockcount() + 2000, # Can be anything
106107
))['hex']

test/functional/test_framework/blocktools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
CTxIn,
2323
CTxInWitness,
2424
CTxOut,
25+
SEQUENCE_FINAL,
2526
hash256,
2627
ser_uint256,
2728
tx_from_hex,
@@ -128,7 +129,7 @@ def create_coinbase(height, pubkey=None, extra_output_script=None, fees=0, nValu
128129
If extra_output_script is given, make a 0-value output to that
129130
script. This is useful to pad block weight/sigops as needed. """
130131
coinbase = CTransaction()
131-
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff), script_BIP34_coinbase_height(height), 0xffffffff))
132+
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff), script_BIP34_coinbase_height(height), SEQUENCE_FINAL))
132133
coinbaseoutput = CTxOut()
133134
coinbaseoutput.nValue = nValue * COIN
134135
if nValue == 50:
@@ -156,7 +157,7 @@ def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, script_pub_key=C
156157
"""
157158
tx = CTransaction()
158159
assert n < len(prevtx.vout)
159-
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, 0xffffffff))
160+
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, SEQUENCE_FINAL))
160161
tx.vout.append(CTxOut(amount, script_pub_key))
161162
tx.calc_sha256()
162163
return tx

test/functional/test_framework/messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
MAX_MONEY = 21000000 * COIN
4141

4242
BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is rbf-opt-in (BIP 125) and csv-opt-out (BIP 68)
43+
SEQUENCE_FINAL = 0xffffffff # Sequence number that disables nLockTime if set for every input of a tx
4344

4445
MAX_PROTOCOL_MESSAGE_LENGTH = 4000000 # Maximum length of incoming protocol messages
4546
MAX_HEADERS_RESULTS = 2000 # Number of headers sent in one getheaders result

0 commit comments

Comments
 (0)