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) 2014-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 coinbase transactions return the correct categories.7Tests listtransactions, listsinceblock, and gettransaction.8"""10from test_framework.test_framework import BitcoinTestFramework11from test_framework.util import (12assert_array_result13)15class CoinbaseCategoryTest(BitcoinTestFramework):16def set_test_params(self):17self.num_nodes = 118self.setup_clean_chain = True20def skip_test_if_missing_module(self):21self.skip_if_no_wallet()23def assert_category(self, category, address, txid, skip):24assert_array_result(self.nodes[0].listtransactions(skip=skip),25{"address": address},26{"category": category})27assert_array_result(self.nodes[0].listsinceblock()["transactions"],28{"address": address},29{"category": category})30assert_array_result(self.nodes[0].gettransaction(txid)["details"],31{"address": address},32{"category": category})34def run_test(self):35# Generate one block to an address36address = self.nodes[0].getnewaddress()37self.generatetoaddress(self.nodes[0], 1, address)38hash = self.nodes[0].getbestblockhash()39txid = self.nodes[0].getblock(hash)["tx"][0]41# Coinbase transaction is immature after 1 confirmation42self.assert_category("immature", address, txid, 0)44# Mine another 99 blocks on top45self.generate(self.nodes[0], 99)46# Coinbase transaction is still immature after 100 confirmations47self.assert_category("immature", address, txid, 99)49# Mine one more block50self.generate(self.nodes[0], 1)51# Coinbase transaction is now matured, so category is "generate"52self.assert_category("generate", address, txid, 100)54# Orphan block that paid to address55self.nodes[0].invalidateblock(hash)56# Coinbase transaction is now orphaned57self.assert_category("orphan", address, txid, 100)59if __name__ == '__main__':60CoinbaseCategoryTest(__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.