Skip to content

Commit

Permalink
bolt2: add test for accept multiple shutdown msg
Browse files Browse the repository at this point in the history
Changelog-Add: bolt2: add test for accept multiple shutdown msg

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Apr 9, 2022
1 parent 127fd9f commit 4b15032
Showing 1 changed file with 66 additions and 5 deletions.
71 changes: 66 additions & 5 deletions tests/test_bolt2-01-close_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@
| |<-(?)-- closing_signed Fn----| |
+-------+ +-------+
BOLT 2 proposal https://github.com/lightning/bolts/pull/972
author: https://github.com/vincenzopalazzo
"""
from typing import Any

from lnprototest import (
ExpectMsg,
Msg,
Runner,
TryAll,
MustNotMsg,
)
from lnprototest.namespace import peer_message_namespace
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:
def test_close_channel_shutdown_msg_normal_case_received_side(
runner: Runner, namespaceoverride: Any
) -> None:
"""Close the channel with the other peer, and check if the
shutdown message works in the expected way.
Expand All @@ -47,8 +54,8 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) ->
| runner <- shutdown <- ln-node |
--------------------------------
"""
namespaceoverride(peer_message_namespace())

# test preconditions.
# the option that the helper method feel for us
test_opts = {}
pre_events_conn = connect_to_node_helper(
Expand All @@ -65,14 +72,16 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) ->

test = [
# runner sent shutdown message to the ln implementation
# BOLT 2:
# - MUST NOT send an `update_add_htlc` after a shutdown.
TryAll(
[
Msg(
"shutdown",
channel_id=channel_idx,
scriptpubkey=script,
),
MustNotMsg("add_htlc"),
MustNotMsg("update_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 All @@ -83,7 +92,7 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) ->


def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(
runner: Runner,
runner: Runner, namespaceoverride: Any
) -> None:
"""Test close operation from the receiver view point, in the case when
the sender set a wrong script pub key not specified in the spec.
Expand All @@ -92,8 +101,8 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(
| runner <- warning msg <- ln-node |
-------------------------------------------------------
"""
namespaceoverride(peer_message_namespace())

# test preconditions.
# the option that the helper method feels for us
test_opts = {}
pre_events_conn = connect_to_node_helper(
Expand Down Expand Up @@ -124,3 +133,55 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(
),
]
run_runner(runner, merge_events_sequences(pre=pre_events, post=test))


def test_close_channel_allow_multiple_shutdown_msg_receive_side(
runner: Runner, namespaceoverride: Any
) -> None:
"""
Close operation from the receiver point of view, where the receiver will
receive multiple shutdown msg.
FIXME: this need to be allowed by the spec!
________________________________
| runner -> shutdown -> ln-node |
| runner -> shutdown -> ln-node |
| runner <- shutdown <- ln-node |
--------------------------------
"""
namespaceoverride(peer_message_namespace())
test_opts = {}
pre_events_conn = connect_to_node_helper(
runner, tx_spendable=tx_spendable, conn_privkey="03"
)
pre_events = open_and_announce_channel_helper(
runner, conn_privkey="03", opts=test_opts
)
# merge the two events
pre_events = merge_events_sequences(pre_events_conn, pre_events)
channel_idx = channel_id()

script = BitcoinUtils.build_valid_script()

test = [
# runner sent shutdown message to the ln implementation
TryAll(
[
Msg(
"shutdown",
channel_id=channel_idx,
scriptpubkey=script,
),
Msg(
"shutdown",
channel_id=channel_idx,
scriptpubkey=script,
),
MustNotMsg("update_add_htlc"),
# TODO: must be -> ExpectMsg("shutdown", channel_id=channel_idx, scriptpubkey=script),
# why the script is different
ExpectMsg("shutdown", channel_id=channel_idx),
],
),
]
run_runner(runner, merge_events_sequences(pre=pre_events, post=test))

0 comments on commit 4b15032

Please sign in to comment.