(node_factory, executor)
| 6787 | |
| 6788 | |
| 6789 | def test_injectpaymentonion_failures(node_factory, executor): |
| 6790 | l1, l2 = node_factory.line_graph(2, wait_for_announce=True) |
| 6791 | blockheight = l1.rpc.getinfo()['blockheight'] |
| 6792 | |
| 6793 | # |
| 6794 | # Failure cases should give an onion: |
| 6795 | # Unknown invoice. |
| 6796 | # Unknown invoice (selfpay) |
| 6797 | # Cannot forward. |
| 6798 | |
| 6799 | # Unknown invoice |
| 6800 | hops = [{'pubkey': l1.info['id'], |
| 6801 | 'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()}, |
| 6802 | {'pubkey': l2.info['id'], |
| 6803 | 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, '00' * 32).hex()}] |
| 6804 | onion = l1.rpc.createonion(hops=hops, assocdata='00' * 32) |
| 6805 | |
| 6806 | with pytest.raises(RpcError) as err: |
| 6807 | l1.rpc.injectpaymentonion(onion=onion['onion'], |
| 6808 | payment_hash='00' * 32, |
| 6809 | amount_msat=1000, |
| 6810 | cltv_expiry=blockheight + 18 + 6, |
| 6811 | partid=1, |
| 6812 | groupid=0) |
| 6813 | |
| 6814 | # PAY_INJECTPAYMENTONION_FAILED |
| 6815 | assert err.value.error['code'] == 218 |
| 6816 | assert 'onionreply' in err.value.error['data'] |
| 6817 | |
| 6818 | # Self-pay (unknown payment_hash) |
| 6819 | hops = [{'pubkey': l1.info['id'], |
| 6820 | 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, '00' * 32).hex()}] |
| 6821 | onion = l1.rpc.createonion(hops=hops, assocdata='00' * 32) |
| 6822 | |
| 6823 | with pytest.raises(RpcError) as err: |
| 6824 | l1.rpc.injectpaymentonion(onion=onion['onion'], |
| 6825 | payment_hash='00' * 32, |
| 6826 | amount_msat=1000, |
| 6827 | cltv_expiry=blockheight + 18 + 6, |
| 6828 | partid=1, |
| 6829 | groupid=1) |
| 6830 | |
| 6831 | # PAY_INJECTPAYMENTONION_FAILED |
| 6832 | assert err.value.error['code'] == 218 |
| 6833 | assert 'onionreply' in err.value.error['data'] |
| 6834 | |
| 6835 | # Insufficient funds (l2 can't pay to l1) |
| 6836 | inv11 = l1.rpc.invoice(3000, "test_injectpaymentonion11", "test_injectpaymentonion11") |
| 6837 | hops = [{'pubkey': l2.info['id'], |
| 6838 | 'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()}, |
| 6839 | {'pubkey': l1.info['id'], |
| 6840 | 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, inv11['payment_secret']).hex()}] |
| 6841 | onion = l1.rpc.createonion(hops=hops, assocdata=inv11['payment_hash']) |
| 6842 | |
| 6843 | with pytest.raises(RpcError) as err: |
| 6844 | l2.rpc.injectpaymentonion(onion=onion['onion'], |
| 6845 | payment_hash=inv11['payment_hash'], |
| 6846 | amount_msat=1000, |
nothing calls this directly
no test coverage detected