Skip to content

Commit da1c0c6

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22330: test: use MiniWallet for simple doublespend sub-test in feature_rbf.py
aa02c64 test: use MiniWallet for simple doublespend test in feature_rbf.py (Sebastian Falbesoner) a3f6397 test: feature_rbf.py: make MiniWallet instance available for all sub-tests (Sebastian Falbesoner) 84c8747 test: remove unneeded initialization code in feature_rbf.py (Sebastian Falbesoner) Pull request description: This PR's goal is to prepare the functional test `feature_rbf.py` for more MiniWallet usage. It first gets rid of unused initialization code (I guess that was needed at times when the nodes were still in IBD at the start of tests?), then makes the MiniWallet instance introduced in #22210 available for all sub-tests, and finally, uses that instance in the first sub-test `test_simple_doublespend`. Note that the same idea of replacing the `make_utxo` calls with MiniWallet can be also applied to other sub-tests too; this just serves as a first proof-of-concept. ACKs for top commit: MarcoFalke: re-ACK aa02c64 🌯 Tree-SHA512: 2902dd15d493d83b0790028c92d14fbd99ca05ace704c7011fb38261ce6517aeb810ef9f360fcb701d95887975b6a2911cfe538858d38fceb2c1c2a40afdbe6b
2 parents 78f040a + aa02c64 commit da1c0c6

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

test/functional/feature_rbf.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the RBF code."""
66

7+
from copy import deepcopy
78
from decimal import Decimal
89

910
from test_framework.blocktools import COINBASE_MATURITY
@@ -84,10 +85,11 @@ def skip_test_if_missing_module(self):
8485
self.skip_if_no_wallet()
8586

8687
def run_test(self):
87-
make_utxo(self.nodes[0], 1 * COIN)
88-
89-
# Ensure nodes are synced
90-
self.sync_all()
88+
self.wallet = MiniWallet(self.nodes[0])
89+
# the pre-mined test framework chain contains coinbase outputs to the
90+
# MiniWallet's default address ADDRESS_BCRT1_P2WSH_OP_TRUE in blocks
91+
# 76-100 (see method BitcoinTestFramework._initialize_chain())
92+
self.wallet.scan_blocks(start=76, num=2)
9193

9294
self.log.info("Running test simple doublespend...")
9395
self.test_simple_doublespend()
@@ -129,34 +131,25 @@ def run_test(self):
129131

130132
def test_simple_doublespend(self):
131133
"""Simple doublespend"""
132-
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
133-
134-
# make_utxo may have generated a bunch of blocks, so we need to sync
135-
# before we can spend the coins generated, or else the resulting
136-
# transactions might not be accepted by our peers.
137-
self.sync_all()
134+
# we use MiniWallet to create a transaction template with inputs correctly set,
135+
# and modify the output (amount, scriptPubKey) according to our needs
136+
tx_template = self.wallet.create_self_transfer(from_node=self.nodes[0])['tx']
138137

139-
tx1a = CTransaction()
140-
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
138+
tx1a = deepcopy(tx_template)
141139
tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT)]
142140
tx1a_hex = tx1a.serialize().hex()
143141
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, 0)
144142

145-
self.sync_all()
146-
147143
# Should fail because we haven't changed the fee
148-
tx1b = CTransaction()
149-
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
144+
tx1b = deepcopy(tx_template)
150145
tx1b.vout = [CTxOut(1 * COIN, DUMMY_2_P2WPKH_SCRIPT)]
151146
tx1b_hex = tx1b.serialize().hex()
152147

153148
# This will raise an exception due to insufficient fee
154149
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
155150

156151
# Extra 0.1 BTC fee
157-
tx1b = CTransaction()
158-
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
159-
tx1b.vout = [CTxOut(int(0.9 * COIN), DUMMY_P2WPKH_SCRIPT)]
152+
tx1b.vout[0].nValue -= int(0.1 * COIN)
160153
tx1b_hex = tx1b.serialize().hex()
161154
# Works when enabled
162155
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, 0)
@@ -574,20 +567,18 @@ def test_rpc(self):
574567
assert_equal(json1["vin"][0]["sequence"], 4294967294)
575568

576569
def test_no_inherited_signaling(self):
577-
wallet = MiniWallet(self.nodes[0])
578-
wallet.scan_blocks(start=76, num=1)
579-
confirmed_utxo = wallet.get_utxo()
570+
confirmed_utxo = self.wallet.get_utxo()
580571

581572
# Create an explicitly opt-in parent transaction
582-
optin_parent_tx = wallet.send_self_transfer(
573+
optin_parent_tx = self.wallet.send_self_transfer(
583574
from_node=self.nodes[0],
584575
utxo_to_spend=confirmed_utxo,
585576
sequence=BIP125_SEQUENCE_NUMBER,
586577
fee_rate=Decimal('0.01'),
587578
)
588579
assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])
589580

590-
replacement_parent_tx = wallet.create_self_transfer(
581+
replacement_parent_tx = self.wallet.create_self_transfer(
591582
from_node=self.nodes[0],
592583
utxo_to_spend=confirmed_utxo,
593584
sequence=BIP125_SEQUENCE_NUMBER,
@@ -601,8 +592,8 @@ def test_no_inherited_signaling(self):
601592
assert_equal(res['allowed'], True)
602593

603594
# Create an opt-out child tx spending the opt-in parent
604-
parent_utxo = wallet.get_utxo(txid=optin_parent_tx['txid'])
605-
optout_child_tx = wallet.send_self_transfer(
595+
parent_utxo = self.wallet.get_utxo(txid=optin_parent_tx['txid'])
596+
optout_child_tx = self.wallet.send_self_transfer(
606597
from_node=self.nodes[0],
607598
utxo_to_spend=parent_utxo,
608599
sequence=0xffffffff,
@@ -612,7 +603,7 @@ def test_no_inherited_signaling(self):
612603
# Reports true due to inheritance
613604
assert_equal(True, self.nodes[0].getmempoolentry(optout_child_tx['txid'])['bip125-replaceable'])
614605

615-
replacement_child_tx = wallet.create_self_transfer(
606+
replacement_child_tx = self.wallet.create_self_transfer(
616607
from_node=self.nodes[0],
617608
utxo_to_spend=parent_utxo,
618609
sequence=0xffffffff,
@@ -631,9 +622,7 @@ def test_no_inherited_signaling(self):
631622
assert_raises_rpc_error(-26, 'txn-mempool-conflict', self.nodes[0].sendrawtransaction, replacement_child_tx["hex"], 0)
632623

633624
def test_replacement_relay_fee(self):
634-
wallet = MiniWallet(self.nodes[0])
635-
wallet.scan_blocks(start=77, num=1)
636-
tx = wallet.send_self_transfer(from_node=self.nodes[0])['tx']
625+
tx = self.wallet.send_self_transfer(from_node=self.nodes[0])['tx']
637626

638627
# Higher fee, higher feerate, different txid, but the replacement does not provide a relay
639628
# fee conforming to node's `incrementalrelayfee` policy of 1000 sat per KB.

0 commit comments

Comments
 (0)