aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFabian Jahr <fjahr@protonmail.com>2019-08-26 15:49:57 -0400
committerFabian Jahr <fjahr@protonmail.com>2021-04-19 20:31:01 +0200
commit6a4c0c09ab4d073a26c3c4a02783d5dcd88f6eef (patch)
tree365467131a1359f26984e093fbbcbc87e117d0b5 /test
parent3f166ecc125fce6ccd995687fa16572090a5d099 (diff)
downloadbitcoin-6a4c0c09ab4d073a26c3c4a02783d5dcd88f6eef.tar.xz
test: Add functional test for Coinstats index
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_coinstatsindex.py85
-rwxr-xr-xtest/functional/test_framework/test_framework.py2
-rwxr-xr-xtest/functional/test_runner.py1
3 files changed, 87 insertions, 1 deletions
diff --git a/test/functional/feature_coinstatsindex.py b/test/functional/feature_coinstatsindex.py
new file mode 100755
index 0000000000..9ff3a58510
--- /dev/null
+++ b/test/functional/feature_coinstatsindex.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+# Copyright (c) 2020 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Test coinstatsindex across nodes.
+
+Test that the values returned by gettxoutsetinfo are consistent
+between a node running the coinstatsindex and a node without
+the index.
+"""
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal,
+ assert_raises_rpc_error,
+ try_rpc,
+)
+
+class CoinStatsIndexTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ self.num_nodes = 2
+ self.supports_cli = False
+ self.extra_args = [
+ [],
+ ["-coinstatsindex"]
+ ]
+
+ def skip_test_if_missing_module(self):
+ self.skip_if_no_wallet()
+
+ def run_test(self):
+ self._test_coin_stats_index()
+
+ def _test_coin_stats_index(self):
+ node = self.nodes[0]
+ index_node = self.nodes[1]
+ # Both none and muhash options allow the usage of the index
+ index_hash_options = ['none', 'muhash']
+
+ # Generate a normal transaction and mine it
+ node.generate(101)
+ address = self.nodes[0].get_deterministic_priv_key().address
+ node.sendtoaddress(address=address, amount=10, subtractfeefromamount=True)
+ node.generate(1)
+
+ self.sync_blocks(timeout=120)
+
+ self.log.info("Test that gettxoutsetinfo() output is consistent with or without coinstatsindex option")
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", node.gettxoutsetinfo))
+ res0 = node.gettxoutsetinfo('none')
+
+ # The fields 'disk_size' and 'transactions' do not exist on the index
+ del res0['disk_size'], res0['transactions']
+
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ for hash_option in index_hash_options:
+ res1 = index_node.gettxoutsetinfo(hash_option)
+ res1.pop('muhash', None)
+
+ # Everything left should be the same
+ assert_equal(res1, res0)
+
+ self.log.info("Test that gettxoutsetinfo() can get fetch data on specific heights with index")
+
+ # Generate a new tip
+ node.generate(5)
+
+ self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", index_node.gettxoutsetinfo, 'muhash'))
+ for hash_option in index_hash_options:
+ # Fetch old stats by height
+ res2 = index_node.gettxoutsetinfo(hash_option, 102)
+ res2.pop('muhash', None)
+ assert_equal(res0, res2)
+
+ # Fetch old stats by hash
+ res3 = index_node.gettxoutsetinfo(hash_option, res0['bestblock'])
+ res3.pop('muhash', None)
+ assert_equal(res0, res3)
+
+ # It does not work without coinstatsindex
+ assert_raises_rpc_error(-8, "Querying specific block heights requires coinstatsindex", node.gettxoutsetinfo, hash_option, 102)
+
+if __name__ == '__main__':
+ CoinStatsIndexTest().main()
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 02eb10b5a4..5c10cc3687 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -757,7 +757,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
os.rmdir(cache_path('wallets')) # Remove empty wallets dir
for entry in os.listdir(cache_path()):
- if entry not in ['chainstate', 'blocks']: # Only keep chainstate and blocks folder
+ if entry not in ['chainstate', 'blocks', 'indexes']: # Only indexes, chainstate and blocks folders
os.remove(cache_path(entry))
for i in range(self.num_nodes):
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index bd58f2cd51..00527e78f1 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -281,6 +281,7 @@ BASE_SCRIPTS = [
'rpc_scantxoutset.py',
'feature_logging.py',
'feature_anchors.py',
+ 'feature_coinstatsindex.py',
'p2p_node_network_limited.py',
'p2p_permissions.py',
'feature_blocksdir.py',