-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest: Add test for failcode conversion
We added a conversion of failcodes that do not have sufficient information in faac4b2. That means that a failcode that'd require additional information in order to be a correct error to return in an onion is mapped to a generic one since we can't backfill the information. This tests that the mapping is performed correctly and replicates the situation in #4070
- Loading branch information
1 parent
980a951
commit 5a87e88
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
"""A simply plugin that fails HTLCs with a configurable failcode. | ||
""" | ||
from pyln.client import Plugin | ||
|
||
|
||
plugin = Plugin() | ||
|
||
|
||
@plugin.hook('htlc_accepted') | ||
def on_htlc_accepted(htlc, onion, plugin, **kwargs): | ||
res = {"result": "fail"} | ||
|
||
if plugin.failmsg is not None: | ||
res['failure_message'] = plugin.failmsg | ||
|
||
if plugin.failcode is not None: | ||
res['failure_code'] = plugin.failcode | ||
|
||
return res | ||
|
||
|
||
@plugin.method('setfailcode') | ||
def setfailcode(plugin, code=None, msg=None): | ||
"""Sets the failcode to return when receiving an incoming HTLC. | ||
""" | ||
plugin.failcode = code | ||
plugin.failmsg = msg | ||
|
||
|
||
@plugin.init() | ||
def on_init(**kwargs): | ||
plugin.failcode = None | ||
plugin.failmsg = None | ||
|
||
|
||
plugin.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters