Browse Source

Plugins: Add a test for the 'invoice_payment' notfication

pull/2938/head
darosior 6 years ago
committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent
commit
34533ead68
  1. 8
      contrib/plugins/helloworld.py
  2. 18
      tests/test_plugin.py

8
contrib/plugins/helloworld.py

@ -34,6 +34,14 @@ def on_disconnect(plugin, id):
plugin.log("Received disconnect event for peer {}".format(id))
@plugin.subscribe("invoice_payment")
def on_payment(plugin, invoice_payment):
plugin.log("Received invoice_payment event for label {}, preimage {},"
" and amount of {}".format(invoice_payment.get("label"),
invoice_payment.get("preimage"),
invoice_payment.get("msat")))
@plugin.hook("htlc_accepted")
def on_htlc_accepted(onion, htlc, plugin):
plugin.log('on_htlc_accepted called')

18
tests/test_plugin.py

@ -476,3 +476,21 @@ def test_warning_notification(node_factory):
l1.daemon.wait_for_log('plugin-pretend_badlog.py time: *')
l1.daemon.wait_for_log('plugin-pretend_badlog.py source: plugin-pretend_badlog.py')
l1.daemon.wait_for_log('plugin-pretend_badlog.py log: Test warning notification\\(for broken event\\)')
def test_invoice_payment_notification(node_factory):
"""
Test the 'invoice_payment' notification
"""
opts = [{}, {"plugin": "contrib/plugins/helloworld.py"}]
l1, l2 = node_factory.line_graph(2, opts=opts)
msats = 12345
preimage = '1' * 64
label = "a_descriptive_label"
inv1 = l2.rpc.invoice(msats, label, 'description', preimage=preimage)
l1.rpc.pay(inv1['bolt11'])
l2.daemon.wait_for_log(r"Received invoice_payment event for label {},"
" preimage {}, and amount of {}msat"
.format(label, preimage, msats))

Loading…
Cancel
Save