Skip to content

Commit 5b6c823

Browse files
rustyrussellcdecker
authored andcommitted
pytest: test that we get a correct result when peer says onion is bad.
Currently fails: we get a garbage error. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e0621fa commit 5b6c823

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/test_misc.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,3 +1135,44 @@ def test_check_command(node_factory):
11351135
assert 'error' in obj
11361136

11371137
sock.close()
1138+
1139+
1140+
@pytest.mark.xfail(strict=True)
1141+
def test_bad_onion(node_factory, bitcoind):
1142+
"""Test that we get a reasonable error from sendpay when an onion is bad"""
1143+
l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True)
1144+
1145+
h = l4.rpc.invoice(123000, 'test_bad_onion', 'description')['payment_hash']
1146+
route = l1.rpc.getroute(l4.info['id'], 123000, 1)['route']
1147+
1148+
assert len(route) == 3
1149+
1150+
mangled_nodeid = '0265b6ab5ec860cd257865d61ef0bbf5b3339c36cbda8b26b74e7f1dca490b6518'
1151+
1152+
# Replace id with a different pubkey, so onion encoded badly at third hop.
1153+
route[2]['id'] = mangled_nodeid
1154+
l1.rpc.sendpay(route, h)
1155+
with pytest.raises(RpcError) as err:
1156+
l1.rpc.waitsendpay(h)
1157+
1158+
# FIXME: #define PAY_TRY_OTHER_ROUTE 204
1159+
PAY_TRY_OTHER_ROUTE = 204
1160+
assert err.value.error['code'] == PAY_TRY_OTHER_ROUTE
1161+
# FIXME: WIRE_INVALID_ONION_HMAC = BADONION|PERM|5
1162+
WIRE_INVALID_ONION_HMAC = 0x8000 | 0x4000 | 5
1163+
assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC
1164+
assert err.value.error['data']['erring_node'] == mangled_nodeid
1165+
assert err.value.error['data']['erring_channel'] == route[2]['channel']
1166+
1167+
# Replace id with a different pubkey, so onion encoded badly at second hop.
1168+
route[1]['id'] = mangled_nodeid
1169+
l1.rpc.sendpay(route, h)
1170+
with pytest.raises(RpcError) as err:
1171+
l1.rpc.waitsendpay(h)
1172+
1173+
# FIXME: #define PAY_TRY_OTHER_ROUTE 204
1174+
PAY_TRY_OTHER_ROUTE = 204
1175+
assert err.value.error['code'] == PAY_TRY_OTHER_ROUTE
1176+
assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC
1177+
assert err.value.error['data']['erring_node'] == mangled_nodeid
1178+
assert err.value.error['data']['erring_channel'] == route[1]['channel']

0 commit comments

Comments
 (0)