Skip to content

Commit 50d72b1

Browse files
feat: Enable stashing of expected messages
There are cases where we need to access the message that was just decoded within the `ExpectMsg` event. This commit adds a generic method to the stash module, allowing retrieval of information from the message. Furthermore, starting from this point, lnprototest will stash all messages that are decoded using `ExpectMsg`. This enhancement simplifies cross-compatibility efforts with other implementations. Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent dea47c2 commit 50d72b1

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

lnprototest/dummyrunner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def has_option(self, optname: str) -> Optional[str]:
4949
def start(self) -> None:
5050
self.blockheight = 102
5151

52-
def stop(self) -> None:
52+
def stop(self, print_logs: bool = False) -> None:
5353
pass
5454

5555
def restart(self) -> None:

lnprototest/event.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def action(self, runner: "Runner") -> bool:
346346
# Might be completely unknown to namespace.
347347
try:
348348
msg = Message.read(namespace(), io.BytesIO(binmsg))
349+
runner.add_stash(msg.messagetype.name, msg)
349350
except ValueError as ve:
350351
raise EventError(
351352
self, "Runner gave bad msg {}: {}".format(binmsg.hex(), ve)

lnprototest/stash/__init__.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,5 @@
2828
htlc_sigs_to_recv,
2929
locking_script,
3030
witnesses,
31+
stash_field_from_event,
3132
)
32-
33-
34-
__all__ = [
35-
"commitsig_to_send",
36-
"commitsig_to_recv",
37-
"htlc_sigs_to_send",
38-
"htlc_sigs_to_recv",
39-
"channel_id",
40-
"channel_announcement",
41-
"channel_update",
42-
"get_member",
43-
"rcvd",
44-
"sent",
45-
"funding_amount",
46-
"funding_pubkey",
47-
"funding_tx",
48-
"funding_txid",
49-
"funding",
50-
"funding_close_tx",
51-
"locking_script",
52-
"witnesses",
53-
]

lnprototest/stash/stash.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,14 @@ def _funding_close_tx(runner: Runner, event: Event, field: str) -> str:
273273
return runner.get_stash(event, "Funding").close_tx()
274274

275275
return _funding_close_tx
276+
277+
278+
def stash_field_from_event(stash_key: str) -> Callable[[Runner, Event, str], str]:
279+
"""Generic stash function to get the information back from a previous event"""
280+
281+
def _stash_field_from_event(runner: Runner, event: Event, field: str) -> str:
282+
if runner._is_dummy():
283+
return "0"
284+
return runner.get_stash(event, stash_key).fields[field]
285+
286+
return _stash_field_from_event

tests/test_bolt2-01-open_channel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
funding_txid,
3434
funding_tx,
3535
funding,
36+
stash_field_from_event,
3637
)
3738
from helpers import (
3839
utxo,
@@ -110,7 +111,7 @@ def test_open_channel_from_accepter_side(runner: Runner) -> None:
110111
delayed_payment_basepoint=remote_delayed_payment_basepoint(),
111112
htlc_basepoint=remote_htlc_basepoint(),
112113
first_per_commitment_point=remote_per_commitment_point(0),
113-
minimum_depth=3,
114+
minimum_depth=stash_field_from_event("accept_channel"),
114115
channel_reserve_satoshis=9998,
115116
),
116117
# Ignore unknown odd messages

0 commit comments

Comments
 (0)