Skip to content

Commit

Permalink
watchtower-plugin: adapts tests to stop using deprecated options/comm…
Browse files Browse the repository at this point in the history
…ands
  • Loading branch information
sr-gi committed Mar 29, 2024
1 parent 7da0e2a commit e29cc58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 3 additions & 1 deletion watchtower-plugin/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def pytest_runtest_makereport(item, call):


def pytest_configure(config):
config.addinivalue_line("markers", "developer: only run when developer is flagged on")
config.addinivalue_line(
"markers", "developer: only run when developer is flagged on"
)


def pytest_runtest_setup(item):
Expand Down
37 changes: 27 additions & 10 deletions watchtower-plugin/tests/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from pyln.client import RpcError
from conftest import WT_PLUGIN


Expand All @@ -16,7 +15,6 @@ def change_endianness(x):
return b[::-1].hex()


@pytest.mark.developer("Requires dev_sign_last_tx")
def test_watchtower(node_factory, bitcoind, teosd):
"""
Test watchtower hook.
Expand All @@ -27,7 +25,9 @@ def test_watchtower(node_factory, bitcoind, teosd):
commitment transaction.
"""

l1, l2 = node_factory.line_graph(2, opts=[{"allow_broken_log": True}, {"plugin": WT_PLUGIN}])
l1, l2 = node_factory.line_graph(
2, opts=[{"allow_broken_log": True}, {"plugin": WT_PLUGIN}]
)

# We need to register l2 with the tower
tower_id = teosd.cli.gettowerinfo()["tower_id"]
Expand All @@ -48,7 +48,9 @@ def test_watchtower(node_factory, bitcoind, teosd):
locator = change_endianness(dispute_txid[32:])

# Make sure l2's normal penalty_tx doesn't reach the network
l2.daemon.rpcproxy.mock_rpc("sendrawtransaction", lambda _: {"result": None, "error": None, "id": "pytest"})
l2.daemon.rpcproxy.mock_rpc(
"sendrawtransaction", lambda _: {"result": None, "error": None, "id": "pytest"}
)
l2.start()

# The tower will react once the dispute gets confirmed. For now it is still watching for it
Expand All @@ -60,14 +62,17 @@ def test_watchtower(node_factory, bitcoind, teosd):
penalty_txid = bitcoind.rpc.getrawmempool()[0]

# The channel still exists between the two peers, but it's on chain
assert l1.rpc.listpeers()["peers"][0]["channels"][0]["state"] == "ONCHAIN"
assert l1.rpc.listpeerchannels()["channels"][0]["state"] == "ONCHAIN"
assert l2.rpc.getappointment(tower_id, locator)["status"] == "dispute_responded"

# Generate blocks until the penalty gets irrevocably resolved
for i in range(101):
bitcoind.generate_block()
if i < 100:
assert l2.rpc.getappointment(tower_id, locator)["status"] == "dispute_responded"
assert (
l2.rpc.getappointment(tower_id, locator)["status"]
== "dispute_responded"
)
else:
# Once the channel gets irrevocably resolved the tower will forget about it
assert l2.rpc.getappointment(tower_id, locator) == {
Expand Down Expand Up @@ -193,7 +198,9 @@ def test_manually_retry_watchtower(node_factory, bitcoind, teosd):


def test_misbehaving_watchtower(node_factory, bitcoind, teosd, directory):
l1, l2 = node_factory.line_graph(2, opts=[{}, {"plugin": WT_PLUGIN, "allow_broken_log": True}])
l1, l2 = node_factory.line_graph(
2, opts=[{}, {"plugin": WT_PLUGIN, "allow_broken_log": True}]
)

# We need to register l2 with the tower
tower_id = teosd.cli.gettowerinfo()["tower_id"]
Expand All @@ -210,7 +217,9 @@ def test_misbehaving_watchtower(node_factory, bitcoind, teosd, directory):


def test_get_appointment(node_factory, bitcoind, teosd, directory):
l1, l2 = node_factory.line_graph(2, opts=[{"allow_broken_log": True}, {"plugin": WT_PLUGIN}])
l1, l2 = node_factory.line_graph(
2, opts=[{"allow_broken_log": True}, {"plugin": WT_PLUGIN}]
)

# We need to register l2 with the tower
tower_id = teosd.cli.gettowerinfo()["tower_id"]
Expand All @@ -229,13 +238,21 @@ def test_get_appointment(node_factory, bitcoind, teosd, directory):

# Check the appointment before mining a block
appointment = l2.rpc.getappointment(tower_id, locator)["appointment"]
assert "locator" in appointment and "encrypted_blob" in appointment and "to_self_delay" in appointment
assert (
"locator" in appointment
and "encrypted_blob" in appointment
and "to_self_delay" in appointment
)

# And after. Now this should be a tracker
bitcoind.generate_block()
teosd.wait_for_log("New tracker added")
tracker = l2.rpc.getappointment(tower_id, locator)["appointment"]
assert "dispute_txid" in tracker and "penalty_txid" in tracker and "penalty_rawtx" in tracker
assert (
"dispute_txid" in tracker
and "penalty_txid" in tracker
and "penalty_rawtx" in tracker
)

# Manually stop l2, otherwise the tower may be stopped before the tower client and we may get some BROKEN logs.
l2.stop()

0 comments on commit e29cc58

Please sign in to comment.