Skip to content

Commit

Permalink
add the expect msg at the end to trigger the must not msg
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzopalazzo committed Aug 29, 2022
1 parent 2c129cb commit b1677ca
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 97 deletions.
4 changes: 0 additions & 4 deletions docker/Dockerfile.clightning
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ LABEL mantainer="Vincenzo Palazzo [email protected]"
WORKDIR /work

ENV BITCOIN_VERSION=23.0
ENV CLIGHTNING_VERSION=0.11.0
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get -qq update && \
Expand Down Expand Up @@ -60,9 +59,6 @@ RUN git config --global user.name "John Doe" && \
git config --global user.email [email protected] && \
git clone https://github.com/ElementsProject/lightning.git && \
cd lightning && \
# git checkout v$CLIGHTNING_VERSION && \
# fetch core lightning patch
git pull origin pull/5367/head && \
poetry config virtualenvs.create false && \
poetry install && \
./configure --enable-developer && \
Expand Down
5 changes: 3 additions & 2 deletions lnprototest/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /usr/bin/python3
import logging
import traceback
from pyln.proto.message import Message
import collections
Expand Down Expand Up @@ -123,13 +124,13 @@ def __init__(self, must_not: str, connprivkey: Optional[str] = None):
self.must_not = must_not

def matches(self, binmsg: bytes) -> bool:
msgnum = struct.unpack(">H", binmsg[0:2])[0]
msgnum = struct.unpack(">H", binmsg[:2])[0]
msgtype = namespace().get_msgtype_by_number(msgnum)
if msgtype:
name = msgtype.name
else:
name = str(msgnum)

logging.info(f"msg {name} != from what we are looking for {self.must_not}?")
return name == self.must_not

def action(self, runner: "Runner") -> bool:
Expand Down
3 changes: 3 additions & 0 deletions lnprototest/structure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /usr/bin/python3
import io
import logging

from .event import Event, ExpectMsg, ResolvableBool
from .errors import SpecFileError, EventError
from .namespace import namespace
Expand Down Expand Up @@ -44,6 +46,7 @@ def action(self, runner: "Runner", skip_first: bool = False) -> bool:
super().action(runner)
all_done = True
for e in self.events:
logging.debug(f"receiving event {e}")
if not e.enabled(runner):
continue
if skip_first:
Expand Down
32 changes: 18 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 18 additions & 77 deletions tests/test_bolt2-01-close_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,19 @@
author: https://github.com/vincenzopalazzo
"""
from typing import Any

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

# the option that the helper method feel for us
# the option that the helper method feels for us
test_opts = {}
pre_events_conn = connect_to_node_helper(
runner, tx_spendable=tx_spendable, conn_privkey="03"
Expand All @@ -69,7 +62,7 @@ def test_close_channel_shutdown_msg_normal_case_received_side(

script = BitcoinUtils.build_valid_script()
test = [
# runner sent shutdown message to the ln implementation
# runner sent shutdown message to ln implementation
# BOLT 2:
# - MUST NOT send an `update_add_htlc` after a shutdown.
Msg(
Expand All @@ -94,7 +87,7 @@ def test_close_channel_shutdown_msg_normal_case_received_side(


def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(
runner: Runner, namespaceoverride: Any
runner: Runner,
) -> 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 @@ -103,8 +96,6 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(
| runner <- warning msg <- ln-node |
-------------------------------------------------------
"""
namespaceoverride(peer_message_namespace())

# the option that the helper method feels for us
test_opts = {}
pre_events_conn = connect_to_node_helper(
Expand All @@ -126,76 +117,28 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_received_side(
channel_id=channel_idx,
scriptpubkey=script,
),
MustNotMsg("shutdown"),
MustNotMsg("add_htlc"),
MustNotMsg("shutdown"),
# FIXME: add support for warning messages in pyln package?
ExpectMsg("warning"),
]
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
Msg(
"shutdown",
channel_id=channel_idx,
scriptpubkey=script,
),
Msg(
"shutdown",
channel_id=channel_idx,
scriptpubkey=script,
),
MustNotMsg("update_add_htlc"),
ExpectMsg(
"shutdown", ignore=ExpectMsg.ignore_all_gossip, channel_id=channel_idx
),
]
run_runner(runner, merge_events_sequences(pre=pre_events, post=test))


def test_close_channel_allow_multiple_shutdown_msg_with_diff_script_receive_side(
runner: Runner, namespaceoverride: Any
) -> None:
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 |
--------------------------------
In This case, multiple shutdowns are not allowed by the spec:
# BOLT #2:
- MUST NOT send multiple `shutdown` messages.
____________________________________
| runner -> shutdown -> ln-node |
| runner -> shutdown -> ln-node |
| runner <- error/warning <- ln-node |
-------------------------------------
"""
namespaceoverride(peer_message_namespace())
test_opts = {}
pre_events_conn = connect_to_node_helper(
runner, tx_spendable=tx_spendable, conn_privkey="03"
Expand Down Expand Up @@ -224,10 +167,8 @@ def test_close_channel_allow_multiple_shutdown_msg_with_diff_script_receive_side
scriptpubkey=script_two,
),
MustNotMsg("update_add_htlc"),
# TODO: must be -> ExpectMsg("shutdown", channel_id=channel_idx, scriptpubkey=script_two),
# why the script is different
ExpectMsg(
"shutdown", ignore=ExpectMsg.ignore_all_gossip, channel_id=channel_idx
),
MustNotMsg("shutdown"),
# TODO: check why message cln send here, I assume a warning
ExpectMsg("warning"),
]
run_runner(runner, merge_events_sequences(pre=pre_events, post=test))

0 comments on commit b1677ca

Please sign in to comment.