(node_factory, bitcoind, chainparams)
| 5041 | |
| 5042 | |
| 5043 | def test_pay_plugin_notifications(node_factory, bitcoind, chainparams): |
| 5044 | plugin = os.path.join(os.getcwd(), 'tests/plugins/all_notifications.py') |
| 5045 | opts = {"plugin": plugin, |
| 5046 | "xpay-handle-pay": False, |
| 5047 | "allow-deprecated-apis": True} |
| 5048 | |
| 5049 | l1, l2, l3 = node_factory.line_graph(3, opts=[opts, {}, {}], |
| 5050 | wait_for_announce=True) |
| 5051 | |
| 5052 | def zero_timestamps(obj): |
| 5053 | if isinstance(obj, dict): |
| 5054 | for k, v in obj.items(): |
| 5055 | if k == "timestamp": |
| 5056 | obj[k] = 0 |
| 5057 | else: |
| 5058 | zero_timestamps(v) |
| 5059 | elif isinstance(obj, list): |
| 5060 | for item in obj: |
| 5061 | zero_timestamps(item) |
| 5062 | # other types are ignored |
| 5063 | return obj |
| 5064 | |
| 5065 | inv1 = l3.rpc.invoice(20000, "first", "desc") |
| 5066 | l1.rpc.pay(inv1['bolt11']) |
| 5067 | |
| 5068 | # It gets a channel hint update notification |
| 5069 | line = l1.daemon.wait_for_log(f"plugin-all_notifications.py: notification channel_hint_update: ") |
| 5070 | dict_str = line.split("notification channel_hint_update: ", 1)[1] |
| 5071 | data = zero_timestamps(ast.literal_eval(dict_str)) |
| 5072 | |
| 5073 | channel_hint_update_core = {'scid': first_scid(l1, l2) + '/1', |
| 5074 | 'estimated_capacity_msat': 964719000 if chainparams['elements'] else 978718000, |
| 5075 | 'total_capacity_msat': 1000000000, |
| 5076 | 'timestamp': 0, |
| 5077 | 'enabled': True} |
| 5078 | channel_hint_update = {'origin': 'pay', |
| 5079 | 'channel_hint_update': channel_hint_update_core} |
| 5080 | # pyln-client's plugin.py duplicated payload into same name as update. |
| 5081 | channel_hint_update['payload'] = {'channel_hint': channel_hint_update_core} |
| 5082 | |
| 5083 | assert data == channel_hint_update |
| 5084 | |
| 5085 | # It gets a success notification |
| 5086 | line = l1.daemon.wait_for_log(f"plugin-all_notifications.py: notification pay_success: ") |
| 5087 | dict_str = line.split("notification pay_success: ", 1)[1] |
| 5088 | data = ast.literal_eval(dict_str) |
| 5089 | success_core = {'payment_hash': inv1['payment_hash'], |
| 5090 | 'bolt11': inv1['bolt11']} |
| 5091 | success = {'origin': 'pay', |
| 5092 | 'pay_success': success_core} |
| 5093 | # pyln-client's plugin.py duplicated payload into same name as update. |
| 5094 | success['payload'] = success_core |
| 5095 | assert data == success |
| 5096 | |
| 5097 | inv2 = l3.rpc.invoice(10000, "second", "desc") |
| 5098 | l3.rpc.delinvoice('second', 'unpaid') |
| 5099 | with pytest.raises(RpcError, match="WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS"): |
| 5100 | l1.rpc.pay(inv2['bolt11']) |
nothing calls this directly
no test coverage detected