From 6c4e603ff6ae92817603265e2829b30956a2b5b9 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 21 Sep 2023 12:47:11 +0200 Subject: [PATCH] regtest: pass config options from regtest.py to script --- electrum/tests/regtest.py | 57 ++++++++++++++++++++++++------- electrum/tests/regtest/regtest.sh | 20 +++-------- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/electrum/tests/regtest.py b/electrum/tests/regtest.py index ccf64b9a2..de6ea9351 100644 --- a/electrum/tests/regtest.py +++ b/electrum/tests/regtest.py @@ -19,12 +19,12 @@ class TestLightning(unittest.TestCase): test_name = self.id().split('.')[-1] sys.stdout.write("***** %s ******\n" % test_name) # initialize and get funds - for agent in self.agents: + for agent, config_options in self.agents.items(): self.run_shell(['init', agent]) + for k, v in config_options.items(): + self.run_shell(['setconfig', agent, k, v]) # mine a block so that funds are confirmed self.run_shell(['new_block']) - # extra configuration (optional) - self.run_shell(['configure_' + test_name]) # start daemons for agent in self.agents: self.run_shell(['start', agent]) @@ -35,24 +35,24 @@ class TestLightning(unittest.TestCase): class TestUnixSockets(TestLightning): - agents = [] + agents = {} def test_unixsockets(self): self.run_shell(['unixsockets']) class TestLightningAB(TestLightning): - agents = ['alice', 'bob'] + agents = { + 'alice': { + }, + 'bob': { + 'lightning_listen': 'localhost:9735', + } + } def test_collaborative_close(self): self.run_shell(['collaborative_close']) - def test_swapserver_success(self): - self.run_shell(['swapserver_success']) - - def test_swapserver_refund(self): - self.run_shell(['swapserver_refund']) - def test_backup(self): self.run_shell(['backup']) @@ -75,8 +75,39 @@ class TestLightningAB(TestLightning): self.run_shell(['breach_with_spent_htlc']) -class TestLightningABC(TestLightning): - agents = ['alice', 'bob', 'carol'] +class TestLightningSwapserver(TestLightning): + agents = { + 'alice': { + }, + 'bob': { + 'lightning_listen': 'localhost:9735', + 'use_swapserver': 'true', + } + } + + def test_swapserver_success(self): + self.run_shell(['swapserver_success']) + + def test_swapserver_refund(self): + self.run_shell(['swapserver_refund']) + + + +class TestLightningWatchtower(TestLightning): + agents = { + 'alice':{ + }, + 'bob':{ + 'lightning_listen': 'localhost:9735', + 'watchtower_url': 'http://wtuser:wtpassword@127.0.0.1:12345', + }, + 'carol':{ + 'run_watchtower': 'true', + 'watchtower_user': 'wtuser', + 'watchtower_password': 'wtpassword', + 'watchtower_port': '12345', + } + } def test_watchtower(self): self.run_shell(['watchtower']) diff --git a/electrum/tests/regtest/regtest.sh b/electrum/tests/regtest/regtest.sh index 14ad5a001..bcce18464 100755 --- a/electrum/tests/regtest/regtest.sh +++ b/electrum/tests/regtest/regtest.sh @@ -94,16 +94,16 @@ if [[ $1 == "init" ]]; then $agent setconfig --offline server 127.0.0.1:51001:t $agent setconfig --offline lightning_to_self_delay 144 $agent setconfig --offline test_force_disable_mpp True - # alice is funded, bob is listening - if [[ $2 == "bob" ]]; then - $bob setconfig --offline lightning_listen localhost:9735 - $bob setconfig --offline use_swapserver true - fi echo "funding $2" # note: changing the funding amount affects all tests, as they rely on "wait_for_balance" $bitcoin_cli sendtoaddress $($agent getunusedaddress -o) 1 fi +if [[ $1 == "setconfig" ]]; then + # use this to set config vars that need to be set before the daemon is started + agent="./run_electrum --regtest -D /tmp/$2" + $agent setconfig --offline $3 $4 +fi # start daemons. Bob is started first because he is listening if [[ $1 == "start" ]]; then @@ -408,16 +408,6 @@ if [[ $1 == "breach_with_spent_htlc" ]]; then $bob getbalance fi - -if [[ $1 == "configure_test_watchtower" ]]; then - # carol is the watchtower of bob - $carol setconfig -o run_watchtower true - $carol setconfig -o watchtower_user wtuser - $carol setconfig -o watchtower_password wtpassword - $carol setconfig -o watchtower_port 12345 - $bob setconfig -o watchtower_url http://wtuser:wtpassword@127.0.0.1:12345 -fi - if [[ $1 == "watchtower" ]]; then wait_for_balance alice 1 echo "alice opens channel"