mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
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>
This commit is contained in:
parent
a6516f477b
commit
53488e5739
2 changed files with 26 additions and 1 deletions
|
@ -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'}
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue