|
3 | 3 | # Distributed under the MIT software license, see the accompanying
|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test the scanblocks RPC call."""
|
| 6 | +from test_framework.blockfilter import ( |
| 7 | + bip158_basic_element_hash, |
| 8 | + bip158_relevant_scriptpubkeys, |
| 9 | +) |
6 | 10 | from test_framework.messages import COIN
|
7 | 11 | from test_framework.test_framework import BitcoinTestFramework
|
8 | 12 | from test_framework.util import (
|
@@ -71,6 +75,28 @@ def run_test(self):
|
71 | 75 | assert(blockhash in node.scanblocks(
|
72 | 76 | "start", [{"desc": f"pkh({parent_key}/*)", "range": [0, 100]}], height)['relevant_blocks'])
|
73 | 77 |
|
| 78 | + # check that false-positives are included in the result now; note that |
| 79 | + # finding a false-positive at runtime would take too long, hence we simply |
| 80 | + # use a pre-calculated one that collides with the regtest genesis block's |
| 81 | + # coinbase output and verify that their BIP158 ranged hashes match |
| 82 | + genesis_blockhash = node.getblockhash(0) |
| 83 | + genesis_spks = bip158_relevant_scriptpubkeys(node, genesis_blockhash) |
| 84 | + assert_equal(len(genesis_spks), 1) |
| 85 | + genesis_coinbase_spk = list(genesis_spks)[0] |
| 86 | + false_positive_spk = bytes.fromhex("001400000000000000000000000000000000000cadcb") |
| 87 | + |
| 88 | + genesis_coinbase_hash = bip158_basic_element_hash(genesis_coinbase_spk, 1, genesis_blockhash) |
| 89 | + false_positive_hash = bip158_basic_element_hash(false_positive_spk, 1, genesis_blockhash) |
| 90 | + assert_equal(genesis_coinbase_hash, false_positive_hash) |
| 91 | + |
| 92 | + assert(genesis_blockhash in node.scanblocks( |
| 93 | + "start", [{"desc": f"raw({genesis_coinbase_spk.hex()})"}], 0, 0)['relevant_blocks']) |
| 94 | + assert(genesis_blockhash in node.scanblocks( |
| 95 | + "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0)['relevant_blocks']) |
| 96 | + |
| 97 | + # TODO: after an "accurate" mode for scanblocks is implemented (e.g. PR #26325) |
| 98 | + # check here that it filters out the false-positive |
| 99 | + |
74 | 100 | # test node with disabled blockfilterindex
|
75 | 101 | assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic",
|
76 | 102 | self.nodes[1].scanblocks, "start", [f"addr({addr_1})"])
|
|
0 commit comments