mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 09:40:19 +01:00
pytest: Split the python integration tests into new and legacy
This commit is contained in:
parent
5f61b3a272
commit
180c96776b
2 changed files with 44 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from utils import BitcoinD, LightningD, LightningRpc, LightningNode
|
from lightning import LightningRpc, LegacyLightningRpc
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -9,6 +9,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
import utils
|
||||||
|
|
||||||
bitcoind = None
|
bitcoind = None
|
||||||
TEST_DIR = tempfile.mkdtemp(prefix='lightning-')
|
TEST_DIR = tempfile.mkdtemp(prefix='lightning-')
|
||||||
|
@ -21,7 +22,7 @@ logging.info("Tests running in '%s'", TEST_DIR)
|
||||||
|
|
||||||
def setupBitcoind():
|
def setupBitcoind():
|
||||||
global bitcoind
|
global bitcoind
|
||||||
bitcoind = BitcoinD(rpcport=28332)
|
bitcoind = utils.BitcoinD(rpcport=28332)
|
||||||
bitcoind.start()
|
bitcoind.start()
|
||||||
info = bitcoind.rpc.getinfo()
|
info = bitcoind.rpc.getinfo()
|
||||||
# Make sure we have segwit and some funds
|
# Make sure we have segwit and some funds
|
||||||
|
@ -59,7 +60,7 @@ class NodeFactory(object):
|
||||||
self.nodes = []
|
self.nodes = []
|
||||||
self.executor = executor
|
self.executor = executor
|
||||||
|
|
||||||
def get_node(self):
|
def get_node(self, legacy=True):
|
||||||
node_id = self.next_id
|
node_id = self.next_id
|
||||||
self.next_id += 1
|
self.next_id += 1
|
||||||
|
|
||||||
|
@ -67,9 +68,15 @@ class NodeFactory(object):
|
||||||
TEST_DIR, self.func._testMethodName, "lightning-{}/".format(node_id))
|
TEST_DIR, self.func._testMethodName, "lightning-{}/".format(node_id))
|
||||||
|
|
||||||
socket_path = os.path.join(lightning_dir, "lightning-rpc").format(node_id)
|
socket_path = os.path.join(lightning_dir, "lightning-rpc").format(node_id)
|
||||||
daemon = LightningD(lightning_dir, bitcoind.bitcoin_dir, port=16330+node_id)
|
port = 16330+node_id
|
||||||
rpc = LightningRpc(socket_path, self.executor)
|
if legacy:
|
||||||
node = LightningNode(daemon, rpc, bitcoind, self.executor)
|
daemon = utils.LegacyLightningD(lightning_dir, bitcoind.bitcoin_dir, port=port)
|
||||||
|
rpc = LegacyLightningRpc(socket_path, self.executor)
|
||||||
|
else:
|
||||||
|
daemon = utils.LightningD(lightning_dir, bitcoind.bitcoin_dir, port=port)
|
||||||
|
rpc = LightningRpc(socket_path, self.executor)
|
||||||
|
|
||||||
|
node = utils.LightningNode(daemon, rpc, bitcoind, self.executor)
|
||||||
self.nodes.append(node)
|
self.nodes.append(node)
|
||||||
if VALGRIND:
|
if VALGRIND:
|
||||||
node.daemon.cmd_line = [
|
node.daemon.cmd_line = [
|
||||||
|
@ -80,7 +87,6 @@ class NodeFactory(object):
|
||||||
] + node.daemon.cmd_line
|
] + node.daemon.cmd_line
|
||||||
|
|
||||||
node.daemon.start()
|
node.daemon.start()
|
||||||
node.rpc.connect_rpc()
|
|
||||||
# Cache `getinfo`, we'll be using it a lot
|
# Cache `getinfo`, we'll be using it a lot
|
||||||
node.info = node.rpc.getinfo()
|
node.info = node.rpc.getinfo()
|
||||||
return node
|
return node
|
||||||
|
@ -90,8 +96,7 @@ class NodeFactory(object):
|
||||||
n.daemon.stop()
|
n.daemon.stop()
|
||||||
|
|
||||||
|
|
||||||
class LightningDTests(unittest.TestCase):
|
class BaseLightningDTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Most of the executor threads will be waiting for IO, so
|
# Most of the executor threads will be waiting for IO, so
|
||||||
# let's have a few of them
|
# let's have a few of them
|
||||||
|
@ -103,6 +108,23 @@ class LightningDTests(unittest.TestCase):
|
||||||
self.executor.shutdown(wait=False)
|
self.executor.shutdown(wait=False)
|
||||||
# TODO(cdecker) Check that valgrind didn't find any errors
|
# TODO(cdecker) Check that valgrind didn't find any errors
|
||||||
|
|
||||||
|
|
||||||
|
class LightningDTests(BaseLightningDTests):
|
||||||
|
def test_connect(self):
|
||||||
|
l1 = self.node_factory.get_node(legacy=False)
|
||||||
|
l2 = self.node_factory.get_node(legacy=False)
|
||||||
|
ret = l1.rpc.connect('localhost', l2.info['port'], l2.info['id'])
|
||||||
|
|
||||||
|
assert ret['id'] == l2.info['id']
|
||||||
|
|
||||||
|
p1 = l1.rpc.getpeer(l2.info['id'])
|
||||||
|
p2 = l2.rpc.getpeer(l1.info['id'])
|
||||||
|
|
||||||
|
assert p1['condition'] == 'Exchanging gossip'
|
||||||
|
assert p2['condition'] == 'Exchanging gossip'
|
||||||
|
|
||||||
|
class LegacyLightningDTests(BaseLightningDTests):
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
l1 = self.node_factory.get_node()
|
l1 = self.node_factory.get_node()
|
||||||
l2 = self.node_factory.get_node()
|
l2 = self.node_factory.get_node()
|
||||||
|
|
|
@ -160,7 +160,7 @@ class LightningD(TailableProc):
|
||||||
self.lightning_dir = lightning_dir
|
self.lightning_dir = lightning_dir
|
||||||
self.port = port
|
self.port = port
|
||||||
self.cmd_line = [
|
self.cmd_line = [
|
||||||
'daemon/lightningd',
|
'lightningd/lightningd',
|
||||||
'--bitcoin-datadir={}'.format(bitcoin_dir),
|
'--bitcoin-datadir={}'.format(bitcoin_dir),
|
||||||
'--lightning-dir={}'.format(lightning_dir),
|
'--lightning-dir={}'.format(lightning_dir),
|
||||||
'--port={}'.format(port),
|
'--port={}'.format(port),
|
||||||
|
@ -176,13 +176,24 @@ class LightningD(TailableProc):
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
TailableProc.start(self)
|
TailableProc.start(self)
|
||||||
self.wait_for_log("Hello world!")
|
self.wait_for_log("Creating IPv6 listener on port")
|
||||||
logging.info("LightningD started")
|
logging.info("LightningD started")
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
TailableProc.stop(self)
|
TailableProc.stop(self)
|
||||||
logging.info("LightningD stopped")
|
logging.info("LightningD stopped")
|
||||||
|
|
||||||
|
class LegacyLightningD(LightningD):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
LightningD.__init__(self, *args, **kwargs)
|
||||||
|
self.cmd_line[0] = 'daemon/lightningd'
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
TailableProc.start(self)
|
||||||
|
self.wait_for_log("Hello world!")
|
||||||
|
logging.info("LightningD started")
|
||||||
|
|
||||||
|
|
||||||
class LightningNode(object):
|
class LightningNode(object):
|
||||||
def __init__(self, daemon, rpc, btc, executor):
|
def __init__(self, daemon, rpc, btc, executor):
|
||||||
self.rpc = rpc
|
self.rpc = rpc
|
||||||
|
|
Loading…
Add table
Reference in a new issue