mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
4c8e77a48d
d841301010914203fb5ef02627c76fad99cb11f1 test: Add docstring to wait_until() in util.py to warn about its usage (Seleme Topuz) 1343c86c7cc1fc896696b3ed87c12039e4ef3a0c test: Update wait_until usage in tests not to use the one from utils (Seleme Topuz) Pull request description: Replace global (from [test_framework/util.py](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/util.py#L228)) `wait_until()` usages with the ones provided by `BitcoinTestFramework` and `P2PInterface` classes. The motivation behind this change is that the `util.wait_until()` expects a timeout, timeout_factor and lock and it is not aware of the context of the test framework. `BitcoinTestFramework` offers a `wait_until()` which has an understandable amount of default `timeout` and a shared `timeout_factor`. Moreover, on top of these, `mininode.wait_until()` also has a shared lock. closes #19080 ACKs for top commit: MarcoFalke: ACK d841301010914203fb5ef02627c76fad99cb11f1 🦆 kallewoof: utACK d841301010914203fb5ef02627c76fad99cb11f1 Tree-SHA512: 81604f4cfa87fed98071a80e4afe940b3897fe65cf680a69619a93e97d45f25b313c12227de7040e19517fa9c003291b232f1b40b2567aba0148f22c23c47a88
107 lines
4.1 KiB
Python
Executable File
107 lines
4.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2019 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 RPC misc output."""
|
|
import xml.etree.ElementTree as ET
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (
|
|
assert_raises_rpc_error,
|
|
assert_equal,
|
|
assert_greater_than,
|
|
assert_greater_than_or_equal,
|
|
)
|
|
|
|
from test_framework.authproxy import JSONRPCException
|
|
|
|
|
|
class RpcMiscTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 1
|
|
self.supports_cli = False
|
|
|
|
def run_test(self):
|
|
node = self.nodes[0]
|
|
|
|
self.log.info("test CHECK_NONFATAL")
|
|
assert_raises_rpc_error(
|
|
-1,
|
|
"Internal bug detected: 'request.params.size() != 100'",
|
|
lambda: node.echo(*[0] * 100),
|
|
)
|
|
|
|
self.log.info("test getmemoryinfo")
|
|
memory = node.getmemoryinfo()['locked']
|
|
assert_greater_than(memory['used'], 0)
|
|
assert_greater_than(memory['free'], 0)
|
|
assert_greater_than(memory['total'], 0)
|
|
# assert_greater_than_or_equal() for locked in case locking pages failed at some point
|
|
assert_greater_than_or_equal(memory['locked'], 0)
|
|
assert_greater_than(memory['chunks_used'], 0)
|
|
assert_greater_than(memory['chunks_free'], 0)
|
|
assert_equal(memory['used'] + memory['free'], memory['total'])
|
|
|
|
self.log.info("test mallocinfo")
|
|
try:
|
|
mallocinfo = node.getmemoryinfo(mode="mallocinfo")
|
|
self.log.info('getmemoryinfo(mode="mallocinfo") call succeeded')
|
|
tree = ET.fromstring(mallocinfo)
|
|
assert_equal(tree.tag, 'malloc')
|
|
except JSONRPCException:
|
|
self.log.info('getmemoryinfo(mode="mallocinfo") not available')
|
|
assert_raises_rpc_error(-8, 'mallocinfo mode not available', node.getmemoryinfo, mode="mallocinfo")
|
|
|
|
assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar")
|
|
|
|
self.log.info("test logging rpc and help")
|
|
|
|
# Test logging RPC returns the expected number of logging categories.
|
|
assert_equal(len(node.logging()), 36)
|
|
|
|
# Test toggling a logging category on/off/on with the logging RPC.
|
|
assert_equal(node.logging()['qt'], True)
|
|
node.logging(exclude=['qt'])
|
|
assert_equal(node.logging()['qt'], False)
|
|
node.logging(include=['qt'])
|
|
assert_equal(node.logging()['qt'], True)
|
|
|
|
# Test logging RPC returns the logging categories in alphabetical order.
|
|
sorted_logging_categories = sorted(node.logging())
|
|
assert_equal(list(node.logging()), sorted_logging_categories)
|
|
|
|
# Test logging help returns the logging categories string in alphabetical order.
|
|
categories = ', '.join(sorted_logging_categories)
|
|
logging_help = self.nodes[0].help('logging')
|
|
assert f"valid logging categories are: {categories}" in logging_help
|
|
|
|
self.log.info("test getindexinfo")
|
|
self.restart_node(0, ["-txindex=0"])
|
|
# Without any indices running the RPC returns an empty object
|
|
assert_equal(node.getindexinfo(), {})
|
|
|
|
# Restart the node with indices and wait for them to sync
|
|
self.restart_node(0, ["-txindex", "-blockfilterindex", "-coinstatsindex"])
|
|
self.wait_until(lambda: all(i["synced"] for i in node.getindexinfo().values()))
|
|
|
|
# Returns a list of all running indices by default
|
|
values = {"synced": True, "best_block_height": 200}
|
|
assert_equal(
|
|
node.getindexinfo(),
|
|
{
|
|
"txindex": values,
|
|
"basic block filter index": values,
|
|
"coinstatsindex": values,
|
|
}
|
|
)
|
|
# Specifying an index by name returns only the status of that index
|
|
for i in {"txindex", "basic block filter index", "coinstatsindex"}:
|
|
assert_equal(node.getindexinfo(i), {i: values})
|
|
|
|
# Specifying an unknown index name returns an empty result
|
|
assert_equal(node.getindexinfo("foo"), {})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
RpcMiscTest().main()
|