(node_factory, executor)
| 6715 | |
| 6716 | |
| 6717 | def test_injectpaymentonion_failures(node_factory, executor): |
| 6718 | l1, l2 = node_factory.line_graph(2, wait_for_announce=True) |
| 6719 | blockheight = l1.rpc.getinfo()['blockheight'] |
| 6720 | |
| 6721 | # |
| 6722 | # Failure cases should give an onion: |
| 6723 | # Unknown invoice. |
| 6724 | # Unknown invoice (selfpay) |
| 6725 | # Cannot forward. |
| 6726 | |
| 6727 | # Unknown invoice |
| 6728 | hops = [{'pubkey': l1.info['id'], |
| 6729 | 'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()}, |
| 6730 | {'pubkey': l2.info['id'], |
| 6731 | 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, '00' * 32).hex()}] |
| 6732 | onion = l1.rpc.createonion(hops=hops, assocdata='00' * 32) |
| 6733 | |
| 6734 | with pytest.raises(RpcError) as err: |
| 6735 | l1.rpc.injectpaymentonion(onion=onion['onion'], |
| 6736 | payment_hash='00' * 32, |
| 6737 | amount_msat=1000, |
| 6738 | cltv_expiry=blockheight + 18 + 6, |
| 6739 | partid=1, |
| 6740 | groupid=0) |
| 6741 | |
| 6742 | # PAY_INJECTPAYMENTONION_FAILED |
| 6743 | assert err.value.error['code'] == 218 |
| 6744 | assert 'onionreply' in err.value.error['data'] |
| 6745 | |
| 6746 | # Self-pay (unknown payment_hash) |
| 6747 | hops = [{'pubkey': l1.info['id'], |
| 6748 | 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, '00' * 32).hex()}] |
| 6749 | onion = l1.rpc.createonion(hops=hops, assocdata='00' * 32) |
| 6750 | |
| 6751 | with pytest.raises(RpcError) as err: |
| 6752 | l1.rpc.injectpaymentonion(onion=onion['onion'], |
| 6753 | payment_hash='00' * 32, |
| 6754 | amount_msat=1000, |
| 6755 | cltv_expiry=blockheight + 18 + 6, |
| 6756 | partid=1, |
| 6757 | groupid=1) |
| 6758 | |
| 6759 | # PAY_INJECTPAYMENTONION_FAILED |
| 6760 | assert err.value.error['code'] == 218 |
| 6761 | assert 'onionreply' in err.value.error['data'] |
| 6762 | |
| 6763 | # Insufficient funds (l2 can't pay to l1) |
| 6764 | inv11 = l1.rpc.invoice(3000, "test_injectpaymentonion11", "test_injectpaymentonion11") |
| 6765 | hops = [{'pubkey': l2.info['id'], |
| 6766 | 'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()}, |
| 6767 | {'pubkey': l1.info['id'], |
| 6768 | 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, inv11['payment_secret']).hex()}] |
| 6769 | onion = l1.rpc.createonion(hops=hops, assocdata=inv11['payment_hash']) |
| 6770 | |
| 6771 | with pytest.raises(RpcError) as err: |
| 6772 | l2.rpc.injectpaymentonion(onion=onion['onion'], |
| 6773 | payment_hash=inv11['payment_hash'], |
| 6774 | amount_msat=1000, |
nothing calls this directly
no test coverage detected