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) 2017-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.5"""Test wallet fallbackfee."""7from decimal import Decimal9from test_framework.blocktools import COINBASE_MATURITY10from test_framework.test_framework import BitcoinTestFramework11from test_framework.util import assert_equal, assert_raises_rpc_error13HIGH_TX_FEE_PER_KB = Decimal('0.01')16class WalletFallbackFeeTest(BitcoinTestFramework):17def set_test_params(self):18self.num_nodes = 119self.setup_clean_chain = True21def skip_test_if_missing_module(self):22self.skip_if_no_wallet()24def sending_succeeds(self, node):25# Check that fallback fee is being used as a test-of-the-test.26assert_equal(27node.sendtoaddress(node.getnewaddress(), 1, verbose=True)['fee_reason'],28"Fallback fee"29)30node.fundrawtransaction(node.createrawtransaction([], {node.getnewaddress(): 1}))31assert_equal(32node.sendmany("", {node.getnewaddress(): 1}, verbose=True)["fee_reason"],33"Fallback fee"34)36def sending_fails(self, node):37assert_raises_rpc_error(-6, "Fee estimation failed", lambda: node.sendtoaddress(node.getnewaddress(), 1))38assert_raises_rpc_error(-4, "Fee estimation failed", lambda: node.fundrawtransaction(node.createrawtransaction([], {node.getnewaddress(): 1})))39assert_raises_rpc_error(-6, "Fee estimation failed", lambda: node.sendmany("", {node.getnewaddress(): 1}))41def run_test(self):42node = self.nodes[0]43self.generate(node, COINBASE_MATURITY + 1)45# By default, the test framework sets a fallback fee for nodes,46# in order to test default behavior, comment this line out.47node.replace_in_config([("fallbackfee=", "#fallbackfee=")])48self.restart_node(0)50# Sending a transaction with no -fallbackfee setting fails, since the51# default value is 0.52self.sending_fails(node)54# Sending a tx with explicitly disabled fallback fee fails.55self.restart_node(0, extra_args=["-fallbackfee=0"])56self.sending_fails(node)58# Sending a transaction with a fallback fee set succeeds. Use the59# largest fallbackfee value that doesn't trigger a warning.60self.restart_node(0, extra_args=[f"-fallbackfee={HIGH_TX_FEE_PER_KB}"])61self.sending_succeeds(node)62self.stop_node(0, expected_stderr='')64# Starting a node with a large fallback fee set...65excessive_fallback = HIGH_TX_FEE_PER_KB + Decimal('0.00000001')66self.start_node(0, extra_args=[f"-fallbackfee={excessive_fallback}"])67# ...works...68self.sending_succeeds(node)69# ...but results in a warning message.70expected_error = "Warning: -fallbackfee is set very high! This is the transaction fee you may pay when fee estimates are not available."71self.stop_node(0, expected_stderr=expected_error)74if __name__ == '__main__':75WalletFallbackFeeTest(__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.