Skip to content

Commit

Permalink
Merge pull request #94 from Psycho-Pirate/feature_function
Browse files Browse the repository at this point in the history
fix: runner_features added in runner.py and tests modified
  • Loading branch information
vincenzopalazzo committed Jul 11, 2023
2 parents e51fb97 + 0dc5ddd commit 4251a32
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
14 changes: 14 additions & 0 deletions lnprototest/runner.py
Expand Up @@ -6,6 +6,7 @@
import coincurve
import functools

from .bitfield import bitfield
from .errors import SpecFileError
from .structure import Sequence
from .event import Event, MustNotMsg, ExpectMsg
Expand Down Expand Up @@ -120,6 +121,19 @@ def teardown(self):
and it is used to clean up the root dir where the tests are run."""
shutil.rmtree(self.directory)

def runner_features(
self,
additional_features: Optional[List[int]] = None,
globals: bool = False,
) -> str:
"""
Provide the features required by the node.
"""
if additional_features is None:
return ""
else:
return bitfield(*additional_features)

@abstractmethod
def is_running(self) -> bool:
"""Return a boolean value that tells whether the runner is running
Expand Down
18 changes: 11 additions & 7 deletions lnprototest/utils/ln_spec_utils.py
Expand Up @@ -49,12 +49,11 @@ def connect_to_node_helper(
runner: "Runner",
tx_spendable: str,
conn_privkey: str = "02",
global_features: Optional[str] = None,
features: Optional[str] = None,
global_features: Optional[List[int]] = None,
features: Optional[List[int]] = None,
) -> List["Event"]:
"""Helper function to make a connection with the node"""
from lnprototest.utils.bitcoin_utils import tx_spendable
from lnprototest.stash import stash_field_from_event
from lnprototest import (
Connect,
Block,
Expand All @@ -68,12 +67,17 @@ def connect_to_node_helper(
ExpectMsg("init"),
Msg(
"init",
globalfeatures=stash_field_from_event("init", dummy_val="")
globalfeatures=runner.runner_features(globals=True)
if global_features is None
else global_features,
features=stash_field_from_event("init", dummy_val="")
else (
runner.runner_features(
global_features,
globals=True,
)
),
features=runner.runner_features()
if features is None
else features,
else (runner.runner_features(features)),
),
]

Expand Down
12 changes: 9 additions & 3 deletions tests/test_bolt2-01-close_channel.py
Expand Up @@ -56,7 +56,9 @@ def test_close_channel_shutdown_msg_normal_case_receiver_side(runner: Runner) ->
# 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"
runner=runner,
tx_spendable=tx_spendable,
conn_privkey="03",
)
pre_events = open_and_announce_channel_helper(
runner, conn_privkey="03", opts=test_opts
Expand Down Expand Up @@ -105,7 +107,9 @@ def test_close_channel_shutdown_msg_normal_case_sender_side(runner: Runner) -> N
# 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"
runner=runner,
tx_spendable=tx_spendable,
conn_privkey="03",
)
pre_events = open_and_announce_channel_helper(
runner, conn_privkey="03", opts=test_opts
Expand Down Expand Up @@ -140,7 +144,9 @@ def test_close_channel_shutdown_msg_wrong_script_pubkey_receiver_side(
# 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"
runner=runner,
tx_spendable=tx_spendable,
conn_privkey="03",
)
pre_events = open_and_announce_channel_helper(
runner, conn_privkey="03", opts=test_opts
Expand Down
8 changes: 6 additions & 2 deletions tests/test_bolt2-01-open_channel.py
Expand Up @@ -74,7 +74,9 @@ def test_open_channel_from_accepter_side(runner: Runner) -> None:
local_funding_privkey = "20"
local_keyset = gen_random_keyset(int(local_funding_privkey))
connections_events = connect_to_node_helper(
runner=runner, tx_spendable=tx_spendable, conn_privkey="02"
runner=runner,
tx_spendable=tx_spendable,
conn_privkey="02",
)

# Accepter side: we initiate a new channel.
Expand Down Expand Up @@ -179,7 +181,9 @@ def test_open_channel_opener_side(runner: Runner) -> None:
local_funding_privkey = "20"
local_keyset = gen_random_keyset(int(local_funding_privkey))
connections_events = connect_to_node_helper(
runner=runner, tx_spendable=tx_spendable, conn_privkey="02"
runner=runner,
tx_spendable=tx_spendable,
conn_privkey="02",
)

# Now we test the 'opener' side of an open_channel (node initiates)
Expand Down

0 comments on commit 4251a32

Please sign in to comment.