diff --git a/test/functional/feature_addressindex.py b/test/functional/feature_addressindex.py index 176083b3cf21..42c31105d1fb 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,17 @@ 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] + 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_equal(node.getaddressbalance(new_address)["received"], paid) assert_equal(node.getaddressbalance(orphan_address)["received"], 0) assert_equal(node.getaddresstxids(orphan_address), []) 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/feature_masternode_payout_shares.py b/test/functional/feature_masternode_payout_shares.py index b3976c21f06a..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,10 +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) - assert softfork_active(self.nodes[0], "v24") + 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 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) 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)