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

Function test_sendpay

tests/test_pay.py:499–635  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

497
498
499def test_sendpay(node_factory):
500 l1, l2 = node_factory.line_graph(2, fundamount=10**6)
501
502 amt = 200000000
503 inv = l2.rpc.invoice(amt, 'testpayment2', 'desc')
504 rhash = inv['payment_hash']
505
506 def invoice_unpaid(dst, label):
507 invoices = dst.rpc.listinvoices(label)['invoices']
508 return len(invoices) == 1 and invoices[0]['status'] == 'unpaid'
509
510 routestep = {
511 'amount_msat': amt,
512 'id': l2.info['id'],
513 'delay': 5,
514 'channel': first_scid(l1, l2)
515 }
516
517 # Insufficient funds.
518 with pytest.raises(RpcError):
519 rs = copy.deepcopy(routestep)
520 rs['amount_msat'] = rs['amount_msat'] - 1
521 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
522 l1.rpc.waitsendpay(rhash)
523 assert invoice_unpaid(l2, 'testpayment2')
524
525 # Gross overpayment (more than factor of 2)
526 with pytest.raises(RpcError):
527 rs = copy.deepcopy(routestep)
528 rs['amount_msat'] = rs['amount_msat'] * 2 + 1
529 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
530 l1.rpc.waitsendpay(rhash)
531 assert invoice_unpaid(l2, 'testpayment2')
532
533 # Insufficient delay.
534 with pytest.raises(RpcError):
535 rs = copy.deepcopy(routestep)
536 rs['delay'] = rs['delay'] - 2
537 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
538 l1.rpc.waitsendpay(rhash)
539 assert invoice_unpaid(l2, 'testpayment2')
540
541 # Bad ID.
542 l1.rpc.check_request_schemas = False
543 with pytest.raises(RpcError):
544 rs = copy.deepcopy(routestep)
545 rs['id'] = '00000000000000000000000000000000'
546 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
547 assert invoice_unpaid(l2, 'testpayment2')
548 l1.rpc.check_request_schemas = True
549
550 # Bad payment_secret
551 l1.rpc.sendpay([routestep], rhash, payment_secret="00" * 32)
552 with pytest.raises(RpcError):
553 l1.rpc.waitsendpay(rhash)
554 assert invoice_unpaid(l2, 'testpayment2')
555
556 # Missing payment_secret

Callers

nothing calls this directly

Calls 13

first_scidFunction · 0.90
only_oneFunction · 0.90
wait_forFunction · 0.90
invoice_unpaidFunction · 0.85
line_graphMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
listpeerchannelsMethod · 0.80
is_in_logMethod · 0.80
wait_for_logMethod · 0.80
listsendpaysMethod · 0.80
invoiceMethod · 0.45

Tested by

no test coverage detected