Skip to content

Commit 27c8786

Browse files
MarcoFalkeglozow
authored andcommitted
test framework: Add and use option for tx-version in MiniWallet methods
1 parent 9a1fea5 commit 27c8786

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

test/functional/feature_bip68_sequence.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,8 @@ def activateCSV(self):
408408
# Use self.nodes[1] to test that version 2 transactions are standard.
409409
def test_version2_relay(self):
410410
mini_wallet = MiniWallet(self.nodes[1])
411-
mini_wallet.rescan_utxos()
412-
tx = mini_wallet.create_self_transfer()["tx"]
413-
tx.nVersion = 2
414-
mini_wallet.sendrawtransaction(from_node=self.nodes[1], tx_hex=tx.serialize().hex())
411+
mini_wallet.send_self_transfer(from_node=self.nodes[1], version=2)
412+
415413

416414
if __name__ == '__main__':
417415
BIP68Test().main()

test/functional/test_framework/wallet.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ def create_self_transfer_multi(
286286
utxos_to_spend: Optional[list[dict]] = None,
287287
num_outputs=1,
288288
amount_per_output=0,
289+
version=2,
289290
locktime=0,
290291
sequence=0,
291292
fee_per_output=1000,
292293
target_weight=0,
293-
confirmed_only=False
294+
confirmed_only=False,
294295
):
295296
"""
296297
Create and return a transaction that spends the given UTXOs and creates a
@@ -313,6 +314,7 @@ def create_self_transfer_multi(
313314
tx = CTransaction()
314315
tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']), nSequence=seq) for utxo_to_spend, seq in zip(utxos_to_spend, sequence)]
315316
tx.vout = [CTxOut(amount_per_output, bytearray(self._scriptPubKey)) for _ in range(num_outputs)]
317+
tx.nVersion = version
316318
tx.nLockTime = locktime
317319

318320
self.sign_tx(tx)
@@ -337,14 +339,15 @@ def create_self_transfer_multi(
337339
"tx": tx,
338340
}
339341

340-
def create_self_transfer(self, *,
342+
def create_self_transfer(
343+
self,
344+
*,
341345
fee_rate=Decimal("0.003"),
342346
fee=Decimal("0"),
343347
utxo_to_spend=None,
344-
locktime=0,
345-
sequence=0,
346348
target_weight=0,
347-
confirmed_only=False
349+
confirmed_only=False,
350+
**kwargs,
348351
):
349352
"""Create and return a tx with the specified fee. If fee is 0, use fee_rate, where the resulting fee may be exact or at most one satoshi higher than needed."""
350353
utxo_to_spend = utxo_to_spend or self.get_utxo(confirmed_only=confirmed_only)
@@ -360,7 +363,12 @@ def create_self_transfer(self, *,
360363
send_value = utxo_to_spend["value"] - (fee or (fee_rate * vsize / 1000))
361364

362365
# create tx
363-
tx = self.create_self_transfer_multi(utxos_to_spend=[utxo_to_spend], locktime=locktime, sequence=sequence, amount_per_output=int(COIN * send_value), target_weight=target_weight)
366+
tx = self.create_self_transfer_multi(
367+
utxos_to_spend=[utxo_to_spend],
368+
amount_per_output=int(COIN * send_value),
369+
target_weight=target_weight,
370+
**kwargs,
371+
)
364372
if not target_weight:
365373
assert_equal(tx["tx"].get_vsize(), vsize)
366374
tx["new_utxo"] = tx.pop("new_utxos")[0]

0 commit comments

Comments
 (0)