Skip to content

Commit aa02c64

Browse files
committed
test: use MiniWallet for simple doublespend test in feature_rbf.py
1 parent a3f6397 commit aa02c64

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

test/functional/feature_rbf.py

Lines changed: 8 additions & 16 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
@@ -88,7 +89,7 @@ def run_test(self):
8889
# the pre-mined test framework chain contains coinbase outputs to the
8990
# MiniWallet's default address ADDRESS_BCRT1_P2WSH_OP_TRUE in blocks
9091
# 76-100 (see method BitcoinTestFramework._initialize_chain())
91-
self.wallet.scan_blocks(start=76, num=1)
92+
self.wallet.scan_blocks(start=76, num=2)
9293

9394
self.log.info("Running test simple doublespend...")
9495
self.test_simple_doublespend()
@@ -130,34 +131,25 @@ def run_test(self):
130131

131132
def test_simple_doublespend(self):
132133
"""Simple doublespend"""
133-
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
134-
135-
# make_utxo may have generated a bunch of blocks, so we need to sync
136-
# before we can spend the coins generated, or else the resulting
137-
# transactions might not be accepted by our peers.
138-
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']
139137

140-
tx1a = CTransaction()
141-
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
138+
tx1a = deepcopy(tx_template)
142139
tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT)]
143140
tx1a_hex = tx1a.serialize().hex()
144141
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, 0)
145142

146-
self.sync_all()
147-
148143
# Should fail because we haven't changed the fee
149-
tx1b = CTransaction()
150-
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
144+
tx1b = deepcopy(tx_template)
151145
tx1b.vout = [CTxOut(1 * COIN, DUMMY_2_P2WPKH_SCRIPT)]
152146
tx1b_hex = tx1b.serialize().hex()
153147

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

157151
# Extra 0.1 BTC fee
158-
tx1b = CTransaction()
159-
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
160-
tx1b.vout = [CTxOut(int(0.9 * COIN), DUMMY_P2WPKH_SCRIPT)]
152+
tx1b.vout[0].nValue -= int(0.1 * COIN)
161153
tx1b_hex = tx1b.serialize().hex()
162154
# Works when enabled
163155
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, 0)

0 commit comments

Comments
 (0)