From 596601cb814b1d5e2313c531c4b15d73d1bef440 Mon Sep 17 00:00:00 2001 From: pasta Date: Sat, 14 Nov 2026 19:13:54 +0000 Subject: [PATCH 1/4] test: make two functional test checks able to fail p2p_instantsend.py asserted that the key "confirmation" was absent from getrawtransaction, but the key is "confirmations", so the check that a transaction without a lock is not mined before it is 10 minutes old never ran. It would have failed: the isolated node's mocktime lagged behind the bumps made while waiting for the lock, so the transaction was already old enough. Sync the isolated node's clock and assert the early block leaves the transaction in the mempool. The rejection of the doublespend block was checked with waitforblock timeouts of 10 ms and 1 ms, before the block could arrive; wait for it to be listed as invalid instead. feature_masternode_params.py only logged the masternode's services and indexes and asserted getblockcount() >= 0, and looked the block filter index up under the wrong name, so its "regular node has no filter index" check could not fail either. Assert the service bit and the index. Co-Authored-By: Claude Fable 5.2 --- test/functional/feature_masternode_params.py | 10 ++----- test/functional/p2p_instantsend.py | 29 ++++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/test/functional/feature_masternode_params.py b/test/functional/feature_masternode_params.py index a674a902e849..09da856265b1 100755 --- a/test/functional/feature_masternode_params.py +++ b/test/functional/feature_masternode_params.py @@ -16,7 +16,7 @@ NODE_COMPACT_FILTERS = (1 << 6) # Constants -BASIC_FILTER_INDEX = 'basic filter index' +BASIC_FILTER_INDEX = 'basic block filter index' class MasternodeParamsTest(BitcoinTestFramework): @@ -50,15 +50,11 @@ def run_test(self): # Masternode should have peerblockfilters enabled services = int(node1.getnetworkinfo()['localservices'], 16) - self.log.info(f"Masternode services: {hex(services)}, has COMPACT_FILTERS: {services & NODE_COMPACT_FILTERS != 0}") + assert services & NODE_COMPACT_FILTERS # Check blockfilterindex index_info = node1.getindexinfo() - self.log.info(f"Masternode indexes: {list(index_info.keys())}") - - # For now, just check that the node started successfully with masternode key - # The actual filter enabling might require the node to be fully synced - assert node1.getblockcount() >= 0 # Basic check that node is running + assert BASIC_FILTER_INDEX in index_info self.log.info("Test that masternode refuses settings that silently skip its duties") self.stop_node(1) diff --git a/test/functional/p2p_instantsend.py b/test/functional/p2p_instantsend.py index 7ae8fa353889..1c7dfbd4db51 100755 --- a/test/functional/p2p_instantsend.py +++ b/test/functional/p2p_instantsend.py @@ -81,27 +81,28 @@ def test_block_doublespend(self): connected_nodes = self.nodes.copy() del connected_nodes[self.isolated_idx] self.wait_for_instantlock(is_id, nodes=connected_nodes) - # send doublespend transaction to isolated node + # send doublespend transaction to isolated node, whose clock missed the bumps made while waiting for the lock + isolated.setmocktime(self.mocktime) dblspnd_txid = isolated.sendrawtransaction(dblspnd_tx['hex']) - # generate block on isolated node with doublespend transaction + # a transaction without a lock is not mined until it is 10 minutes old self.bump_mocktime(599) - wrong_early_block = self.generate(isolated, 1, sync_fun=self.no_op)[0] - assert not "confirmation" in isolated.getrawtransaction(dblspnd_txid, 1) - isolated.invalidateblock(wrong_early_block) + early_block = self.generate(isolated, 1, sync_fun=self.no_op)[0] + assert dblspnd_txid not in isolated.getblock(early_block)["tx"] + assert dblspnd_txid in isolated.getrawmempool() + isolated.invalidateblock(early_block) + # generate block on isolated node with doublespend transaction self.bump_mocktime(1) wrong_block = self.generate(isolated, 1, sync_fun=self.no_op)[0] assert_equal(isolated.getrawtransaction(dblspnd_txid, 1)["confirmations"], 1) # connect isolated block to network self.reconnect_isolated_node(self.isolated_idx, 0) - # check doublespend block is rejected by other nodes - timeout = 10 - for idx, node in enumerate(self.nodes): - if idx == self.isolated_idx: - continue - res = node.waitforblock(wrong_block, timeout) - assert res['hash'] != wrong_block - # wait for long time only for first node - timeout = 1 + # check doublespend block is rejected + self.wait_until(lambda: any(tip["hash"] == wrong_block and tip["status"] == "invalid" + for tip in self.nodes[0].getchaintips())) + self.sync_blocks([n for n in self.nodes if n is not isolated]) + for node in self.nodes: + if node is not isolated: + assert node.getbestblockhash() != wrong_block # send coins back to the controller node without waiting for confirmations receiver.sendtoaddress(self.nodes[0].getnewaddress(), 0.9, "", "", True) assert_equal(receiver.getwalletinfo()["balance"], 0) From eed2f50ab2ef010ec27e4a37a437fe0ebdd860c3 Mon Sep 17 00:00:00 2001 From: pasta Date: Sun, 15 Nov 2026 05:20:18 +0000 Subject: [PATCH 2/4] test: make index and EHF checks observe the behavior they name feature_addressindex.py and feature_spentindex.py toggled the index off and on at genesis, before any block the index could miss. The toggle now covers a spend mined while the index is disabled, and the index has to catch up when it is turned back on. feature_mnehf.py asserted that a payload it had just filled in still contained those values, and polled activation one block at a time. The payload check is gone. Activation is mined across the BIP9 windows and the started, locked_in and active states are checked. feature_masternode_payout_shares.py asserted that v24 was active after a loop that only exits once it is. Co-Authored-By: Claude Fable 5.2 Co-authored-by: Cursor --- test/functional/feature_addressindex.py | 13 ++------ .../feature_masternode_payout_shares.py | 1 - test/functional/feature_mnehf.py | 17 +++++----- test/functional/feature_spentindex.py | 31 +++++++++---------- 4 files changed, 24 insertions(+), 38 deletions(-) diff --git a/test/functional/feature_addressindex.py b/test/functional/feature_addressindex.py index 176083b3cf21..df68acb433db 100755 --- a/test/functional/feature_addressindex.py +++ b/test/functional/feature_addressindex.py @@ -49,15 +49,6 @@ def setup_network(self): self.import_deterministic_coinbase_privkeys() def run_test(self): - self.log.info("Test that settings can be disabled and re-enabled...") - self.restart_node(1, ["-addressindex=0"]) - self.connect_nodes(0, 1) - self.sync_all() - # AddressIndex is now async, so it can be enabled without -reindex - self.restart_node(1, ["-addressindex"]) - self.connect_nodes(0, 1) - self.sync_all() - self.log.info("Mining blocks...") mining_address = self.nodes[0].getnewaddress() self.generatetoaddress(self.nodes[0], 105, mining_address) @@ -361,10 +352,12 @@ def test_reorg_while_disabled(self): self.restart_node(3, ["-addressindex=0"]) node.invalidateblock(orphan_block) - self.generatetoaddress(node, 2, getnewdestination()[2], sync_fun=self.no_op) + new_address = getnewdestination()[2] + self.generatetoaddress(node, 2, new_address, sync_fun=self.no_op) self.restart_node(3, ["-addressindex"]) self.wait_index_synced(node) + assert_greater_than(node.getaddressbalance(new_address)["received"], 0) assert_equal(node.getaddressbalance(orphan_address)["received"], 0) assert_equal(node.getaddresstxids(orphan_address), []) diff --git a/test/functional/feature_masternode_payout_shares.py b/test/functional/feature_masternode_payout_shares.py index b3976c21f06a..0a541e3f2eed 100755 --- a/test/functional/feature_masternode_payout_shares.py +++ b/test/functional/feature_masternode_payout_shares.py @@ -30,7 +30,6 @@ def activate_v24(self): while not softfork_active(self.nodes[0], "v24"): self.bump_mocktime(50) self.generate(self.nodes[0], 50, sync_fun=self.no_op) - assert softfork_active(self.nodes[0], "v24") def build_block(self, node, tamper=None): """Build a block extending the tip whose coinbase pays exactly the template's diff --git a/test/functional/feature_mnehf.py b/test/functional/feature_mnehf.py index 851607a8e5bb..bc9581e6b7e0 100755 --- a/test/functional/feature_mnehf.py +++ b/test/functional/feature_mnehf.py @@ -145,13 +145,8 @@ def run_test(self): ehf_tx = self.create_mnehf(28, pubkey) ehf_unknown_tx = self.create_mnehf(27, pubkey) - self.log.info("Checking deserialization of CMnEhf by python's code") mnehf_payload = CMnEhf() mnehf_payload.deserialize(BytesIO(ehf_tx.vExtraPayload)) - assert_equal(mnehf_payload.version, 1) - assert_equal(mnehf_payload.versionBit, 28) - self.log.info("Checking correctness of requestId and quorumHash") - assert_equal(mnehf_payload.quorumHash, int(self.mninfo[0].get_node(self).quorum("selectquorum", 100, 'a0eee872d7d3170dd20d5c5e8380c92b3aa887da5f63d8033289fafa35a90691')["quorumHash"], 16)) ehf_tx_sent = self.send_tx(ehf_tx) self.log.info(f"ehf tx: {ehf_tx_sent}") @@ -243,11 +238,13 @@ def run_test(self): self.mine_quorum_single_member() self.check_fork('defined') - def check_ehf_activated(self): - self.bump_mocktime(1) - self.generate(self.nodes[1], 1) - return get_bip9_details(self.nodes[0], 'testdummy')['status'] == 'active' - self.wait_until(lambda: check_ehf_activated(self), sleep=1) + self.wait_until(lambda: len(self.ehf_signals_in_mempool(self.nodes[1], 28)) == 1) + self.generate(self.nodes[1], 4, sync_fun=self.sync_blocks) + self.check_fork('started') + self.generate(self.nodes[1], 4, sync_fun=self.sync_blocks) + self.check_fork('locked_in') + self.generate(self.nodes[1], 4, sync_fun=self.sync_blocks) + self.check_fork('active') if __name__ == '__main__': MnehfTest().main() diff --git a/test/functional/feature_spentindex.py b/test/functional/feature_spentindex.py index 9413e47023b6..00f862932676 100755 --- a/test/functional/feature_spentindex.py +++ b/test/functional/feature_spentindex.py @@ -29,7 +29,7 @@ def add_options(self, parser): def set_test_params(self): self.setup_clean_chain = True - self.num_nodes = 4 + self.num_nodes = 3 def skip_test_if_missing_module(self): self.skip_if_no_wallet() @@ -39,25 +39,14 @@ def setup_network(self): # Nodes 0/1 are "wallet" nodes self.start_node(0) self.start_node(1, ["-spentindex"]) - # Nodes 2/3 are used for testing - self.start_node(2, ["-spentindex"]) - self.start_node(3, ["-spentindex", "-txindex"]) + # Node 2 is used for testing + self.start_node(2, ["-spentindex", "-txindex"]) self.connect_nodes(0, 1) self.connect_nodes(0, 2) - self.connect_nodes(0, 3) self.sync_all() self.import_deterministic_coinbase_privkeys() def run_test(self): - self.log.info("Test that settings can be disabled and re-enabled...") - self.restart_node(1, ["-spentindex=0"]) - self.connect_nodes(0, 1) - self.sync_all() - # SpentIndex is now async, so it can be enabled without -reindex - self.restart_node(1, ["-spentindex"]) - self.connect_nodes(0, 1) - self.sync_all() - self.log.info("Mining blocks...") self.generate(self.nodes[0], 105) @@ -80,8 +69,16 @@ def run_test(self): tx.rehash() signed_tx = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex()) + self.log.info("Test that the index catches up without -reindex on a spend mined while it was disabled") + self.restart_node(1, ["-spentindex=0"]) + self.connect_nodes(0, 1) txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], 0) self.generate(self.nodes[0], 1) + # SpentIndex is async, so it can be enabled without -reindex + self.restart_node(1, ["-spentindex"]) + self.connect_nodes(0, 1) + self.sync_all() + self.wait_until(lambda: self.nodes[1].getindexinfo()["spentindex"] == {"synced": True, "best_block_height": 106}) self.log.info("Testing getspentinfo method...") @@ -94,13 +91,13 @@ def run_test(self): self.log.info("Testing getrawtransaction method...") # Check that verbose raw transaction includes spent info - txVerbose = self.nodes[3].getrawtransaction(unspent[0]["txid"], 1) + txVerbose = self.nodes[2].getrawtransaction(unspent[0]["txid"], 1) assert_equal(txVerbose["vout"][unspent[0]["vout"]]["spentTxId"], txid) assert_equal(txVerbose["vout"][unspent[0]["vout"]]["spentIndex"], 0) assert_equal(txVerbose["vout"][unspent[0]["vout"]]["spentHeight"], 106) # Check that verbose raw transaction includes input values - txVerbose2 = self.nodes[3].getrawtransaction(txid, 1) + txVerbose2 = self.nodes[2].getrawtransaction(txid, 1) assert_equal(txVerbose2["vin"][0]["value"], Decimal(unspent[0]["amount"])) assert_equal(txVerbose2["vin"][0]["valueSat"] - tx_fee_sat, amount) @@ -134,7 +131,7 @@ def run_test(self): # Check the database index self.generate(self.nodes[0], 1) - txVerbose4 = self.nodes[3].getrawtransaction(txid2, 1) + txVerbose4 = self.nodes[2].getrawtransaction(txid2, 1) assert_equal(txVerbose4["vin"][0]["address"], address2) assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]) - tx_fee) assert_equal(txVerbose4["vin"][0]["valueSat"], amount) From 4f15516a87a8f6314991d15524eb6e69e1ebe206 Mon Sep 17 00:00:00 2001 From: pasta Date: Sun, 15 Nov 2026 05:36:02 +0000 Subject: [PATCH 3/4] test: require the address index to catch both blocks mined while disabled A received total greater than zero still passed if only one of the two coinbases was indexed. Compare it with the sum paid to the address by both blocks. Co-authored-by: Cursor --- test/functional/feature_addressindex.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_addressindex.py b/test/functional/feature_addressindex.py index df68acb433db..42c31105d1fb 100755 --- a/test/functional/feature_addressindex.py +++ b/test/functional/feature_addressindex.py @@ -353,11 +353,16 @@ def test_reorg_while_disabled(self): self.restart_node(3, ["-addressindex=0"]) node.invalidateblock(orphan_block) new_address = getnewdestination()[2] - self.generatetoaddress(node, 2, new_address, sync_fun=self.no_op) + block_hashes = self.generatetoaddress(node, 2, new_address, sync_fun=self.no_op) + # Greater-than-zero would pass if only one of the two blocks was indexed. + paid = sum(vout["valueSat"] + for block_hash in block_hashes + for vout in node.getblock(block_hash, 2)["tx"][0]["vout"] + if vout["scriptPubKey"].get("address") == new_address) self.restart_node(3, ["-addressindex"]) self.wait_index_synced(node) - assert_greater_than(node.getaddressbalance(new_address)["received"], 0) + assert_equal(node.getaddressbalance(new_address)["received"], paid) assert_equal(node.getaddressbalance(orphan_address)["received"], 0) assert_equal(node.getaddresstxids(orphan_address), []) From 468397eb3d9a3a41ee8cbb5291852b5898bc04ac Mon Sep 17 00:00:00 2001 From: pasta Date: Sun, 15 Nov 2026 06:52:15 +0000 Subject: [PATCH 4/4] test: activate the payout-shares v24 deployment with activate_by_name Setup already mines past height 100, so the old loop was a no-op and the helper's pending-fork check would fail. The minimum activation height now stays above that premine. Co-authored-by: Cursor --- test/functional/feature_masternode_payout_shares.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/functional/feature_masternode_payout_shares.py b/test/functional/feature_masternode_payout_shares.py index 0a541e3f2eed..8360d7391365 100755 --- a/test/functional/feature_masternode_payout_shares.py +++ b/test/functional/feature_masternode_payout_shares.py @@ -8,9 +8,11 @@ from test_framework.messages import CTxOut, tx_from_hex from test_framework.script import CScript from test_framework.test_framework import DashTestFramework, MasternodeInfo, p2p_port -from test_framework.util import assert_equal, softfork_active +from test_framework.util import assert_equal -V24_ACTIVATION_THRESHOLD = 100 +# setup_nodes mines through coinbase maturity (height ~109) before run_test. +# The deployment has to still be pending so activate_by_name can bring v24 in. +V24_ACTIVATION_THRESHOLD = 200 def payout_address_rewards(payouts): @@ -27,9 +29,7 @@ def set_test_params(self): ]]) def activate_v24(self): - while not softfork_active(self.nodes[0], "v24"): - self.bump_mocktime(50) - self.generate(self.nodes[0], 50, sync_fun=self.no_op) + self.activate_by_name("v24") def build_block(self, node, tamper=None): """Build a block extending the tip whose coinbase pays exactly the template's