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.5"""Test the getblockfilter RPC."""7from test_framework.test_framework import BitcoinTestFramework8from test_framework.util import (9assert_equal, assert_is_hex_string, assert_raises_rpc_error,10)12FILTER_TYPES = ["basic"]14class GetBlockFilterTest(BitcoinTestFramework):15def set_test_params(self):16self.setup_clean_chain = True17self.num_nodes = 218self.extra_args = [["-blockfilterindex"], []]20def run_test(self):21# Create two chains by disconnecting nodes 0 & 1, mining, then reconnecting22self.disconnect_nodes(0, 1)24self.generate(self.nodes[0], 3, sync_fun=self.no_op)25self.generate(self.nodes[1], 4, sync_fun=self.no_op)27assert_equal(self.nodes[0].getblockcount(), 3)28chain0_hashes = [self.nodes[0].getblockhash(block_height) for block_height in range(4)]30# Reorg node 0 to a new chain31self.connect_nodes(0, 1)32self.sync_blocks()34assert_equal(self.nodes[0].getblockcount(), 4)35chain1_hashes = [self.nodes[0].getblockhash(block_height) for block_height in range(4)]37# Test getblockfilter returns a filter for all blocks and filter types on active chain38for block_hash in chain1_hashes:39for filter_type in FILTER_TYPES:40result = self.nodes[0].getblockfilter(block_hash, filter_type)41assert_is_hex_string(result['filter'])43# Test getblockfilter returns a filter for all blocks and filter types on stale chain44for block_hash in chain0_hashes:45for filter_type in FILTER_TYPES:46result = self.nodes[0].getblockfilter(block_hash, filter_type)47assert_is_hex_string(result['filter'])49# Test getblockfilter with unknown block50bad_block_hash = "0123456789abcdef" * 451assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblockfilter, bad_block_hash, "basic")53# Test getblockfilter with undefined filter type54genesis_hash = self.nodes[0].getblockhash(0)55assert_raises_rpc_error(-5, "Unknown filtertype", self.nodes[0].getblockfilter, genesis_hash, "unknown")57# Test getblockfilter fails on node without compact block filter index58self.restart_node(0, extra_args=["-blockfilterindex=0"])59for filter_type in FILTER_TYPES:60assert_raises_rpc_error(-1, "Index is not enabled for filtertype {}".format(filter_type),61self.nodes[0].getblockfilter, genesis_hash, filter_type)63if __name__ == '__main__':64GetBlockFilterTest(__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.