Skip to content

Commit ff9a363

Browse files
ryanofskyjnewbery
authored andcommitted
TestNodeCLI batch emulation
Support same get_request and batch methods as AuthServiceProxy
1 parent ca9085a commit ff9a363

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/functional/test_framework/test_node.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ def disconnect_p2ps(self):
191191
p.peer_disconnect()
192192
del self.p2ps[:]
193193

194+
class TestNodeCLIAttr:
195+
def __init__(self, cli, command):
196+
self.cli = cli
197+
self.command = command
198+
199+
def __call__(self, *args, **kwargs):
200+
return self.cli.send_cli(self.command, *args, **kwargs)
201+
202+
def get_request(self, *args, **kwargs):
203+
return lambda: self(*args, **kwargs)
194204

195205
class TestNodeCLI():
196206
"""Interface to bitcoin-cli for an individual node"""
@@ -209,9 +219,16 @@ def __call__(self, *args, input=None):
209219
return cli
210220

211221
def __getattr__(self, command):
212-
def dispatcher(*args, **kwargs):
213-
return self.send_cli(command, *args, **kwargs)
214-
return dispatcher
222+
return TestNodeCLIAttr(self, command)
223+
224+
def batch(self, requests):
225+
results = []
226+
for request in requests:
227+
try:
228+
results.append(dict(result=request()))
229+
except JSONRPCException as e:
230+
results.append(dict(error=e))
231+
return results
215232

216233
def send_cli(self, command, *args, **kwargs):
217234
"""Run bitcoin-cli command. Deserializes returned string as python object."""

0 commit comments

Comments
 (0)