Skip to content

Commit

Permalink
pytest: Add test for failcode conversion
Browse files Browse the repository at this point in the history
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 ElementsProject#4070
  • Loading branch information
cdecker committed Sep 23, 2020
1 parent 15adcc9 commit 97ca766
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1889,3 +1889,42 @@ def test_htlc_accepted_hook_crash(node_factory, executor):

with pytest.raises(RpcError, match=r'failed: WIRE_TEMPORARY_NODE_FAILURE'):
f.result(10)


def test_htlc_accepted_hook_failcodes(node_factory):
plugin = os.path.join(os.path.dirname(__file__), 'plugins/htlc_accepted-failcode.py')
l1, l2 = node_factory.line_graph(2, opts=[{}, {'plugin': plugin}])

# First let's test the newer failure_message, which should get passed
# through without being mapped.
tests = {
'2002': 'WIRE_TEMPORARY_NODE_FAILURE',
'400F' + 12 * '00': 'WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS',
'4009': 'WIRE_REQUIRED_CHANNEL_FEATURE_MISSING',
'4016' + 3 * '00': 'WIRE_INVALID_ONION_PAYLOAD',
}

for failmsg, expected in tests.items():
l2.rpc.setfailcode(msg=failmsg)
inv = l2.rpc.invoice(42, 'failmsg{}'.format(failmsg), '')['bolt11']
with pytest.raises(RpcError, match=r'failcodename.: .{}.'.format(expected)):
l1.rpc.pay(inv)

# And now test the older failcode return value. This is deprecated and can
# be removed once we have removed the failcode correction code in
# peer_htlcs.c. The following ones get remapped
tests.update({
'400F': 'WIRE_TEMPORARY_NODE_FAILURE',
'4009': 'WIRE_TEMPORARY_NODE_FAILURE',
'4016': 'WIRE_TEMPORARY_NODE_FAILURE',
})

for failcode, expected in tests.items():
# Do not attempt with full messages
if len(failcode) > 4:
continue

l2.rpc.setfailcode(code=failcode)
inv = l2.rpc.invoice(42, 'failcode{}'.format(failcode), '')['bolt11']
with pytest.raises(RpcError, match=r'failcodename.: .{}.'.format(expected)):
l1.rpc.pay(inv)

0 comments on commit 97ca766

Please sign in to comment.