pytest: don't use deprecated options for close() in tests.

Only downside is you have to wait 1 second at least before
unilaterally closing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-08-08 16:18:44 +09:30
parent 83e654a106
commit 0edc0ae5e9
3 changed files with 29 additions and 43 deletions

View file

@ -13,7 +13,7 @@ import unittest
@unittest.skipIf(not DEVELOPER, "Too slow without --dev-bitcoind-poll")
def test_closing(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, opts={'allow-deprecated-apis': True})
l1, l2 = node_factory.line_graph(2)
chan = l1.get_channel_scid(l2)
l1.pay(l2, 200000000)
@ -38,9 +38,7 @@ def test_closing(node_factory, bitcoind):
# check for the substring
assert 'CHANNELD_NORMAL:Funding transaction locked.' in billboard[0]
# This should return with an error, then close.
with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):
l1.rpc.close(chan, False, 0)
l1.rpc.close(chan)
l1.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
l2.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
@ -97,19 +95,20 @@ def test_closing(node_factory, bitcoind):
assert l2.db_query("SELECT count(*) as c FROM channels;")[0]['c'] == 1
def test_closing_while_disconnected(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True, 'allow-deprecated-apis': True})
def test_closing_while_disconnected(node_factory, bitcoind, executor):
l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True})
chan = l1.get_channel_scid(l2)
l1.pay(l2, 200000000)
l2.stop()
# The close should still be triggered afterwards.
with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):
l1.rpc.close(chan, False, 0)
fut = executor.submit(l1.rpc.close, chan, 0)
l1.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
l2.start()
fut.result(TIMEOUT)
l1.daemon.wait_for_log(' to CLOSINGD_SIGEXCHANGE')
l2.daemon.wait_for_log(' to CLOSINGD_SIGEXCHANGE')
@ -147,7 +146,7 @@ def test_closing_id(node_factory):
@unittest.skipIf(not DEVELOPER, "needs dev-rescan-outputs")
def test_closing_torture(node_factory, executor, bitcoind):
l1, l2 = node_factory.get_nodes(2, opts={'allow-deprecated-apis': True})
l1, l2 = node_factory.get_nodes(2)
amount = 10**6
# Before the fix was applied, 15 would often pass.
@ -181,8 +180,8 @@ def test_closing_torture(node_factory, executor, bitcoind):
l2.wait_channel_active(scid)
# Start closers: can take a long time under valgrind!
c1 = executor.submit(l1.rpc.close, l2.info['id'], False, 60)
c2 = executor.submit(l2.rpc.close, l1.info['id'], False, 60)
c1 = executor.submit(l1.rpc.close, l2.info['id'])
c2 = executor.submit(l2.rpc.close, l1.info['id'])
# Wait for close to finish
c1.result(TIMEOUT)
c2.result(TIMEOUT)
@ -197,7 +196,7 @@ def test_closing_torture(node_factory, executor, bitcoind):
@unittest.skipIf(SLOW_MACHINE and VALGRIND, "slow test")
def test_closing_different_fees(node_factory, bitcoind, executor):
l1 = node_factory.get_node(options={'allow-deprecated-apis': True})
l1 = node_factory.get_node()
# Default feerate = 15000/7500/1000
# It will start at the second number, accepting anything above the first.
@ -215,7 +214,7 @@ def test_closing_different_fees(node_factory, bitcoind, executor):
peers = []
for feerate in feerates:
for amount in amounts:
p = node_factory.get_node(feerates=feerate, options={'allow-deprecated-apis': True})
p = node_factory.get_node(feerates=feerate)
p.feerate = feerate
p.amount = amount
l1.rpc.connect(p.info['id'], 'localhost', p.port)
@ -235,13 +234,8 @@ def test_closing_different_fees(node_factory, bitcoind, executor):
if p.amount != 0:
l1.pay(p, 100000000)
# Now close all channels
# All closes occur in parallel, and on Travis,
# ALL those lightningd are running on a single core,
# so increase the timeout so that this test will pass
# when valgrind is enabled.
# (close timeout defaults to 30 as of this writing)
closes = [executor.submit(l1.rpc.close, p.channel, False, 90) for p in peers]
# Now close all channels (not unilaterally!)
closes = [executor.submit(l1.rpc.close, p.channel, 0) for p in peers]
for c in closes:
c.result(90)
@ -265,7 +259,7 @@ def test_closing_negotiation_reconnect(node_factory, bitcoind):
disconnects = ['-WIRE_CLOSING_SIGNED',
'@WIRE_CLOSING_SIGNED',
'+WIRE_CLOSING_SIGNED']
l1 = node_factory.get_node(disconnect=disconnects, may_reconnect=True, options={'allow-deprecated-apis': True})
l1 = node_factory.get_node(disconnect=disconnects, may_reconnect=True)
l2 = node_factory.get_node(may_reconnect=True)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
@ -274,9 +268,7 @@ def test_closing_negotiation_reconnect(node_factory, bitcoind):
assert bitcoind.rpc.getmempoolinfo()['size'] == 0
# This should return with an error, then close.
with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):
l1.rpc.close(chan, False, 0)
l1.rpc.close(chan)
l1.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
l2.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')

View file

