Skip to content

Commit

Permalink
df tests: node still correctly picks up new tx if broadcast fails
Browse files Browse the repository at this point in the history
Now that we're more broadcast failure aware, let's check that on
actual broadcast failure we still update UTXO set properly and the
channel opens.
  • Loading branch information
niftynei committed Jul 7, 2022
1 parent 8446c1f commit 6becf47
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,47 @@ def mock_donothing(r):
assert len(l2.rpc.listpeers(l1.info['id'])['peers']) == 0


@pytest.mark.developer("needs --dev-max-funding-unconfirmed-blocks")
@pytest.mark.openchannel('v2')
def test_fundee_node_unconfirmed(node_factory, bitcoind):
"""Test that fundee will successfully broadcast and
funder still has correct UTXOs/correctly advances the channel
"""
# opener
l1, l2 = node_factory.line_graph(2, fundchannel=False)

# Give opener some funds.
l1.fundwallet(10**7)

start_amount = only_one(l1.rpc.listfunds()['outputs'])['amount_msat']

def mock_sendrawtransaction(r):
return {'id': r['id'], 'error': {'code': 100, 'message': 'sendrawtransaction disabled'}}

def mock_donothing(r):
time.sleep(10)
return bitcoind.rpc.sendrawtransaction(r['params'][0])

# Prevent both from broadcasting funding tx (any tx really).
l1.daemon.rpcproxy.mock_rpc('sendrawtransaction', mock_sendrawtransaction)
l2.daemon.rpcproxy.mock_rpc('sendrawtransaction', mock_donothing)

# Fund the channel.
# The process will complete, but opener will be unable
# to broadcast and confirm funding tx.
with pytest.raises(RpcError, match=r'sendrawtransaction disabled'):
l1.rpc.fundchannel(l2.info['id'], 10**6)

# Generate blocks until unconfirmed.
bitcoind.generate_block(1, wait_for_mempool=1)

# Check that l1 opened the channel
wait_for(lambda: only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['state'] == 'CHANNELD_NORMAL')
end_amount = only_one(l1.rpc.listfunds()['outputs'])['amount_msat']
# We should be out the onchaind fees
assert start_amount > end_amount + Millisatoshi(10 ** 7 * 100)


@pytest.mark.developer("needs dev_fail")
def test_no_fee_estimate(node_factory, bitcoind, executor):
l1 = node_factory.get_node(start=False, options={'dev-no-fake-fees': True})
Expand Down

0 comments on commit 6becf47

Please sign in to comment.