| 1 |
import os |
| 2 |
import sys |
| 3 |
import unittest |
| 4 |
import subprocess |
| 5 |
from typing import Mapping, Any |
| 6 |
|
| 7 |
|
| 8 |
class TestLightning(unittest.TestCase): |
| 9 |
agents: Mapping[str, Mapping[str, Any]] |
| 10 |
|
| 11 |
@staticmethod |
| 12 |
def run_shell(args, timeout=30): |
| 13 |
process = subprocess.Popen(['tests/regtest/regtest.sh'] + args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, universal_newlines=True) |
| 14 |
for line in iter(process.stdout.readline, ''): |
| 15 |
sys.stdout.write(line) |
| 16 |
sys.stdout.flush() |
| 17 |
process.wait(timeout=timeout) |
| 18 |
process.stdout.close() |
| 19 |
assert process.returncode == 0 |
| 20 |
|
| 21 |
def setUp(self): |
| 22 |
test_name = self.id().split('.')[-1] |
| 23 |
sys.stdout.write("***** %s ******\n" % test_name) |
| 24 |
|
| 25 |
for agent, config_options in self.agents.items(): |
| 26 |
self.run_shell(['init', agent]) |
| 27 |
for k, v in config_options.items(): |
| 28 |
self.run_shell(['setconfig', agent, k, v]) |
| 29 |
|
| 30 |
self.run_shell(['new_block']) |
| 31 |
|
| 32 |
for agent in self.agents: |
| 33 |
self.run_shell(['start', agent]) |
| 34 |
|
| 35 |
def tearDown(self): |
| 36 |
for agent in self.agents: |
| 37 |
self.run_shell(['stop', agent]) |
| 38 |
|
| 39 |
|
| 40 |
class TestUnixSockets(TestLightning): |
| 41 |
agents = {} |
| 42 |
|
| 43 |
def test_unixsockets(self): |
| 44 |
self.run_shell(['unixsockets']) |
| 45 |
|
| 46 |
|
| 47 |
class TestLightningAB(TestLightning): |
| 48 |
agents = { |
| 49 |
'alice': { |
| 50 |
'test_force_disable_mpp': 'false', |
| 51 |
'test_force_mpp': 'true', |
| 52 |
}, |
| 53 |
'bob': { |
| 54 |
'lightning_listen': 'localhost:9735', |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
def test_collaborative_close(self): |
| 59 |
self.run_shell(['collaborative_close']) |
| 60 |
|
| 61 |
def test_backup(self): |
| 62 |
self.run_shell(['backup']) |
| 63 |
|
| 64 |
def test_backup_local_forceclose(self): |
| 65 |
self.run_shell(['backup_local_forceclose']) |
| 66 |
|
| 67 |
def test_breach(self): |
| 68 |
self.run_shell(['breach']) |
| 69 |
|
| 70 |
def test_extract_preimage(self): |
| 71 |
self.run_shell(['extract_preimage']) |
| 72 |
|
| 73 |
def test_redeem_received_htlcs(self): |
| 74 |
self.run_shell(['redeem_received_htlcs']) |
| 75 |
|
| 76 |
def test_redeem_offered_htlcs(self): |
| 77 |
self.run_shell(['redeem_offered_htlcs']) |
| 78 |
|
| 79 |
def test_breach_with_unspent_htlc(self): |
| 80 |
self.run_shell(['breach_with_unspent_htlc']) |
| 81 |
|
| 82 |
def test_breach_with_spent_htlc(self): |
| 83 |
self.run_shell(['breach_with_spent_htlc']) |
| 84 |
|
| 85 |
def test_lnwatcher_waits_until_fees_go_down(self): |
| 86 |
self.run_shell(['lnwatcher_waits_until_fees_go_down']) |
| 87 |
|
| 88 |
|
| 89 |
class TestLightningSwapserver(TestLightning): |
| 90 |
agents = { |
| 91 |
'alice': { |
| 92 |
'use_gossip': 'false', |
| 93 |
'swapserver_url': 'http://localhost:5455', |
| 94 |
'nostr_relays': "''", |
| 95 |
}, |
| 96 |
'bob': { |
| 97 |
'lightning_listen': 'localhost:9735', |
| 98 |
'plugins.swapserver.enabled': 'true', |
| 99 |
'plugins.swapserver.port': '5455', |
| 100 |
'nostr_relays': "''", |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
def test_swapserver_success_forward(self): |
| 105 |
self.run_shell(['swapserver_success_forward']) |
| 106 |
|
| 107 |
def test_swapserver_success_reverse(self): |
| 108 |
self.run_shell(['swapserver_success_reverse']) |
| 109 |
|
| 110 |
def test_swapserver_forceclose(self): |
| 111 |
self.run_shell(['swapserver_forceclose']) |
| 112 |
|
| 113 |
def test_swapserver_refund(self): |
| 114 |
self.run_shell(['swapserver_refund']) |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
class TestLightningWatchtower(TestLightning): |
| 119 |
agents = { |
| 120 |
'alice': { |
| 121 |
}, |
| 122 |
'bob': { |
| 123 |
'lightning_listen': 'localhost:9735', |
| 124 |
'watchtower_url': 'http://wtuser:[email protected]:12345', |
| 125 |
}, |
| 126 |
'carol': { |
| 127 |
'plugins.watchtower.enabled': 'true', |
| 128 |
'plugins.watchtower.server_user': 'wtuser', |
| 129 |
'plugins.watchtower.server_password': 'wtpassword', |
| 130 |
'plugins.watchtower.server_port': '12345', |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
def test_watchtower(self): |
| 135 |
self.run_shell(['watchtower']) |
| 136 |
|
| 137 |
|
| 138 |
class TestLightningABC(TestLightning): |
| 139 |
agents = { |
| 140 |
'alice': { |
| 141 |
}, |
| 142 |
'bob': { |
| 143 |
'lightning_listen': 'localhost:9735', |
| 144 |
'lightning_forward_payments': 'true', |
| 145 |
}, |
| 146 |
'carol': { |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
def test_fw_fail_htlc(self): |
| 151 |
self.run_shell(['fw_fail_htlc']) |
| 152 |
|
| 153 |
|
| 154 |
class TestLightningJIT(TestLightning): |
| 155 |
agents = { |
| 156 |
'alice': { |
| 157 |
'open_zeroconf_channels': 'true', |
| 158 |
}, |
| 159 |
'bob': { |
| 160 |
'lightning_listen': 'localhost:9735', |
| 161 |
'lightning_forward_payments': 'true', |
| 162 |
'open_zeroconf_channels': 'true', |
| 163 |
}, |
| 164 |
'carol': { |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
def test_just_in_time(self): |
| 169 |
self.run_shell(['just_in_time']) |
| 170 |
|
| 171 |
|
| 172 |
class TestLightningJITTrampoline(TestLightningJIT): |
| 173 |
agents = { |
| 174 |
'alice': { |
| 175 |
'use_gossip': 'false', |
| 176 |
'open_zeroconf_channels': 'true', |
| 177 |
}, |
| 178 |
'bob': { |
| 179 |
'lightning_listen': 'localhost:9735', |
| 180 |
'lightning_forward_payments': 'true', |
| 181 |
'lightning_forward_trampoline_payments': 'true', |
| 182 |
'open_zeroconf_channels': 'true', |
| 183 |
}, |
| 184 |
'carol': { |
| 185 |
'use_gossip': 'false', |
| 186 |
} |
| 187 |
} |