Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2018-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.6from test_framework.messages import (7tx_from_hex,8)9from test_framework.test_framework import BitcoinTestFramework10from test_framework.util import (11assert_equal,12assert_raises_rpc_error,13)14from test_framework.blocktools import (15TIME_GENESIS_BLOCK,16)18from decimal import Decimal20class CreateTxWalletTest(BitcoinTestFramework):21def set_test_params(self):22self.setup_clean_chain = True23self.num_nodes = 124self.extra_args = [[]]26def skip_test_if_missing_module(self):27self.skip_if_no_wallet()29def run_test(self):30self.log.info('Create some old blocks')31self.nodes[0].setmocktime(TIME_GENESIS_BLOCK)32self.generate(self.nodes[0], 200)33self.nodes[0].setmocktime(0)35self.test_anti_fee_sniping()36self.test_tx_size_too_large()37self.test_create_too_long_mempool_chain()38self.test_version3()40def test_anti_fee_sniping(self):41self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')42assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 200)43txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)44tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']45assert_equal(tx['locktime'], 0)47self.log.info('Check that anti-fee-sniping is enabled when we mine a recent block')48self.generate(self.nodes[0], 1)49txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)50tx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']51assert 0 < tx['locktime'] <= 20153def test_tx_size_too_large(self):54# More than 10kB of outputs, so that we hit -maxtxfee with a high feerate55outputs = {self.nodes[0].getnewaddress(address_type='bech32'): 0.000025 for _ in range(400)}56raw_tx = self.nodes[0].createrawtransaction(inputs=[], outputs=outputs)58for fee_setting in ['-minrelaytxfee=0.01', '-mintxfee=0.01']:59self.log.info('Check maxtxfee in combination with {}'.format(fee_setting))60self.restart_node(0, extra_args=[fee_setting])61assert_raises_rpc_error(62-6,63"Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",64lambda: self.nodes[0].sendmany(dummy="", amounts=outputs),65)66assert_raises_rpc_error(67-4,68"Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",69lambda: self.nodes[0].fundrawtransaction(hexstring=raw_tx),70)72# Hit maxtxfee with explicit fee rate73self.log.info('Check maxtxfee in combination with explicit fee_rate=1000 sat/vB')75fee_rate_sats_per_vb = Decimal('0.01') * Decimal(1e8) / 1000 # Convert 0.01 BTC/kvB to sat/vB77assert_raises_rpc_error(78-6,79"Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",80lambda: self.nodes[0].sendmany(dummy="", amounts=outputs, fee_rate=fee_rate_sats_per_vb),81)82assert_raises_rpc_error(83-4,84"Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",85lambda: self.nodes[0].fundrawtransaction(hexstring=raw_tx, options={'fee_rate': fee_rate_sats_per_vb}),86)88def test_create_too_long_mempool_chain(self):89self.log.info('Check too-long mempool chain error')90df_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)92self.nodes[0].createwallet("too_long")93test_wallet = self.nodes[0].get_wallet_rpc("too_long")95tx_data = df_wallet.send(outputs=[{test_wallet.getnewaddress(): 25}], options={"change_position": 0})96txid = tx_data['txid']97vout = 199self.nodes[0].syncwithvalidationinterfacequeue()100options = {"change_position": 0, "add_inputs": False}101for i in range(1, 25):102options['inputs'] = [{'txid': txid, 'vout': vout}]103tx_data = test_wallet.send(outputs=[{test_wallet.getnewaddress(): 25 - i}], options=options)104txid = tx_data['txid']106# Sending one more chained transaction will fail107options = {"minconf": 0, "include_unsafe": True, 'add_inputs': True}108assert_raises_rpc_error(-4, "Unconfirmed UTXOs are available, but spending them creates a chain of transactions that will be rejected by the mempool",109test_wallet.send, outputs=[{test_wallet.getnewaddress(): 0.3}], options=options)111test_wallet.unloadwallet()113def test_version3(self):114self.log.info('Check wallet does not create transactions with version=3 yet')115wallet_rpc = self.nodes[0].get_wallet_rpc(self.default_wallet_name)117self.nodes[0].createwallet("version3")118wallet_v3 = self.nodes[0].get_wallet_rpc("version3")120tx_data = wallet_rpc.send(outputs=[{wallet_v3.getnewaddress(): 25}], options={"change_position": 0})121wallet_tx_data = wallet_rpc.gettransaction(tx_data["txid"])122tx_current_version = tx_from_hex(wallet_tx_data["hex"])124# While version=3 transactions are standard, the CURRENT_VERSION is 2.125# This test can be removed if CURRENT_VERSION is changed, and replaced with tests that the126# wallet handles TRUC rules properly.127assert_equal(tx_current_version.version, 2)128wallet_v3.unloadwallet()131if __name__ == '__main__':132CreateTxWalletTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.