Skip to content

Commit 0845e19

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#22139: test: add type annotations to util.get_rpc_proxy
fbeb8c4 test: add type annotations to util.get_rpc_proxy (fanquake) Pull request description: Split out from bitcoin#22092 while we address the functional test failure. ACKs for top commit: instagibbs: ACK bitcoin@fbeb8c4 Tree-SHA512: 031ef8703202ae5271787719fc3fea8693574b2eb937ccf852875de95798d7fa3c39a8db7c91993d0c946b45d9b4d6de570bd1102e0344348784723bd84803a8
1 parent 693abb2 commit 0845e19

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

test/functional/test_framework/coverage.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import os
1212

13+
from .authproxy import AuthServiceProxy
1314

1415
REFERENCE_FILENAME = 'rpc_interface.txt'
1516

@@ -19,24 +20,25 @@ class AuthServiceProxyWrapper():
1920
An object that wraps AuthServiceProxy to record specific RPC calls.
2021
2122
"""
22-
def __init__(self, auth_service_proxy_instance, coverage_logfile=None):
23+
def __init__(self, auth_service_proxy_instance: AuthServiceProxy, rpc_url: str, coverage_logfile: str=None):
2324
"""
2425
Kwargs:
25-
auth_service_proxy_instance (AuthServiceProxy): the instance
26-
being wrapped.
27-
coverage_logfile (str): if specified, write each service_name
26+
auth_service_proxy_instance: the instance being wrapped.
27+
rpc_url: url of the RPC instance being wrapped
28+
coverage_logfile: if specified, write each service_name
2829
out to a file when called.
2930
3031
"""
3132
self.auth_service_proxy_instance = auth_service_proxy_instance
33+
self.rpc_url = rpc_url
3234
self.coverage_logfile = coverage_logfile
3335

3436
def __getattr__(self, name):
3537
return_val = getattr(self.auth_service_proxy_instance, name)
3638
if not isinstance(return_val, type(self.auth_service_proxy_instance)):
3739
# If proxy getattr returned an unwrapped value, do the same here.
3840
return return_val
39-
return AuthServiceProxyWrapper(return_val, self.coverage_logfile)
41+
return AuthServiceProxyWrapper(return_val, self.rpc_url, self.coverage_logfile)
4042

4143
def __call__(self, *args, **kwargs):
4244
"""
@@ -57,6 +59,7 @@ def _log_call(self):
5759

5860
def __truediv__(self, relative_uri):
5961
return AuthServiceProxyWrapper(self.auth_service_proxy_instance / relative_uri,
62+
self.rpc_url,
6063
self.coverage_logfile)
6164

6265
def get_request(self, *args, **kwargs):
@@ -74,18 +77,18 @@ def get_filename(dirname, n_node):
7477
dirname, "coverage.pid%s.node%s.txt" % (pid, str(n_node)))
7578

7679

77-
def write_all_rpc_commands(dirname, node):
80+
def write_all_rpc_commands(dirname: str, node: AuthServiceProxy) -> bool:
7881
"""
7982
Write out a list of all RPC functions available in `dash-cli` for
8083
coverage comparison. This will only happen once per coverage
8184
directory.
8285
8386
Args:
84-
dirname (str): temporary test dir
85-
node (AuthServiceProxy): client
87+
dirname: temporary test dir
88+
node: client
8689
8790
Returns:
88-
bool. if the RPC interface file was written.
91+
if the RPC interface file was written.
8992
9093
"""
9194
filename = os.path.join(dirname, REFERENCE_FILENAME)

test/functional/test_framework/test_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def wait_for_rpc_connection(self):
271271
return
272272
self.rpc = rpc
273273
self.rpc_connected = True
274-
self.url = self.rpc.url
274+
self.url = self.rpc.rpc_url
275275
return
276276
except JSONRPCException as e: # Initialization phase
277277
# -28 RPC in warmup

test/functional/test_framework/util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,16 @@ class PortSeed:
260260
# Must be initialized with a unique integer for each process
261261
n = None
262262

263-
def get_rpc_proxy(url, node_number, *, timeout=None, coveragedir=None):
263+
264+
def get_rpc_proxy(url: str, node_number: int, *, timeout: int=None, coveragedir: str=None) -> coverage.AuthServiceProxyWrapper:
264265
"""
265266
Args:
266-
url (str): URL of the RPC server to call
267-
node_number (int): the node number (or id) that this calls to
267+
url: URL of the RPC server to call
268+
node_number: the node number (or id) that this calls to
268269
269270
Kwargs:
270-
timeout (int): HTTP timeout in seconds
271-
coveragedir (str): Directory
271+
timeout: HTTP timeout in seconds
272+
coveragedir: Directory
272273
273274
Returns:
274275
AuthServiceProxy. convenience object for making RPC calls.
@@ -279,12 +280,11 @@ def get_rpc_proxy(url, node_number, *, timeout=None, coveragedir=None):
279280
proxy_kwargs['timeout'] = int(timeout)
280281

281282
proxy = AuthServiceProxy(url, **proxy_kwargs)
282-
proxy.url = url # store URL on proxy for info
283283

284284
coverage_logfile = coverage.get_filename(
285285
coveragedir, node_number) if coveragedir else None
286286

287-
return coverage.AuthServiceProxyWrapper(proxy, coverage_logfile)
287+
return coverage.AuthServiceProxyWrapper(proxy, url, coverage_logfile)
288288

289289
def p2p_port(n):
290290
assert n <= MAX_NODES

0 commit comments

Comments
 (0)