0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00
bitcoin-bitcoin-core/test/functional/feature_framework_miniwallet.py
Ava Chow 4ac1efb147
Merge bitcoin/bitcoin#30322: test: raise an error in _bulk_tx_ when target_vsize is too low
92787dd52c test: raise an error when target_vsize is below tx virtual size (ismaelsadeeq)
a8780c937f test: raise an error if output value is <= 0 in `create_self_transfer` (ismaelsadeeq)
f6e88931f0 test: test that `create_self_transfer_multi` respects `target_vsize` (ismaelsadeeq)

Pull request description:

  This is a simple test PR that does two things:

  1. Raise an exception in `_bulk_tx_` when `target_vsize` is too low, i.e., below the tx vsize.
  2. Addresses some review comments from https://github.com/bitcoin/bitcoin/pull/30162, which are:
     - Raise an error if the output value is less than or equal to zero in `create_self_transfer`.
  This prevents creating transactions with a value of 0 or less.
     - Add a test to verify that `create_self_transfer_multi` also respects the passed `target_vsize`.

ACKs for top commit:
  achow101:
    ACK 92787dd52c
  theStack:
    ACK 92787dd52c
  rkrux:
    reACK 92787dd52c
  glozow:
    ACK 92787dd52c

Tree-SHA512: 1f2767f2cf715ed65074c5fff347eec160b142685777d833d5e872cfef364d3dc1916b52ee442e99c7b9a8d514ff62bc67a9899d8854f65a4b93ac3ae300d18e
2025-01-24 18:27:32 -05:00

68 lines
2.8 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright (c) 2024 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test MiniWallet."""
import random
import string
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
)
from test_framework.wallet import (
MiniWallet,
MiniWalletMode,
)
class FeatureFrameworkMiniWalletTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
def test_tx_padding(self):
"""Verify that MiniWallet's transaction padding (`target_vsize` parameter)
works accurately with all modes."""
for mode_name, wallet in self.wallets:
self.log.info(f"Test tx padding with MiniWallet mode {mode_name}...")
utxo = wallet.get_utxo(mark_as_spent=False)
for target_vsize in [250, 500, 1250, 2500, 5000, 12500, 25000, 50000, 1000000,
248, 501, 1085, 3343, 5805, 12289, 25509, 55855, 999998]:
tx = wallet.create_self_transfer(utxo_to_spend=utxo, target_vsize=target_vsize)
assert_equal(tx['tx'].get_vsize(), target_vsize)
child_tx = wallet.create_self_transfer_multi(utxos_to_spend=[tx["new_utxo"]], target_vsize=target_vsize)
assert_equal(child_tx['tx'].get_vsize(), target_vsize)
def test_wallet_tagging(self):
"""Verify that tagged wallet instances are able to send funds."""
self.log.info("Test tagged wallet instances...")
node = self.nodes[0]
untagged_wallet = self.wallets[0][1]
for i in range(10):
tag = ''.join(random.choice(string.ascii_letters) for _ in range(20))
self.log.debug(f"-> ({i}) tag name: {tag}")
tagged_wallet = MiniWallet(node, tag_name=tag)
untagged_wallet.send_to(from_node=node, scriptPubKey=tagged_wallet.get_scriptPubKey(), amount=100000)
tagged_wallet.rescan_utxos()
tagged_wallet.send_self_transfer(from_node=node)
self.generate(node, 1) # clear mempool
def run_test(self):
node = self.nodes[0]
self.wallets = [
("ADDRESS_OP_TRUE", MiniWallet(node, mode=MiniWalletMode.ADDRESS_OP_TRUE)),
("RAW_OP_TRUE", MiniWallet(node, mode=MiniWalletMode.RAW_OP_TRUE)),
("RAW_P2PK", MiniWallet(node, mode=MiniWalletMode.RAW_P2PK)),
]
for _, wallet in self.wallets:
self.generate(wallet, 10)
self.generate(wallet, COINBASE_MATURITY)
self.test_tx_padding()
self.test_wallet_tagging()
if __name__ == '__main__':
FeatureFrameworkMiniWalletTest(__file__).main()