|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test the RBF code."""
|
6 | 6 |
|
| 7 | +from copy import deepcopy |
7 | 8 | from decimal import Decimal
|
8 | 9 |
|
9 | 10 | from test_framework.blocktools import COINBASE_MATURITY
|
@@ -88,7 +89,7 @@ def run_test(self):
|
88 | 89 | # the pre-mined test framework chain contains coinbase outputs to the
|
89 | 90 | # MiniWallet's default address ADDRESS_BCRT1_P2WSH_OP_TRUE in blocks
|
90 | 91 | # 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) |
92 | 93 |
|
93 | 94 | self.log.info("Running test simple doublespend...")
|
94 | 95 | self.test_simple_doublespend()
|
@@ -130,34 +131,25 @@ def run_test(self):
|
130 | 131 |
|
131 | 132 | def test_simple_doublespend(self):
|
132 | 133 | """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'] |
139 | 137 |
|
140 |
| - tx1a = CTransaction() |
141 |
| - tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)] |
| 138 | + tx1a = deepcopy(tx_template) |
142 | 139 | tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT)]
|
143 | 140 | tx1a_hex = tx1a.serialize().hex()
|
144 | 141 | tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, 0)
|
145 | 142 |
|
146 |
| - self.sync_all() |
147 |
| - |
148 | 143 | # 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) |
151 | 145 | tx1b.vout = [CTxOut(1 * COIN, DUMMY_2_P2WPKH_SCRIPT)]
|
152 | 146 | tx1b_hex = tx1b.serialize().hex()
|
153 | 147 |
|
154 | 148 | # This will raise an exception due to insufficient fee
|
155 | 149 | assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
|
156 | 150 |
|
157 | 151 | # 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) |
161 | 153 | tx1b_hex = tx1b.serialize().hex()
|
162 | 154 | # Works when enabled
|
163 | 155 | tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, 0)
|
|
0 commit comments