test_lightningd.py: make pay helper use random label if we don't care.

Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-07-05 15:03:40 +09:30
parent a87d50acc9
commit f04222cb12

View file

@ -8,8 +8,10 @@ import copy
import json import json
import logging import logging
import os import os
import sys import random
import sqlite3 import sqlite3
import string
import sys
import tempfile import tempfile
import time import time
import unittest import unittest
@ -174,7 +176,7 @@ class LightningDTests(BaseLightningDTests):
l2.daemon.wait_for_log('WIRE_GOSSIPCTL_NEW_PEER') l2.daemon.wait_for_log('WIRE_GOSSIPCTL_NEW_PEER')
return l1,l2 return l1,l2
def fund_channel(self,l1,l2,amount): def fund_channel(self, l1, l2, amount):
addr = l1.rpc.newaddr()['address'] addr = l1.rpc.newaddr()['address']
txid = l1.bitcoin.rpc.sendtoaddress(addr, amount / 10**8 + 0.01) txid = l1.bitcoin.rpc.sendtoaddress(addr, amount / 10**8 + 0.01)
@ -190,7 +192,10 @@ class LightningDTests(BaseLightningDTests):
l1.daemon.wait_for_log('-> CHANNELD_NORMAL') l1.daemon.wait_for_log('-> CHANNELD_NORMAL')
l2.daemon.wait_for_log('-> CHANNELD_NORMAL') l2.daemon.wait_for_log('-> CHANNELD_NORMAL')
def pay(self,lsrc,ldst,amt,label): def pay(self, lsrc, ldst, amt, label=None):
if not label:
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
rhash = ldst.rpc.invoice(amt, label)['rhash'] rhash = ldst.rpc.invoice(amt, label)['rhash']
assert ldst.rpc.listinvoice(label)[0]['complete'] == False assert ldst.rpc.listinvoice(label)[0]['complete'] == False
@ -311,7 +316,7 @@ class LightningDTests(BaseLightningDTests):
l1,l2 = self.connect() l1,l2 = self.connect()
self.fund_channel(l1, l2, 10**6) self.fund_channel(l1, l2, 10**6)
self.pay(l1,l2,200000000,'testpayment2') self.pay(l1,l2,200000000)
assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0 assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0
@ -706,7 +711,7 @@ class LightningDTests(BaseLightningDTests):
l1.rpc.connect('localhost', l2.info['port'], l2.info['id']) l1.rpc.connect('localhost', l2.info['port'], l2.info['id'])
self.fund_channel(l1, l2, 10**6) self.fund_channel(l1, l2, 10**6)
self.pay(l1,l2,200000000,'testpayment2') self.pay(l1,l2,200000000)
assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0 assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0
@ -733,7 +738,7 @@ class LightningDTests(BaseLightningDTests):
l1.rpc.connect('localhost', l2.info['port'], l2.info['id']) l1.rpc.connect('localhost', l2.info['port'], l2.info['id'])
self.fund_channel(l1, l2, 10**6) self.fund_channel(l1, l2, 10**6)
self.pay(l1,l2,200000000,'testpayment2') self.pay(l1,l2,200000000)
assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0 assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0