Browse Source

pytest: Strengthen the htlc_accepted tests

We were having a few issues with malformed data in the past, so this time we
really check that stuff.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pull/2938/head
Christian Decker 6 years ago
parent
commit
53488e5739
  1. 12
      tests/plugins/hold_htlcs.py
  2. 15
      tests/test_plugin.py

12
tests/plugins/hold_htlcs.py

@ -8,17 +8,27 @@ settled/forwarded/
from lightning import Plugin
import json
import os
import tempfile
import time
plugin = Plugin()
@plugin.hook("htlc_accepted")
def on_htlc_accepted(htlc, onion, plugin):
# Stash the onion so the test can check it
fname = os.path.join(tempfile.mkdtemp(), "onion.json")
with open(fname, 'w') as f:
f.write(json.dumps(onion))
plugin.log("Holding onto an incoming htlc for 10 seconds")
time.sleep(10)
print("Onion written to {}".format(fname))
# Give the tester something to look for
plugin.log("htlc_accepted hook called")
return {'result': 'continue'}

15
tests/test_plugin.py

@ -4,8 +4,10 @@ from flaky import flaky # noqa: F401
from lightning import RpcError, Millisatoshi
from utils import only_one, wait_for, TIMEOUT
import json
import os
import pytest
import re
import sqlite3
import subprocess
import time
@ -427,8 +429,21 @@ def test_htlc_accepted_hook_forward_restart(node_factory, executor):
f1 = executor.submit(l1.rpc.pay, i1)
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
l2.restart()
# Grab the file where the plugin wrote the onion and read it in for some
# additional checks
logline = l2.daemon.wait_for_log(r'Onion written to')
fname = re.search(r'Onion written to (.*\.json)', logline).group(1)
onion = json.load(open(fname))
assert re.match(r'^00006700000.000100000000000003e8000000..000000000000000000000000$', onion['payload'])
assert len(onion['payload']) == 64
assert len(onion['shared_secret']) == 64
assert onion['per_hop_v0']['realm'] == "00"
assert onion['per_hop_v0']['forward_amount'] == '1000msat'
assert len(onion['next_onion']) == 2 * (1300 + 32 + 33 + 1)
f1.result()

Loading…
Cancel
Save