diff --git a/docker/Dockerfile.clightning b/docker/Dockerfile.clightning index 383a1fd..7884750 100644 --- a/docker/Dockerfile.clightning +++ b/docker/Dockerfile.clightning @@ -4,7 +4,6 @@ LABEL mantainer="Vincenzo Palazzo vincenzopalazzodev@gmail.com" WORKDIR /work ENV BITCOIN_VERSION=23.0 -ENV CLIGHTNING_VERSION=0.11.0 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get -qq update && \ @@ -60,9 +59,6 @@ RUN git config --global user.name "John Doe" && \ git config --global user.email johndoe@example.com && \ 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 && \ diff --git a/lnprototest/event.py b/lnprototest/event.py index 134620e..231ed6d 100644 --- a/lnprototest/event.py +++ b/lnprototest/event.py @@ -1,4 +1,5 @@ #! /usr/bin/python3 +import logging import traceback from pyln.proto.message import Message import collections @@ -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: diff --git a/lnprototest/structure.py b/lnprototest/structure.py index 54ef65b..40812b0 100644 --- a/lnprototest/structure.py +++ b/lnprototest/structure.py @@ -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 @@ -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: diff --git a/poetry.lock b/poetry.lock index c9e638f..9cbeed0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -180,7 +180,7 @@ pyflakes = ">=2.4.0,<2.5.0" [[package]] name = "flask" -version = "2.1.3" +version = "2.2.2" description = "A simple framework for building complex web applications." category = "main" optional = false @@ -191,7 +191,7 @@ click = ">=8.0" importlib-metadata = {version = ">=3.6.0", markers = "python_version < \"3.10\""} itsdangerous = ">=2.0" Jinja2 = ">=3.0" -Werkzeug = ">=2.0" +Werkzeug = ">=2.2.2" [package.extras] async = ["asgiref (>=3.2)"] @@ -275,7 +275,7 @@ i18n = ["Babel (>=2.7)"] [[package]] name = "jsonschema" -version = "4.8.0" +version = "4.14.0" description = "An implementation of JSON Schema validation for Python" category = "main" optional = false @@ -285,6 +285,7 @@ python-versions = ">=3.7" attrs = ">=17.4.0" importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} importlib-resources = {version = ">=1.4.0", markers = "python_version < \"3.9\""} +pkgutil-resolve-name = {version = ">=1.3.10", markers = "python_version < \"3.9\""} pyrsistent = ">=0.14.0,<0.17.0 || >0.17.0,<0.17.1 || >0.17.1,<0.17.2 || >0.17.2" typing-extensions = {version = "*", markers = "python_version < \"3.8\""} @@ -310,7 +311,7 @@ python-versions = "*" [[package]] name = "more-itertools" -version = "8.13.0" +version = "8.14.0" description = "More routines for operating on iterables, beyond itertools" category = "main" optional = false @@ -343,6 +344,14 @@ category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +[[package]] +name = "pkgutil-resolve-name" +version = "1.3.10" +description = "Resolve a name to an object." +category = "main" +optional = false +python-versions = ">=3.6" + [[package]] name = "platformdirs" version = "2.5.2" @@ -546,7 +555,7 @@ testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2. [[package]] name = "python-bitcoinlib" -version = "0.11.0" +version = "0.11.2" description = "The Swiss Army Knife of the Bitcoin protocol." category = "main" optional = false @@ -586,7 +595,7 @@ python-versions = ">=3.7" [[package]] name = "werkzeug" -version = "2.2.1" +version = "2.2.2" description = "The comprehensive WSGI web application library." category = "main" optional = false @@ -778,10 +787,7 @@ mccabe = [ {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, ] -more-itertools = [ - {file = "more-itertools-8.13.0.tar.gz", hash = "sha256:a42901a0a5b169d925f6f217cd5a190e32ef54360905b9c39ee7db5313bfec0f"}, - {file = "more_itertools-8.13.0-py3-none-any.whl", hash = "sha256:c5122bffc5f104d37c1626b8615b511f3427aa5389b94d61e5ef8236bfbc3ddb"}, -] +more-itertools = [] mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, @@ -794,6 +800,7 @@ pathspec = [ {file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"}, {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"}, ] +pkgutil-resolve-name = [] platformdirs = [ {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"}, @@ -974,10 +981,7 @@ pytest = [ {file = "pytest-7.1.2-py3-none-any.whl", hash = "sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c"}, {file = "pytest-7.1.2.tar.gz", hash = "sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45"}, ] -python-bitcoinlib = [ - {file = "python-bitcoinlib-0.11.0.tar.gz", hash = "sha256:3daafd63cb755f6e2067b7c9c514053856034c9f9363c80c37007744d54a2e06"}, - {file = "python_bitcoinlib-0.11.0-py3-none-any.whl", hash = "sha256:6e7982734637135599e2136d3c88d622f147e3b29201636665f799365784cd9e"}, -] +python-bitcoinlib = [] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, diff --git a/tests/test_bolt2-01-close_channel.py b/tests/test_bolt2-01-close_channel.py index 7320799..4dbc793 100644 --- a/tests/test_bolt2-01-close_channel.py +++ b/tests/test_bolt2-01-close_channel.py @@ -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. @@ -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" @@ -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( @@ -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. @@ -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( @@ -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" @@ -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))