@ -577,8 +577,7 @@ def test_shutdown_reconnect(node_factory):
'@WIRE_SHUTDOWN',
'+WIRE_SHUTDOWN']
l1 = node_factory.get_node(disconnect=disconnects,
may_reconnect=True,
options={'allow-deprecated-apis': True})
may_reconnect=True)
l2 = node_factory.get_node(may_reconnect=True)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
@ -587,9 +586,8 @@ def test_shutdown_reconnect(node_factory):
assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0
# This should return with an error, then close.
with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):
l1.rpc.close(chan, False, 0)
# This should wait until we're closed.
l1.rpc.close(chan)
l1.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
l2.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
@ -638,7 +636,7 @@ def test_reconnect_remote_sends_no_sigs(node_factory):
def test_shutdown_awaiting_lockin(node_factory, bitcoind):
l1 = node_factory.get_node(options={'allow-deprecated-apis': True})
l1 = node_factory.get_node()
l2 = node_factory.get_node(options={'funding-confirms': 3})
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
@ -649,9 +647,7 @@ def test_shutdown_awaiting_lockin(node_factory, bitcoind):
l1.daemon.wait_for_log('sendrawtx exit 0')
bitcoind.generate_block(1)
# This should return with an error, then close.
with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):
l1.rpc.close(chanid, False, 0)
l1.rpc.close(chanid)
l1.daemon.wait_for_log('CHANNELD_AWAITING_LOCKIN to CHANNELD_SHUTTING_DOWN')
l2.daemon.wait_for_log('CHANNELD_AWAITING_LOCKIN to CHANNELD_SHUTTING_DOWN')
@ -1129,7 +1125,7 @@ def test_channel_reenable(node_factory):
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_update_fee(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, fundchannel=True, opts={'allow-deprecated-apis': True})
l1, l2 = node_factory.line_graph(2, fundchannel=True)
chanid = l1.get_channel_scid(l2)
# Make l1 send out feechange.
@ -1146,8 +1142,7 @@ def test_update_fee(node_factory, bitcoind):
l2.pay(l1, 100000000)
# Now shutdown cleanly.
with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):
l1.rpc.close(chanid, False, 0)
l1.rpc.close(chanid)
l1.daemon.wait_for_log(' to CLOSINGD_COMPLETE')
l2.daemon.wait_for_log(' to CLOSINGD_COMPLETE')
@ -1313,7 +1308,7 @@ def test_forget_channel(node_factory):
def test_peerinfo(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, fundchannel=False, opts={'may_reconnect': True, 'allow-deprecated-apis': True})
l1, l2 = node_factory.line_graph(2, fundchannel=False, opts={'may_reconnect': True})
lfeatures = 'aa'
# Gossiping but no node announcement yet
assert l1.rpc.getpeer(l2.info['id'])['connected']
@ -1346,8 +1341,7 @@ def test_peerinfo(node_factory, bitcoind):
assert l2.rpc.getpeer(l1.info['id'])['localfeatures'] == lfeatures
# Close the channel to forget the peer
with pytest.raises(RpcError, match=r'Channel close negotiation not finished'):
l1.rpc.close(chan, False, 0)
l1.rpc.close(chan)
wait_for(lambda: not only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['connected'])
wait_for(lambda: not only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['connected'])

View file

@ -1165,7 +1165,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
disconnects = ['-WIRE_UPDATE_FAIL_HTLC', 'permfail']
l1 = node_factory.get_node()
l2 = node_factory.get_node(options={'allow-deprecated-apis': True})
l2 = node_factory.get_node()
l3 = node_factory.get_node()
l4 = node_factory.get_node(disconnect=disconnects)
l5 = node_factory.get_node()
@ -1202,7 +1202,7 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
payment_hash = l3.rpc.invoice(amount, "first", "desc")['payment_hash']
route = l1.rpc.getroute(l3.info['id'], amount, 1)['route']
l2.rpc.close(c23, True, 0)
l2.rpc.close(c23, 1)
with pytest.raises(RpcError):
l1.rpc.sendpay(route, payment_hash)
@ -1824,7 +1824,7 @@ def test_setchannelfee_state(node_factory, bitcoind):
l0 = node_factory.get_node(options={'fee-base': DEF_BASE, 'fee-per-satoshi': DEF_PPM})
l1 = node_factory.get_node(options={'fee-base': DEF_BASE, 'fee-per-satoshi': DEF_PPM})
l2 = node_factory.get_node(options={'fee-base': DEF_BASE, 'fee-per-satoshi': DEF_PPM, 'allow-deprecated-apis': True})
l2 = node_factory.get_node(options={'fee-base': DEF_BASE, 'fee-per-satoshi': DEF_PPM})
# connection and funding
l0.rpc.connect(l1.info['id'], 'localhost', l1.port)
@ -1849,7 +1849,7 @@ def test_setchannelfee_state(node_factory, bitcoind):
# Disconnect and unilaterally close from l2 to l1
l2.rpc.disconnect(l1.info['id'], force=True)
l1.rpc.disconnect(l2.info['id'], force=True)
result = l2.rpc.close(scid, True, 0)
result = l2.rpc.close(scid, 1)
assert result['type'] == 'unilateral'
# wait for l1 to see unilateral close via bitcoin network