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

Function test_sendpay

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

Source from the content-addressed store, hash-verified

559
560
561def test_sendpay(node_factory):
562 l1, l2 = node_factory.line_graph(2, fundamount=10**6)
563
564 amt = 200000000
565 inv = l2.rpc.invoice(amt, 'testpayment2', 'desc')
566 rhash = inv['payment_hash']
567
568 def invoice_unpaid(dst, label):
569 invoices = dst.rpc.listinvoices(label)['invoices']
570 return len(invoices) == 1 and invoices[0]['status'] == 'unpaid'
571
572 routestep = {
573 'amount_msat': amt,
574 'id': l2.info['id'],
575 'delay': 5,
576 'channel': first_scid(l1, l2)
577 }
578
579 # Insufficient funds.
580 with pytest.raises(RpcError):
581 rs = copy.deepcopy(routestep)
582 rs['amount_msat'] = rs['amount_msat'] - 1
583 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
584 l1.rpc.waitsendpay(rhash)
585 assert invoice_unpaid(l2, 'testpayment2')
586
587 # Gross overpayment (more than factor of 2)
588 with pytest.raises(RpcError):
589 rs = copy.deepcopy(routestep)
590 rs['amount_msat'] = rs['amount_msat'] * 2 + 1
591 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
592 l1.rpc.waitsendpay(rhash)
593 assert invoice_unpaid(l2, 'testpayment2')
594
595 # Insufficient delay.
596 with pytest.raises(RpcError):
597 rs = copy.deepcopy(routestep)
598 rs['delay'] = rs['delay'] - 2
599 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
600 l1.rpc.waitsendpay(rhash)
601 assert invoice_unpaid(l2, 'testpayment2')
602
603 # Bad ID.
604 l1.rpc.check_request_schemas = False
605 with pytest.raises(RpcError):
606 rs = copy.deepcopy(routestep)
607 rs['id'] = '00000000000000000000000000000000'
608 l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret'])
609 assert invoice_unpaid(l2, 'testpayment2')
610 l1.rpc.check_request_schemas = True
611
612 # Bad payment_secret
613 l1.rpc.sendpay([routestep], rhash, payment_secret="00" * 32)
614 with pytest.raises(RpcError):
615 l1.rpc.waitsendpay(rhash)
616 assert invoice_unpaid(l2, 'testpayment2')
617
618 # 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
is_in_logMethod · 0.80
wait_for_logMethod · 0.80
listsendpaysMethod · 0.80
invoiceMethod · 0.45
getpeerMethod · 0.45

Tested by

no test coverage detected