From f1822e3650096988bd38cf18882d68d8bc043d60 Mon Sep 17 00:00:00 2001 From: trueptolemy Date: Sat, 24 Aug 2019 22:39:01 +0800 Subject: [PATCH] pytest: Test `fundchannel_cancel` can work after `fundchannel_complete` --- tests/test_connection.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 982690d2a..397e3b6bf 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1,4 +1,5 @@ from collections import namedtuple +from decimal import Decimal from fixtures import * # noqa: F401,F403 from flaky import flaky # noqa: F401 from lightning import RpcError @@ -875,7 +876,38 @@ def test_funding_external_wallet_corners(node_factory, bitcoind): l1.rpc.fundchannel_cancel(l2.info['id']) # Should be able to 'restart' after canceling - l1.rpc.fundchannel_start(l2.info['id'], amount) + amount2 = 1000000 + funding_addr = l1.rpc.fundchannel_start(l2.info['id'], amount2)['funding_address'] + + addr = l1.rpc.newaddr()['bech32'] + l1.bitcoin.rpc.sendtoaddress(addr, 0.1) + bitcoind.generate_block(1) + wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1) + # Create the funding transaction + prep = l1.rpc.txprepare([{funding_addr: amount2}]) + decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx']) + assert decode['txid'] == prep['txid'] + + # One output will be correct. + if decode['vout'][0]['value'] == Decimal('0.01000000'): + txout = 0 + elif decode['vout'][1]['value'] == Decimal('0.01000000'): + txout = 1 + else: + assert False + + # Be sure fundchannel_complete is successful + assert l1.rpc.fundchannel_complete(l2.info['id'], prep['txid'], txout)['commitments_secured'] + # Canceld channel after fundchannel_complete + assert l1.rpc.fundchannel_cancel(l2.info['id'])['cancelled'] + + l1.rpc.connect(l2.info['id'], 'localhost', l2.port) + l1.rpc.fundchannel_start(l2.info['id'], amount)['funding_address'] + assert l1.rpc.fundchannel_complete(l2.info['id'], prep['txid'], txout)['commitments_secured'] + l1.rpc.txsend(prep['txid']) + with pytest.raises(RpcError, match=r'.* been broadcast.*'): + l1.rpc.fundchannel_cancel(l2.info['id']) + l1.rpc.close(l2.info['id']) def test_funding_cancel_race(node_factory, bitcoind, executor):