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

Function test_attempt_notifications

tests/test_xpay.py:816–958  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

814
815
816def test_attempt_notifications(node_factory):
817 def zero_fields(obj, fieldnames):
818 if isinstance(obj, dict):
819 for k, v in obj.items():
820 if k in fieldnames:
821 obj[k] = 0
822 else:
823 zero_fields(v, fieldnames)
824 elif isinstance(obj, list):
825 for item in obj:
826 zero_fields(item, fieldnames)
827 # other types are ignored
828 return obj
829
830 plugin_path = os.path.join(os.getcwd(), 'tests/plugins/custom_notifications.py')
831 l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True,
832 opts=[{"plugin": plugin_path}, {}, {}])
833
834 scid12 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['short_channel_id']
835 scid12_dir = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['direction']
836 scid23 = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['short_channel_id']
837 scid23_dir = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['direction']
838 inv1 = l3.rpc.invoice(5000000, 'test_attempt_notifications1', 'test_attempt_notifications1')
839 l1.rpc.xpay(inv1['bolt11'])
840
841 line = l1.daemon.wait_for_log("plugin-custom_notifications.py: Got pay_part_start: ")
842 dict_str = line.split("Got pay_part_start: ", 1)[1]
843 data = zero_fields(ast.literal_eval(dict_str), ['groupid'])
844 expected = {'pay_part_start':
845 {'payment_hash': inv1['payment_hash'],
846 'groupid': 0,
847 'partid': 1,
848 'total_payment_msat': 5000000,
849 'attempt_msat': 5000000,
850 'hops': [{'next_node': l2.info['id'],
851 'short_channel_id': scid12,
852 'direction': scid12_dir,
853 'channel_in_msat': 5000051,
854 'channel_out_msat': 5000051},
855 {'next_node': l3.info['id'],
856 'short_channel_id': scid23,
857 'direction': scid23_dir,
858 'channel_in_msat': 5000051,
859 'channel_out_msat': 5000000}]}}
860 assert data == expected
861
862 line = l1.daemon.wait_for_log("plugin-custom_notifications.py: Got pay_part_end: ")
863 dict_str = line.split("Got pay_part_end: ", 1)[1]
864 data = zero_fields(ast.literal_eval(dict_str), ('duration', 'groupid'))
865 expected = {'pay_part_end':
866 {'payment_hash': inv1['payment_hash'],
867 'status': 'success',
868 'duration': 0,
869 'groupid': 0,
870 'partid': 1}}
871 assert data == expected
872
873 inv2 = l3.rpc.invoice(10000000, 'test_attempt_notifications2', 'test_attempt_notifications2')

Callers

nothing calls this directly

Calls 10

only_oneFunction · 0.90
zero_fieldsFunction · 0.85
joinMethod · 0.80
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
wait_for_logMethod · 0.80
delinvoiceMethod · 0.80
invoiceMethod · 0.45
xpayMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected