MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_keysend

Function test_keysend

tests/test_pay.py:3505–3560  ·  view source on GitHub ↗
(node_factory, keysendcmd)

Source from the content-addressed store, hash-verified

3503
3504@pytest.mark.parametrize("keysendcmd", ["keysend", "xkeysend"])
3505def test_keysend(node_factory, keysendcmd):
3506 amt = 10000
3507 if keysendcmd == 'keysend':
3508 opts = {'allow-deprecated-apis': True}
3509 else:
3510 opts = {}
3511 l1, l2, l3, l4 = node_factory.line_graph(
3512 4,
3513 wait_for_announce=True,
3514 opts=[opts, {}, opts, {'disable-plugin': 'keysend'}]
3515 )
3516
3517 if keysendcmd == 'xkeysend':
3518 l1keysend = l1.rpc.xkeysend
3519 else:
3520 l1keysend = l1.rpc.keysend
3521
3522 # The keysend featurebit must be set in the announcement, i.e., l1 should
3523 # learn that l3 supports keysends.
3524 features = l1.rpc.listnodes(l3.info['id'])['nodes'][0]['features']
3525 assert(int(features, 16) >> 55 & 0x01 == 1)
3526
3527 # If we disable keysend, then the featurebit must not be set,
3528 # i.e., l4 doesn't support it.
3529 features = l1.rpc.listnodes(l4.info['id'])['nodes'][0]['features']
3530 assert(int(features, 16) >> 55 & 0x01 == 0)
3531
3532 # Self-sends are not allowed (see #4438)
3533 with pytest.raises(RpcError, match=r'We are the destination.'):
3534 l1keysend(l1.info['id'], amt)
3535
3536 # Send an indirect one from l1 to l3
3537 l1keysend(l3.info['id'], amt)
3538 invs = l3.rpc.listinvoices()['invoices']
3539 assert(len(invs) == 1)
3540
3541 inv = invs[0]
3542 print(inv)
3543 assert(inv['amount_received_msat'] >= Millisatoshi(amt))
3544
3545 # Now send a direct one instead from l1 to l2
3546 l1keysend(l2.info['id'], amt)
3547 invs = l2.rpc.listinvoices()['invoices']
3548 assert(len(invs) == 1)
3549
3550 inv = invs[0]
3551 assert(inv['amount_received_msat'] >= Millisatoshi(amt))
3552
3553 # And finally try to send a keysend payment to l4, which doesn't
3554 # support it. It MUST fail.
3555 if keysendcmd == 'xkeysend':
3556 with pytest.raises(RpcError, match=r"Destination reported invalid_onion_payload \(likely doesn't support keysend\)"):
3557 l3.rpc.xkeysend(l4.info['id'], amt)
3558 else:
3559 with pytest.raises(RpcError, match=r"Recipient [0-9a-f]{66} reported an invalid payload"):
3560 l3.rpc.keysend(l4.info['id'], amt)
3561
3562

Callers

nothing calls this directly

Calls 6

MillisatoshiClass · 0.90
line_graphMethod · 0.80
keysendMethod · 0.80
listnodesMethod · 0.45
listinvoicesMethod · 0.45
xkeysendMethod · 0.45

Tested by

no test coverage detected