diff --git a/test/functional/rpc_scanblocks.py b/test/functional/rpc_scanblocks.py index f2f98474c9..c61997fe86 100755 --- a/test/functional/rpc_scanblocks.py +++ b/test/functional/rpc_scanblocks.py @@ -3,11 +3,11 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the scanblocks RPC call.""" -# from test_framework.address import address_to_scriptpubkey -# from test_framework.blockfilter import ( -# bip158_basic_element_hash, -# bip158_relevant_scriptpubkeys, -# ) +from test_framework.address import address_to_scriptpubkey +from test_framework.blockfilter import ( + bip158_basic_element_hash, + bip158_relevant_scriptpubkeys, +) from test_framework.messages import COIN from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( @@ -23,7 +23,7 @@ from test_framework.wallet import ( class ScanblocksTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 - self.extra_args = [["-blockfilterindex=1"], []] + self.extra_args = [["-blockfilterindex=1"],[]] def run_test(self): node = self.nodes[0] @@ -87,27 +87,30 @@ class ScanblocksTest(BitcoinTestFramework): # finding a false-positive at runtime would take too long, hence we simply # use a pre-calculated one that collides with the regtest genesis block's # coinbase output and verify that their BIP158 ranged hashes match - # ELEMENTS: FIXME - # genesis_blockhash = node.getblockhash(0) - # genesis_spks = bip158_relevant_scriptpubkeys(node, genesis_blockhash) - # assert_equal(len(genesis_spks), 1) - # genesis_coinbase_spk = list(genesis_spks)[0] - # false_positive_spk = bytes.fromhex("001400000000000000000000000000000000000cadcb") + # ELEMENTS: use block 1 for coinbase spk + genesis_blockhash = node.getblockhash(1) + print(genesis_blockhash) + print("") + genesis_spks = bip158_relevant_scriptpubkeys(node, genesis_blockhash) + assert_equal(len(genesis_spks), 1) + genesis_coinbase_spk = list(genesis_spks)[0] + # ELEMENTS: hash collision for block 1 spk + false_positive_spk = bytes.fromhex("000000155205000000000000000000000000000cadcb") - # genesis_coinbase_hash = bip158_basic_element_hash(genesis_coinbase_spk, 1, genesis_blockhash) - # false_positive_hash = bip158_basic_element_hash(false_positive_spk, 1, genesis_blockhash) - # assert_equal(genesis_coinbase_hash, false_positive_hash) + genesis_coinbase_hash = bip158_basic_element_hash(genesis_coinbase_spk, 1, genesis_blockhash) + false_positive_hash = bip158_basic_element_hash(false_positive_spk, 1, genesis_blockhash) + assert_equal(genesis_coinbase_hash, false_positive_hash) - # assert genesis_blockhash in node.scanblocks( - # "start", [{"desc": f"raw({genesis_coinbase_spk.hex()})"}], 0, 0)['relevant_blocks'] - # assert genesis_blockhash in node.scanblocks( - # "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0)['relevant_blocks'] + assert genesis_blockhash in node.scanblocks( + "start", [{"desc": f"raw({genesis_coinbase_spk.hex()})"}], 0, 1)['relevant_blocks'] + assert genesis_blockhash in node.scanblocks( + "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 1)['relevant_blocks'] # check that the filter_false_positives option works - # assert genesis_blockhash in node.scanblocks( - # "start", [{"desc": f"raw({genesis_coinbase_spk.hex()})"}], 0, 0, "basic", {"filter_false_positives": True})['relevant_blocks'] - # assert genesis_blockhash not in node.scanblocks( - # "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0, "basic", {"filter_false_positives": True})['relevant_blocks'] + assert genesis_blockhash in node.scanblocks( + "start", [{"desc": f"raw({genesis_coinbase_spk.hex()})"}], 0, 1, "basic", {"filter_false_positives": True})['relevant_blocks'] + assert genesis_blockhash not in node.scanblocks( + "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 1, "basic", {"filter_false_positives": True})['relevant_blocks'] # test node with disabled blockfilterindex assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic",