Browse Source

add request_force_close command to CLI

add regtest for channel backup
patch-4
ThomasV 4 years ago
parent
commit
f16358ec3c
  1. 6
      electrum/commands.py
  2. 3
      electrum/tests/regtest.py
  3. 24
      electrum/tests/regtest/regtest.sh

6
electrum/commands.py

@ -1081,6 +1081,12 @@ class Commands:
coro = wallet.lnworker.force_close_channel(chan_id) if force else wallet.lnworker.close_channel(chan_id)
return await coro
@command('wn')
async def request_force_close(self, channel_point, wallet: Abstract_Wallet = None):
txid, index = channel_point.split(':')
chan_id, _ = channel_id_from_funding_tx(txid, int(index))
return await wallet.lnworker.request_force_close_from_backup(chan_id)
@command('w')
async def export_channel_backup(self, channel_point, wallet: Abstract_Wallet = None):
txid, index = channel_point.split(':')

3
electrum/tests/regtest.py

@ -36,6 +36,9 @@ class TestLightning(unittest.TestCase):
class TestLightningAB(TestLightning):
agents = ['alice', 'bob']
def test_backup(self):
self.run_shell(['backup'])
def test_breach(self):
self.run_shell(['breach'])

24
electrum/tests/regtest/regtest.sh

@ -133,6 +133,30 @@ if [[ $1 == "breach" ]]; then
fi
if [[ $1 == "backup" ]]; then
wait_for_balance alice 1
echo "alice opens channel"
bob_node=$($bob nodeid)
channel=$($alice open_channel $bob_node 0.15)
echo "channel point: $channel"
new_blocks 3
wait_until_channel_open alice
backup=$($alice export_channel_backup $channel)
request=$($bob add_lightning_request 0.01 -m "blah" | jq -r ".invoice")
echo "alice pays"
$alice lnpay $request
seed=$($alice getseed)
$alice stop
sleep 2 # FIXME: we should not have to do that..
mv /tmp/alice/regtest/wallets/default_wallet /tmp/alice/regtest/wallets/default_wallet.old
$alice -o restore "$seed"
$alice daemon -d
$alice load_wallet
$alice import_channel_backup $backup
$alice request_force_close $channel
fi
if [[ $1 == "extract_preimage" ]]; then
# instead of settling bob will broadcast
$bob enable_htlc_settle false

Loading…
Cancel
Save