Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sauron: make tests more robust #649

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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