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.
251self.restart_node(1, ['-persistmempool=0'])252self.connect_nodes(0, 1)253self.sync_blocks()254self.nodes[1].sendrawtransaction(tx_orig)255self.generatetoaddress(self.nodes[1], 1, ADDRESS_WATCHONLY)256assert_equal(self.nodes[0].getbalance(minconf=0), total_amount + 1) # The reorg recovered our fee of 1 coin258# Tests the lastprocessedblock JSON object in getbalances, getwalletinfo259# and gettransaction by checking for valid hex strings and by comparing260# the hashes & heights between generated blocks.261self.log.info("Test getbalances returns expected lastprocessedblock json object")262prev_hash = self.nodes[0].getbestblockhash()263prev_height = self.nodes[0].getblock(prev_hash)['height']264self.generatetoaddress(self.nodes[0], 5, self.nodes[0].get_deterministic_priv_key().address)265lastblock = self.nodes[0].getbalances()['lastprocessedblock']266assert_is_hash_string(lastblock['hash'])267assert_equal((prev_hash == lastblock['hash']), False)268assert_equal(lastblock['height'], prev_height + 5)270prev_hash = self.nodes[0].getbestblockhash()271prev_height = self.nodes[0].getblock(prev_hash)['height']272self.log.info("Test getwalletinfo returns expected lastprocessedblock json object")273walletinfo = self.nodes[0].getwalletinfo()274assert_equal(walletinfo['lastprocessedblock']['height'], prev_height)275assert_equal(walletinfo['lastprocessedblock']['hash'], prev_hash)277self.log.info("Test gettransaction returns expected lastprocessedblock json object")278txid = self.nodes[1].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)279tx_info = self.nodes[1].gettransaction(txid)280assert_equal(tx_info['lastprocessedblock']['height'], prev_height)281assert_equal(tx_info['lastprocessedblock']['hash'], prev_hash)283self.log.info("Test that the balance is updated by an import that makes an untracked output in an existing tx \"mine\"")284default = self.nodes[0].get_wallet_rpc(self.default_wallet_name)285self.nodes[0].createwallet("importupdate")286wallet = self.nodes[0].get_wallet_rpc("importupdate")288import_key1 = get_generate_key()289import_key2 = get_generate_key()290wallet.importdescriptors([{"desc": descsum_create(f"wpkh({import_key1.privkey})"), "timestamp": "now"}])292amount = 15293default.send([{import_key1.p2wpkh_addr: amount},{import_key2.p2wpkh_addr: amount}])294self.generate(self.nodes[0], 1)295# Mock the time forward by 1 day so that "now" will exclude the block we just mined296self.nodes[0].setmocktime(int(time.time()) + 86400)297# Mine 11 blocks to move the MTP past the block we just mined298self.generate(self.nodes[0], 11, sync_fun=self.no_op)300balances = wallet.getbalances()301assert_equal(balances["mine"]["trusted"], amount)303# Don't rescan to make sure that the import updates the wallet txos304wallet.importdescriptors([{"desc": descsum_create(f"wpkh({import_key2.privkey})"), "timestamp": "now"}])305balances = wallet.getbalances()306assert_equal(balances["mine"]["trusted"], amount * 2)308if __name__ == '__main__':309WalletTest(__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.