From 4b15032c1376fdb8965c477f670162c9fd757d69 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sat, 9 Apr 2022 15:33:02 +0200 Subject: [PATCH] bolt2: add test for accept multiple shutdown msg Changelog-Add: bolt2: add test for accept multiple shutdown msg Signed-off-by: Vincenzo Palazzo --- tests/test_bolt2-01-close_channel.py | 71 ++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/tests/test_bolt2-01-close_channel.py b/tests/test_bolt2-01-close_channel.py index 3fe0ca5..c79fa7a 100644 --- a/tests/test_bolt2-01-close_channel.py +++ b/tests/test_bolt2-01-close_channel.py @@ -21,8 +21,12 @@ | |<-(?)-- 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, @@ -30,13 +34,16 @@ 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. @@ -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( @@ -65,6 +72,8 @@ 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( @@ -72,7 +81,7 @@ def test_close_channel_shutdown_msg_normal_case_received_side(runner: Runner) -> 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), @@ -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. @@ -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( @@ -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))