2019-03-11 21:00:29 +01:00
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import unittest
|
|
|
|
|
import subprocess
|
2025-03-10 14:54:50 +00:00
|
|
|
from typing import Mapping, Any
|
|
|
|
|
|
2019-03-11 21:00:29 +01:00
|
|
|
|
|
|
|
|
class TestLightning(unittest.TestCase):
|
2025-03-10 14:54:50 +00:00
|
|
|
agents: Mapping[str, Mapping[str, Any]]
|
2019-03-11 21:00:29 +01:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def run_shell(args, timeout=30):
|
2024-02-16 15:33:34 +01:00
|
|
|
process = subprocess.Popen(['tests/regtest/regtest.sh'] + args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, universal_newlines=True)
|
2021-09-13 16:20:54 +00:00
|
|
|
for line in iter(process.stdout.readline, ''):
|
|
|
|
|
sys.stdout.write(line)
|
|
|
|
|
sys.stdout.flush()
|
2019-03-11 21:00:29 +01:00
|
|
|
process.wait(timeout=timeout)
|
|
|
|
|
process.stdout.close()
|
|
|
|
|
assert process.returncode == 0
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2020-02-02 14:50:08 +01:00
|
|
|
test_name = self.id().split('.')[-1]
|
|
|
|
|
sys.stdout.write("***** %s ******\n" % test_name)
|
|
|
|
|
# initialize and get funds
|
2023-09-21 12:47:11 +02:00
|
|
|
for agent, config_options in self.agents.items():
|
2020-02-02 14:50:08 +01:00
|
|
|
self.run_shell(['init', agent])
|
2023-09-21 12:47:11 +02:00
|
|
|
for k, v in config_options.items():
|
|
|
|
|
self.run_shell(['setconfig', agent, k, v])
|
2020-02-02 14:50:08 +01:00
|
|
|
# mine a block so that funds are confirmed
|
|
|
|
|
self.run_shell(['new_block'])
|
|
|
|
|
# start daemons
|
|
|
|
|
for agent in self.agents:
|
|
|
|
|
self.run_shell(['start', agent])
|
2019-03-11 21:00:29 +01:00
|
|
|
|
|
|
|
|
def tearDown(self):
|
2020-02-02 14:50:08 +01:00
|
|
|
for agent in self.agents:
|
|
|
|
|
self.run_shell(['stop', agent])
|
2019-03-11 21:00:29 +01:00
|
|
|
|
2020-02-03 15:15:29 +01:00
|
|
|
|
2021-10-25 12:00:00 +00:00
|
|
|
class TestUnixSockets(TestLightning):
|
2023-09-21 12:47:11 +02:00
|
|
|
agents = {}
|
2021-10-25 12:00:00 +00:00
|
|
|
|
|
|
|
|
def test_unixsockets(self):
|
|
|
|
|
self.run_shell(['unixsockets'])
|
|
|
|
|
|
|
|
|
|
|
2020-02-03 15:15:29 +01:00
|
|
|
class TestLightningAB(TestLightning):
|
2023-09-21 12:47:11 +02:00
|
|
|
agents = {
|
|
|
|
|
'alice': {
|
2025-02-14 14:12:12 +01:00
|
|
|
'test_force_disable_mpp': 'false',
|
|
|
|
|
'test_force_mpp': 'true',
|
2023-09-21 12:47:11 +02:00
|
|
|
},
|
|
|
|
|
'bob': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'lightning_listen': 'localhost:9735',
|
2023-09-21 12:47:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-02-03 15:15:29 +01:00
|
|
|
|
2021-11-26 09:45:06 +01:00
|
|
|
def test_collaborative_close(self):
|
|
|
|
|
self.run_shell(['collaborative_close'])
|
|
|
|
|
|
2021-03-12 16:10:02 +01:00
|
|
|
def test_backup(self):
|
|
|
|
|
self.run_shell(['backup'])
|
|
|
|
|
|
2023-07-14 13:44:56 +00:00
|
|
|
def test_backup_local_forceclose(self):
|
|
|
|
|
self.run_shell(['backup_local_forceclose'])
|
|
|
|
|
|
2019-03-11 21:00:29 +01:00
|
|
|
def test_breach(self):
|
|
|
|
|
self.run_shell(['breach'])
|
|
|
|
|
|
2020-05-02 11:39:21 +02:00
|
|
|
def test_extract_preimage(self):
|
|
|
|
|
self.run_shell(['extract_preimage'])
|
|
|
|
|
|
2025-05-08 19:28:05 +02:00
|
|
|
def test_redeem_received_htlcs(self):
|
|
|
|
|
self.run_shell(['redeem_received_htlcs'])
|
|
|
|
|
|
|
|
|
|
def test_redeem_offered_htlcs(self):
|
|
|
|
|
self.run_shell(['redeem_offered_htlcs'])
|
2019-05-29 17:34:12 +02:00
|
|
|
|
2019-06-24 11:13:18 +02:00
|
|
|
def test_breach_with_unspent_htlc(self):
|
|
|
|
|
self.run_shell(['breach_with_unspent_htlc'])
|
|
|
|
|
|
|
|
|
|
def test_breach_with_spent_htlc(self):
|
|
|
|
|
self.run_shell(['breach_with_spent_htlc'])
|
2019-07-05 14:42:09 +02:00
|
|
|
|
2025-06-28 08:03:32 +00:00
|
|
|
def test_lnwatcher_waits_until_fees_go_down(self):
|
|
|
|
|
self.run_shell(['lnwatcher_waits_until_fees_go_down'])
|
|
|
|
|
|
2020-02-03 15:15:29 +01:00
|
|
|
|
2023-09-21 12:47:11 +02:00
|
|
|
class TestLightningSwapserver(TestLightning):
|
|
|
|
|
agents = {
|
|
|
|
|
'alice': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'use_gossip': 'false',
|
|
|
|
|
'swapserver_url': 'http://localhost:5455',
|
|
|
|
|
'nostr_relays': "''",
|
2023-09-21 12:47:11 +02:00
|
|
|
},
|
|
|
|
|
'bob': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'lightning_listen': 'localhost:9735',
|
2025-04-11 18:24:59 +02:00
|
|
|
'plugins.swapserver.enabled': 'true',
|
|
|
|
|
'plugins.swapserver.port': '5455',
|
2025-03-10 12:01:41 +01:00
|
|
|
'nostr_relays': "''",
|
2023-09-21 12:47:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_swapserver_success(self):
|
|
|
|
|
self.run_shell(['swapserver_success'])
|
|
|
|
|
|
2024-10-23 15:28:01 +02:00
|
|
|
def test_swapserver_forceclose(self):
|
|
|
|
|
self.run_shell(['swapserver_forceclose'])
|
|
|
|
|
|
2023-09-21 12:47:11 +02:00
|
|
|
def test_swapserver_refund(self):
|
|
|
|
|
self.run_shell(['swapserver_refund'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLightningWatchtower(TestLightning):
|
|
|
|
|
agents = {
|
2025-03-10 14:54:50 +00:00
|
|
|
'alice': {
|
2023-09-21 12:47:11 +02:00
|
|
|
},
|
2025-03-10 14:54:50 +00:00
|
|
|
'bob': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'lightning_listen': 'localhost:9735',
|
|
|
|
|
'watchtower_url': 'http://wtuser:wtpassword@127.0.0.1:12345',
|
2023-09-21 12:47:11 +02:00
|
|
|
},
|
2025-03-10 14:54:50 +00:00
|
|
|
'carol': {
|
2025-04-11 18:24:59 +02:00
|
|
|
'plugins.watchtower.enabled': 'true',
|
|
|
|
|
'plugins.watchtower.server_user': 'wtuser',
|
|
|
|
|
'plugins.watchtower.server_password': 'wtpassword',
|
|
|
|
|
'plugins.watchtower.server_port': '12345',
|
2023-09-21 12:47:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-02-03 15:15:29 +01:00
|
|
|
|
2019-07-05 14:42:09 +02:00
|
|
|
def test_watchtower(self):
|
|
|
|
|
self.run_shell(['watchtower'])
|
2023-08-08 05:09:58 +02:00
|
|
|
|
|
|
|
|
|
2025-03-11 18:13:32 +01:00
|
|
|
class TestLightningABC(TestLightning):
|
|
|
|
|
agents = {
|
|
|
|
|
'alice': {
|
|
|
|
|
},
|
|
|
|
|
'bob': {
|
|
|
|
|
'lightning_listen': 'localhost:9735',
|
|
|
|
|
'lightning_forward_payments': 'true',
|
|
|
|
|
},
|
|
|
|
|
'carol': {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_fw_fail_htlc(self):
|
|
|
|
|
self.run_shell(['fw_fail_htlc'])
|
|
|
|
|
|
|
|
|
|
|
2023-08-08 05:09:58 +02:00
|
|
|
class TestLightningJIT(TestLightning):
|
|
|
|
|
agents = {
|
2025-03-10 14:54:50 +00:00
|
|
|
'alice': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'accept_zeroconf_channels': 'true',
|
2023-08-08 05:09:58 +02:00
|
|
|
},
|
2025-03-10 14:54:50 +00:00
|
|
|
'bob': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'lightning_listen': 'localhost:9735',
|
|
|
|
|
'lightning_forward_payments': 'true',
|
|
|
|
|
'accept_zeroconf_channels': 'true',
|
2023-08-08 05:09:58 +02:00
|
|
|
},
|
2025-03-10 14:54:50 +00:00
|
|
|
'carol': {
|
2023-08-08 05:09:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_just_in_time(self):
|
|
|
|
|
self.run_shell(['just_in_time'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestLightningJITTrampoline(TestLightningJIT):
|
|
|
|
|
agents = {
|
2025-03-10 14:54:50 +00:00
|
|
|
'alice': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'use_gossip': 'false',
|
|
|
|
|
'accept_zeroconf_channels': 'true',
|
2023-08-08 05:09:58 +02:00
|
|
|
},
|
2025-03-10 14:54:50 +00:00
|
|
|
'bob': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'lightning_listen': 'localhost:9735',
|
|
|
|
|
'lightning_forward_payments': 'true',
|
|
|
|
|
'lightning_forward_trampoline_payments': 'true',
|
|
|
|
|
'accept_zeroconf_channels': 'true',
|
2023-08-08 05:09:58 +02:00
|
|
|
},
|
2025-03-10 14:54:50 +00:00
|
|
|
'carol': {
|
2025-03-10 12:01:41 +01:00
|
|
|
'use_gossip': 'false',
|
2023-08-08 05:09:58 +02:00
|
|
|
}
|
|
|
|
|
}
|