mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
07dcddb4ca
* Merge #9815: Trivial: use EXIT_ codes instead of magic numbersa87d02a
use EXIT_ codes instead of magic numbers (Marko Bencun) * Merge #9801: Removed redundant parameter from mempool.PrioritiseTransactioneaea2bb
Removed redundant parameter from mempool.PrioritiseTransaction (gubatron) * remove extra parameter (see 3a3745bb) in dash specific code * Merge #9819: Remove harmless read of unusued priority estimatesbc8fd12
Remove harmless read of unusued priority estimates (Alex Morcos) * Merge #9766: Add --exclude option to rpc-tests.pyc578408
Add exclude option to rpc-tests.py (John Newbery) * Merge #9577: Fix docstrings in qa tests3f95a80
Fix docstrings in qa tests (John Newbery) * Merge #9823: qa: Set correct path for binaries in rpc tests3333ad0
qa: Set correct path for binaries in rpc tests (MarcoFalke) * Merge #9833: Trivial: fix comments referencing AppInit2ef9f495
Trivial: fix comments referencing AppInit2 (Marko Bencun) * Merge #9612: [trivial] Rephrase the definition of difficulty.dc222f8
Trivial: Rephrase the definition of difficulty in the code. (Karl-Johan Alm) * Merge #9847: Extra test vector for BIP3230aedcb
BIP32 extra test vector (Pieter Wuille) * Merge #9839: [qa] Make import-rescan.py watchonly check reliable864890a
[qa] Make import-rescan.py watchonly check reliable (Russell Yanofsky) Tree-SHA512: ea0e2b1d4fc8f35174c3d575fb751b428daf6ad3aa944fad4e3ddcc9195e4f17051473acabc54203b1d27cca64cf911b737ab92e986c40ef384410652e2dbea1 * Change back file params
104 lines
2.9 KiB
Python
104 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) 2015-2016 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Utilities for doing coverage analysis on the RPC interface.
|
|
|
|
Provides a way to track which RPC commands are exercised during
|
|
testing.
|
|
"""
|
|
|
|
import os
|
|
|
|
|
|
REFERENCE_FILENAME = 'rpc_interface.txt'
|
|
|
|
|
|
class AuthServiceProxyWrapper(object):
|
|
"""
|
|
An object that wraps AuthServiceProxy to record specific RPC calls.
|
|
|
|
"""
|
|
def __init__(self, auth_service_proxy_instance, coverage_logfile=None):
|
|
"""
|
|
Kwargs:
|
|
auth_service_proxy_instance (AuthServiceProxy): the instance
|
|
being wrapped.
|
|
coverage_logfile (str): if specified, write each service_name
|
|
out to a file when called.
|
|
|
|
"""
|
|
self.auth_service_proxy_instance = auth_service_proxy_instance
|
|
self.coverage_logfile = coverage_logfile
|
|
|
|
def __getattr__(self, *args, **kwargs):
|
|
return_val = self.auth_service_proxy_instance.__getattr__(
|
|
*args, **kwargs)
|
|
|
|
return AuthServiceProxyWrapper(return_val, self.coverage_logfile)
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
"""
|
|
Delegates to AuthServiceProxy, then writes the particular RPC method
|
|
called to a file.
|
|
|
|
"""
|
|
return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
|
|
rpc_method = self.auth_service_proxy_instance._service_name
|
|
|
|
if self.coverage_logfile:
|
|
with open(self.coverage_logfile, 'a+', encoding='utf8') as f:
|
|
f.write("%s\n" % rpc_method)
|
|
|
|
return return_val
|
|
|
|
@property
|
|
def url(self):
|
|
return self.auth_service_proxy_instance.url
|
|
|
|
|
|
def get_filename(dirname, n_node):
|
|
"""
|
|
Get a filename unique to the test process ID and node.
|
|
|
|
This file will contain a list of RPC commands covered.
|
|
"""
|
|
pid = str(os.getpid())
|
|
return os.path.join(
|
|
dirname, "coverage.pid%s.node%s.txt" % (pid, str(n_node)))
|
|
|
|
|
|
def write_all_rpc_commands(dirname, node):
|
|
"""
|
|
Write out a list of all RPC functions available in `bitcoin-cli` for
|
|
coverage comparison. This will only happen once per coverage
|
|
directory.
|
|
|
|
Args:
|
|
dirname (str): temporary test dir
|
|
node (AuthServiceProxy): client
|
|
|
|
Returns:
|
|
bool. if the RPC interface file was written.
|
|
|
|
"""
|
|
filename = os.path.join(dirname, REFERENCE_FILENAME)
|
|
|
|
if os.path.isfile(filename):
|
|
return False
|
|
|
|
help_output = node.help().split('\n')
|
|
commands = set()
|
|
|
|
for line in help_output:
|
|
line = line.strip()
|
|
|
|
# Ignore blanks and headers
|
|
if line and not line.startswith('='):
|
|
commands.add("%s\n" % line.split()[0])
|
|
|
|
with open(filename, 'w', encoding='utf8') as f:
|
|
f.writelines(list(commands))
|
|
|
|
return True
|