Skip to content

Commit

Permalink
bolt2: sempligy the shutdown process and add some FIXME
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Apr 6, 2022
1 parent 41853af commit a9a5ac5
Showing 1 changed file with 11 additions and 37 deletions.
48 changes: 11 additions & 37 deletions tests/test_bolt2-01-close_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@
author: https://github.com/vincenzopalazzo
"""
import hashlib

from bitcoin.core import CScript, Hash160
from bitcoin.core.script import OP_0, OP_CHECKSIG
from bitcoin.wallet import CBitcoinSecret
from lnprototest import (
ExpectMsg,
Msg,
Runner,
TryAll,
OneOf,
MustNotMsg,
)
from helpers import run_runner, merge_events_sequences, tx_spendable
from lnprototest.stash import channel_id
from spec_helper import open_and_announce_channel_helper, connect_to_node_helper
from lnprototest.utils import BitcoinUtils, ScriptType


def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) -> None:
Expand Down Expand Up @@ -64,11 +60,7 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) ->
pre_events = merge_events_sequences(pre_events_conn, pre_events)
channel_idx = channel_id()

# FIXME: refactoring this in a bitcoin helper
h = hashlib.sha256(b"correct horse battery staple").digest()
seckey = CBitcoinSecret.from_secret_bytes(h)
# Create an address from that private key.
script = CScript([OP_0, Hash160(seckey.pub)]).hex()
script = BitcoinUtils.build_valid_script()

test = [
# runner sent shutdown message to the ln implementation
Expand All @@ -79,27 +71,10 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) ->
channel_id=channel_idx,
scriptpubkey=script,
),
# FIXME: when this have sense? when there is not update?
# from c-lightning code we update the channel state
# so I'm assuming that this will trigger a new channel_update
# from gossip
OneOf(
# channel_update to change the state of the channel from
# NORMAL -> SHUTDOWN
[
ExpectMsg("channel_update"),
ExpectMsg("shutdown", channel_id=channel_idx),
],
# channel_update to change the state of the connection from
# NORMAL -> SHUTDOWN -> ONCHAIN
[
ExpectMsg("channel_update"),
ExpectMsg("channel_update"),
ExpectMsg("shutdown", channel_id=channel_idx),
],
# No channel_update received; this means that there is now pending update?
[ExpectMsg("shutdown", channel_id=channel_idx)],
),
MustNotMsg("add_htlc"),
# TODO: must be -> ExpectMsg("shutdown", channel_id=channel_idx, scriptpubkey=script),
# why the script is different
ExpectMsg("shutdown", channel_id=channel_idx),
],
),
]
Expand Down Expand Up @@ -128,11 +103,7 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(runner: Ru
pre_events = merge_events_sequences(pre_events_conn, pre_events)
channel_idx = channel_id()

# FIXME: refactoring this in a bitcoin helper
h = hashlib.sha256(b"correct horse battery staple").digest()
seckey = CBitcoinSecret.from_secret_bytes(h)
# Create an address from that private key.
script = CScript([seckey.pub, OP_CHECKSIG])
script = BitcoinUtils.build_valid_script(ScriptType.INVALID_CLOSE_SCRIPT)

test = [
# runner sent shutdown message to the ln implementation
Expand All @@ -143,6 +114,9 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(runner: Ru
channel_id=channel_idx,
scriptpubkey=script,
),
MustNotMsg('shutdown'),
MustNotMsg('add_htlc'),
# FIXME: add support for warning messages in pyln package?
],
),
]
Expand Down

0 comments on commit a9a5ac5

Please sign in to comment.