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 7bc966c
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions tests/test_bolt2-01-close_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
| |<-(?)-- closing_signed Fn----| |
+-------+ +-------+
BOLT 2 proposal https://github.com/lightning/bolts/pull/972
author: https://github.com/vincenzopalazzo
"""
from lnprototest import (
Expand Down Expand Up @@ -48,7 +50,6 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) ->
--------------------------------
"""

# test preconditions.
# the option that the helper method feel for us
test_opts = {}
pre_events_conn = connect_to_node_helper(
Expand All @@ -65,14 +66,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 @@ -93,7 +96,6 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(
-------------------------------------------------------
"""

# 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 +126,52 @@ 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) -> 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 |
--------------------------------
"""
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 7bc966c

Please sign in to comment.