@ -14,6 +14,7 @@ import sqlite3
import string
import sys
import tempfile
import threading
import time
import unittest
import utils
@ -195,21 +196,38 @@ class LightningDTests(BaseLightningDTests):
l1 . daemon . wait_for_log ( ' -> CHANNELD_NORMAL ' )
l2 . daemon . wait_for_log ( ' -> CHANNELD_NORMAL ' )
def pay ( self , lsrc , ldst , amt , label = None ) :
def pay ( self , lsrc , ldst , amt , label = None , async = False ) :
if not label :
label = ' ' . join ( random . choice ( string . ascii_letters + string . digits ) for _ in range ( 20 ) )
rhash = ldst . rpc . invoice ( amt , label ) [ ' rhash ' ]
assert ldst . rpc . listinvoice ( label ) [ 0 ] [ ' complete ' ] == False
routestep = {
' msatoshi ' : amt ,
' id ' : ldst . info [ ' id ' ] ,
' delay ' : 5 ,
' channel ' : ' 1:1:1 '
}
lsrc . rpc . sendpay ( to_json ( [ routestep ] ) , rhash )
assert ldst . rpc . listinvoice ( label ) [ 0 ] [ ' complete ' ] == True
def call_pay ( ) :
routestep = {
' msatoshi ' : amt ,
' id ' : ldst . info [ ' id ' ] ,
' delay ' : 5 ,
' channel ' : ' 1:1:1 '
}
lsrc . rpc . sendpay ( to_json ( [ routestep ] ) , rhash , async = False )
t = threading . Thread ( target = call_pay )
t . daemon = True
t . start ( )
def wait_pay ( ) :
# Up to 10 seconds for payment to succeed.
start_time = time . time ( )
while not ldst . rpc . listinvoice ( label ) [ 0 ] [ ' complete ' ] :
if time . time ( ) > start_time + 10 :
raise TimeoutError ( ' Payment timed out ' )
time . sleep ( 0.1 )
if async :
return self . executor . submit ( wait_pay )
else :
return wait_pay ( )
def test_connect ( self ) :
l1 , l2 = self . connect ( )