pytest: add support for starting nodes with a pre-canned db.

With xz, the db is only 9120 bytes, vs 163840.  And lzma is a builtin
in Python 3.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-02-21 11:52:56 +10:30 committed by Christian Decker
parent 3b587a1c6d
commit 7887e5c00a
1 changed files with 8 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from lightning import LightningRpc
import json
import logging
import lzma
import os
import random
import re
@ -753,7 +754,8 @@ class NodeFactory(object):
def get_node(self, disconnect=None, options=None, may_fail=False,
may_reconnect=False, random_hsm=False,
feerates=(15000, 7500, 3750), start=True, log_all_io=False):
feerates=(15000, 7500, 3750), start=True, log_all_io=False,
dbfile=None):
with self.lock:
node_id = self.next_id
self.next_id += 1
@ -812,6 +814,11 @@ class NodeFactory(object):
'--log-file={}/valgrind-errors.%p'.format(node.daemon.lightning_dir)
]
if dbfile:
out = open(os.path.join(node.daemon.lightning_dir, 'lightningd.sqlite3'), 'xb')
with lzma.open(os.path.join('tests/data', dbfile), 'rb') as f:
out.write(f.read())
if start:
try:
node.start()