Skip to content

Commit 807169e

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24035: test: use MiniWallet for mempool_accept.py
aa8a65e test: use MiniWallet for mempool_accept.py (Sebastian Falbesoner) b24f6c6 test: MiniWallet: support default `from_node` for creating txs (Sebastian Falbesoner) f30041c test: create txs with current `nVersion` (2) by default (Sebastian Falbesoner) 2f79786 test: refactor: add constant for sequence number `SEQUENCE_FINAL` (Sebastian Falbesoner) Pull request description: This PR enables one more of the non-wallet functional tests (mempool_accept.py) to be run even with the Bitcoin Core wallet disabled by using the MiniWallet instead, as proposed in #20078. It also includes some other minor changes that came up while working on the replacement: * [commit 1/4] replace magic number 0xffffffff for a tx's nSequence with a new constant `SEQUENCE_FINAL` * [commit 2/4] create `CTransaction` instances with the current nVersion=2 by default, in order to use BIP68 for tests * [commit 3/4] support default `from_node` parameter for creating txs (this is a stripped down version of PR #24025) ACKs for top commit: MarcoFalke: re-ACK aa8a65e 📊 Tree-SHA512: 34cd085ea4147ad5bd3f3321c84204064ceb95f382664c7fe29062c1bbc79d9d9465c5e46d35e11c416f2f3cd46030c90a09b518c829c73ae40d060be5e4c9cb
2 parents 767ee2e + aa8a65e commit 807169e

16 files changed

+88
-86
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: 5 additions & 4 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])
@@ -114,7 +115,7 @@ def run_test(self):
114115
# create one invalid tx per CLTV failure reason (5 in total) and collect them
115116
invalid_cltv_txs = []
116117
for i in range(5):
117-
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
118+
spendtx = wallet.create_self_transfer()['tx']
118119
cltv_invalidate(spendtx, i)
119120
invalid_cltv_txs.append(spendtx)
120121

@@ -145,7 +146,7 @@ def run_test(self):
145146

146147
# create and test one invalid tx per CLTV failure reason (5 in total)
147148
for i in range(5):
148-
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
149+
spendtx = wallet.create_self_transfer()['tx']
149150
cltv_invalidate(spendtx, i)
150151

151152
expected_cltv_reject_reason = [

test/functional/feature_csv_activation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def set_test_params(self):
104104

105105
def create_self_transfer_from_utxo(self, input_tx):
106106
utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False)
107-
tx = self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo)['tx']
107+
tx = self.miniwallet.create_self_transfer(utxo_to_spend=utxo)['tx']
108108
return tx
109109

110110
def create_bip112special(self, input, txversion):

test/functional/feature_dersig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def set_test_params(self):
5757

5858
def create_tx(self, input_txid):
5959
utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid, mark_as_spent=False)
60-
return self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx']
60+
return self.miniwallet.create_self_transfer(utxo_to_spend=utxo_to_spend)['tx']
6161

6262
def test_dersig_info(self, *, is_active):
6363
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip66'],

test/functional/feature_rbf.py

Lines changed: 7 additions & 8 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
@@ -114,7 +115,7 @@ def test_simple_doublespend(self):
114115
"""Simple doublespend"""
115116
# we use MiniWallet to create a transaction template with inputs correctly set,
116117
# and modify the output (amount, scriptPubKey) according to our needs
117-
tx_template = self.wallet.create_self_transfer(from_node=self.nodes[0])['tx']
118+
tx_template = self.wallet.create_self_transfer()['tx']
118119

119120
tx1a = deepcopy(tx_template)
120121
tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT)]
@@ -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()
@@ -562,7 +563,6 @@ def test_no_inherited_signaling(self):
562563
assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])
563564

564565
replacement_parent_tx = self.wallet.create_self_transfer(
565-
from_node=self.nodes[0],
566566
utxo_to_spend=confirmed_utxo,
567567
sequence=BIP125_SEQUENCE_NUMBER,
568568
fee_rate=Decimal('0.02'),
@@ -579,17 +579,16 @@ def test_no_inherited_signaling(self):
579579
optout_child_tx = self.wallet.send_self_transfer(
580580
from_node=self.nodes[0],
581581
utxo_to_spend=parent_utxo,
582-
sequence=0xffffffff,
582+
sequence=SEQUENCE_FINAL,
583583
fee_rate=Decimal('0.01'),
584584
)
585585

586586
# Reports true due to inheritance
587587
assert_equal(True, self.nodes[0].getmempoolentry(optout_child_tx['txid'])['bip125-replaceable'])
588588

589589
replacement_child_tx = self.wallet.create_self_transfer(
590-
from_node=self.nodes[0],
591590
utxo_to_spend=parent_utxo,
592-
sequence=0xffffffff,
591+
sequence=SEQUENCE_FINAL,
593592
fee_rate=Decimal('0.02'),
594593
mempool_valid=False,
595594
)
@@ -608,7 +607,7 @@ def test_no_inherited_signaling(self):
608607
replacement_parent_tx = self.wallet.send_self_transfer(
609608
from_node=self.nodes[0],
610609
utxo_to_spend=confirmed_utxo,
611-
sequence=0xffffffff,
610+
sequence=SEQUENCE_FINAL,
612611
fee_rate=Decimal('0.03'),
613612
)
614613
# 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/feature_utxo_set_hash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def test_muhash_implementation(self):
6969
assert_equal(finalized[::-1].hex(), node_muhash)
7070

7171
self.log.info("Test deterministic UTXO set hash results")
72-
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "221f245cf4c9010eeb7f5183d342c002ae6c1c27e98aa357dccb788c21d98049")
73-
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "7c0890c68501f7630d36aeb3999dc924e63af084ae1bbfba11dd462144637635")
72+
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "3a570529b4c32e77268de1f81b903c75cc2da53c48df0d125c1e697ba7c8c7b7")
73+
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "a13e0e70eb8acc786549596e3bc154623f1a5a622ba2f70715f6773ec745f435")
7474

7575
def run_test(self):
7676
self.test_muhash_implementation()

0 commit comments

Comments
 (0)