From a31a23e3dacca152ce40c1dada452b09d1491b42 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 22 Aug 2018 09:51:57 +0930 Subject: [PATCH] pytest: allow NodeFactory to create non-started peers. Useful it we want to intercept bitcoin-cli first. We move the getinfo() caching into start(), as that's when we can actually use RPC. Signed-off-by: Rusty Russell --- tests/utils.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 3e62f1923290..3a6595a51d5d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -438,8 +438,10 @@ def db_manip(self, query): def start(self): self.daemon.start() + # Cache `getinfo`, we'll be using it a lot + self.info = self.rpc.getinfo() # This shortcut is sufficient for our simple tests. - self.port = self.rpc.getinfo()['binding'][0]['port'] + self.port = self.info['binding'][0]['port'] def stop(self, timeout=10): """ Attempt to do a clean shutdown, but kill if it hangs @@ -682,7 +684,7 @@ def get_nodes(self, num_nodes, opts=None): return [j.result() for j in jobs] - def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False, feerates=(15000, 7500, 3750)): + def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False, feerates=(15000, 7500, 3750), start=True): with self.lock: node_id = self.next_id self.next_id += 1 @@ -746,14 +748,12 @@ def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect= '--log-file={}/valgrind-errors.%p'.format(node.daemon.lightning_dir) ] - try: - node.start() - except Exception: - node.daemon.stop() - raise - - # Cache `getinfo`, we'll be using it a lot - node.info = node.rpc.getinfo() + if start: + try: + node.start() + except Exception: + node.daemon.stop() + raise return node def line_graph(self, num_nodes, fundchannel=True, fundamount=10**6, announce=False, opts=None):