Skip to content

Commit

Permalink
pytest: allow NodeFactory to create non-started peers.
Browse files Browse the repository at this point in the history
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 <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Aug 22, 2018
1 parent 7399716 commit a31a23e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a31a23e

Please sign in to comment.