Skip to content

Commit

Permalink
sauron: make tests more robust
Browse files Browse the repository at this point in the history
cln-grpc was dying and taking the rest of lightningd with it
(because it's important) because it was trying to listen on port
9736 in multiple tests simlutaneously. this PR allows the sauron
tests to take advantage of the new plyn-testing feature that
assigns the grpc plugin a random unused port by default. sauron's
tests were previously overriding these values in its override
fixtures, and this PR corrects that. there is still some brittle-
ness around the `TEST_NETWORK` global variable, but setting it
in the override `LightningNode` fixture at the top of each test,
immediately before the call to init the superclass, appears to
make the tests pass, so we'll leave it like this for now.
  • Loading branch information
chrisguida committed Feb 7, 2025
1 parent 6470b8b commit 6389efa
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 65 deletions.
2 changes: 1 addition & 1 deletion sauron/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyln-client>=23.2,<=24.5
pyln-client>=23.2
requests[socks]>=2.23.0
30 changes: 19 additions & 11 deletions sauron/tests/test_sauron_esplora_bitcoin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python

import os

import pyln
import pytest
from pyln.testing import utils
Expand All @@ -10,20 +9,29 @@

pyln.testing.fixtures.network_daemons["bitcoin"] = utils.BitcoinD


class LightningNode(utils.LightningNode):
def __init__(self, *args, **kwargs):
pyln.testing.utils.TEST_NETWORK = "bitcoin"
utils.LightningNode.__init__(self, *args, **kwargs)
lightning_dir = args[1]
self.daemon = LightningD(lightning_dir, None, port=self.daemon.port) # noqa: F405
options = {
"disable-plugin": "bcli",
old_opts = self.daemon.opts
self.daemon = LightningD(lightning_dir, None) # noqa: F405
new_opts = {
"disable-plugin": ["bcli"],
"network": "bitcoin",
"plugin": os.path.join(os.path.dirname(__file__), "../sauron.py"),
"sauron-api-endpoint": "https://blockstream.info/api",
}
self.daemon.opts.update(options)
self.daemon.opts.update(old_opts)
self.daemon.opts.update(new_opts)
opts_to_disable = [
"bitcoin-datadir",
"bitcoin-rpcpassword",
"bitcoin-rpcuser",
"dev-bitcoind-poll",
]
for opt in opts_to_disable:
self.daemon.opts.pop(opt)

# Monkey patch
def set_feerates(self, feerates, wait_for_effect=True):
Expand All @@ -36,7 +44,7 @@ def node_cls(monkeypatch):
yield LightningNode


def test_rpc_getchaininfo(node_factory):
def test_esplora_bitcoin_getchaininfo(node_factory):
"""
Test getchaininfo
"""
Expand All @@ -52,7 +60,7 @@ def test_rpc_getchaininfo(node_factory):
assert not response["ibd"]


def test_rpc_getrawblockbyheight(node_factory):
def test_esplora_bitcoin_getrawblockbyheight(node_factory):
"""
Test getrawblockbyheight
"""
Expand All @@ -67,7 +75,7 @@ def test_rpc_getrawblockbyheight(node_factory):
assert response == expected_response

@pytest.mark.skip(reason="testing_theory")
def test_rpc_sendrawtransaction_invalid(node_factory):
def test_esplora_bitcoin_sendrawtransaction_invalid(node_factory):
"""
Test sendrawtransaction
"""
Expand All @@ -85,7 +93,7 @@ def test_rpc_sendrawtransaction_invalid(node_factory):
assert response == expected_response


def test_rpc_getutxout(node_factory):
def test_esplora_bitcoin_getutxout(node_factory):
"""
Test getutxout
"""
Expand All @@ -106,7 +114,7 @@ def test_rpc_getutxout(node_factory):
assert response == expected_response


def test_rpc_estimatefees(node_factory):
def test_esplora_bitcoin_estimatefees(node_factory):
"""
Test estimatefees
"""
Expand Down
30 changes: 19 additions & 11 deletions sauron/tests/test_sauron_esplora_signet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python

import os

import pyln
import pytest
from pyln.testing import utils
Expand All @@ -10,20 +9,29 @@

pyln.testing.fixtures.network_daemons["signet"] = utils.BitcoinD


class LightningNode(utils.LightningNode):
def __init__(self, *args, **kwargs):
pyln.testing.utils.TEST_NETWORK = "signet"
utils.LightningNode.__init__(self, *args, **kwargs)
lightning_dir = args[1]
self.daemon = LightningD(lightning_dir, None, port=self.daemon.port) # noqa: F405
options = {
"disable-plugin": "bcli",
old_opts = self.daemon.opts
self.daemon = LightningD(lightning_dir, None) # noqa: F405
new_opts = {
"disable-plugin": ["bcli"],
"network": "signet",
"plugin": os.path.join(os.path.dirname(__file__), "../sauron.py"),
"sauron-api-endpoint": "https://blockstream.info/signet/api",
}
self.daemon.opts.update(options)
self.daemon.opts.update(old_opts)
self.daemon.opts.update(new_opts)
opts_to_disable = [
"bitcoin-datadir",
"bitcoin-rpcpassword",
"bitcoin-rpcuser",
"dev-bitcoind-poll",
]
for opt in opts_to_disable:
self.daemon.opts.pop(opt)

# Monkey patch
def set_feerates(self, feerates, wait_for_effect=True):
Expand All @@ -36,7 +44,7 @@ def node_cls(monkeypatch):
yield LightningNode


def test_rpc_getchaininfo(node_factory):
def test_esplora_signet_getchaininfo(node_factory):
"""
Test getchaininfo
"""
Expand All @@ -52,7 +60,7 @@ def test_rpc_getchaininfo(node_factory):
assert not response["ibd"]


def test_rpc_getrawblockbyheight(node_factory):
def test_esplora_signet_getrawblockbyheight(node_factory):
"""
Test getrawblockbyheight
"""
Expand All @@ -67,7 +75,7 @@ def test_rpc_getrawblockbyheight(node_factory):
assert response == expected_response

@pytest.mark.skip(reason="testing_theory")
def test_rpc_sendrawtransaction_invalid(node_factory):
def test_esplora_signet_sendrawtransaction_invalid(node_factory):
"""
Test sendrawtransaction
"""
Expand All @@ -84,7 +92,7 @@ def test_rpc_sendrawtransaction_invalid(node_factory):
assert response.get("success") is False, "Expected success to be False"


def test_rpc_getutxout(node_factory):
def test_esplora_signet_getutxout(node_factory):
"""
Test getutxout
"""
Expand All @@ -105,7 +113,7 @@ def test_rpc_getutxout(node_factory):
assert response == expected_response


def test_rpc_estimatefees(node_factory):
def test_esplora_signet_estimatefees(node_factory):
"""
Test estimatefees
"""
Expand Down
31 changes: 19 additions & 12 deletions sauron/tests/test_sauron_esplora_testnet.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
#!/usr/bin/python

import os

import pyln
import pytest
from pyln.testing import utils
from pyln.testing.fixtures import * # noqa: F403
from util import LightningD

pyln.testing.fixtures.network_daemons["testnet"] = utils.BitcoinD


class LightningNode(utils.LightningNode):
def __init__(self, *args, **kwargs):
pyln.testing.utils.TEST_NETWORK = "testnet"
utils.LightningNode.__init__(self, *args, **kwargs)
lightning_dir = args[1]
self.daemon = LightningD(lightning_dir, None, port=self.daemon.port) # noqa: F405
options = {
"disable-plugin": "bcli",
old_opts = self.daemon.opts
self.daemon = LightningD(lightning_dir, None) # noqa: F405
new_opts = {
"disable-plugin": ["bcli"],
"network": "testnet",
"plugin": os.path.join(os.path.dirname(__file__), "../sauron.py"),
"sauron-api-endpoint": "https://blockstream.info/testnet/api",
}
self.daemon.opts.update(options)
self.daemon.opts.update(old_opts)
self.daemon.opts.update(new_opts)
opts_to_disable = [
"bitcoin-datadir",
"bitcoin-rpcpassword",
"bitcoin-rpcuser",
"dev-bitcoind-poll",
]
for opt in opts_to_disable:
self.daemon.opts.pop(opt)

# Monkey patch
def set_feerates(self, feerates, wait_for_effect=True):
Expand All @@ -36,7 +43,7 @@ def node_cls(monkeypatch):
yield LightningNode


def test_rpc_getchaininfo(node_factory):
def test_esplora_testnet_getchaininfo(node_factory):
"""
Test getchaininfo
"""
Expand All @@ -52,7 +59,7 @@ def test_rpc_getchaininfo(node_factory):
assert not response["ibd"]


def test_rpc_getrawblockbyheight(node_factory):
def test_esplora_testnet_getrawblockbyheight(node_factory):
"""
Test getrawblockbyheight
"""
Expand All @@ -67,7 +74,7 @@ def test_rpc_getrawblockbyheight(node_factory):
assert response == expected_response

@pytest.mark.skip(reason="testing_theory")
def test_rpc_sendrawtransaction_invalid(node_factory):
def test_esplora_testnet_sendrawtransaction_invalid(node_factory):
"""
Test sendrawtransaction
"""
Expand All @@ -84,7 +91,7 @@ def test_rpc_sendrawtransaction_invalid(node_factory):
assert response.get("success") is False, "Expected success to be False"


def test_rpc_getutxout(node_factory):
def test_esplora_testnet_getutxout(node_factory):
"""
Test getutxout
"""
Expand All @@ -105,7 +112,7 @@ def test_rpc_getutxout(node_factory):
assert response == expected_response


def test_rpc_estimatefees(node_factory):
def test_esplora_testnet_estimatefees(node_factory):
"""
Test estimatefees
"""
Expand Down
20 changes: 14 additions & 6 deletions sauron/tests/test_sauron_esplora_tor_proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python

import os

import pyln
import pytest
from pyln.testing import utils
Expand All @@ -10,21 +9,30 @@

pyln.testing.fixtures.network_daemons["bitcoin"] = utils.BitcoinD


class LightningNode(utils.LightningNode):
def __init__(self, *args, **kwargs):
pyln.testing.utils.TEST_NETWORK = "bitcoin"
utils.LightningNode.__init__(self, *args, **kwargs)
lightning_dir = args[1]
self.daemon = LightningD(lightning_dir, None, port=self.daemon.port) # noqa: F405
options = {
"disable-plugin": "bcli",
old_opts = self.daemon.opts
self.daemon = LightningD(lightning_dir, None) # noqa: F405
new_opts = {
"disable-plugin": ["bcli"],
"network": "bitcoin",
"plugin": os.path.join(os.path.dirname(__file__), "../sauron.py"),
"sauron-api-endpoint": "https://blockstream.info/api",
"sauron-tor-proxy": "localhost:9050",
}
self.daemon.opts.update(options)
self.daemon.opts.update(old_opts)
self.daemon.opts.update(new_opts)
opts_to_disable = [
"bitcoin-datadir",
"bitcoin-rpcpassword",
"bitcoin-rpcuser",
"dev-bitcoind-poll",
]
for opt in opts_to_disable:
self.daemon.opts.pop(opt)

# Monkey patch
def set_feerates(self, feerates, wait_for_effect=True):
Expand Down
Loading

0 comments on commit 6389efa

Please sign in to comment.