MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_closing_simple

Function test_closing_simple

tests/test_closing.py:27–131  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

25
26
27def test_closing_simple(node_factory, bitcoind, chainparams):
28 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
29 l1, l2 = node_factory.line_graph(2, opts={'plugin': coin_mvt_plugin})
30 chan = l1.get_channel_scid(l2)
31 channel_id = first_channel_id(l1, l2)
32 fee = closing_fee(3750, 2) if not chainparams['elements'] else 4278
33
34 l1.pay(l2, 200000000)
35
36 assert bitcoind.rpc.getmempoolinfo()['size'] == 0
37
38 billboard = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['status']
39 assert billboard == ['CHANNELD_NORMAL:Channel ready for use.']
40 billboard = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['status']
41 assert billboard == ['CHANNELD_NORMAL:Channel ready for use.']
42
43 bitcoind.generate_block(5)
44 l1.wait_channel_active(chan)
45 l2.wait_channel_active(chan)
46
47 billboard = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['status']
48 # This may either be from a local_update or an announce, so just
49 # check for the substring
50 assert 'CHANNELD_NORMAL:Channel ready for use.' in billboard[0]
51
52 # Make sure all HTLCs resolved before we close!
53 wait_for(lambda: only_one(l2.rpc.listpeerchannels()['channels'])['htlcs'] == [])
54 l1.rpc.close(chan)
55
56 l1.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
57 l2.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
58
59 l1.daemon.wait_for_log(' to CLOSINGD_SIGEXCHANGE')
60 l2.daemon.wait_for_log(' to CLOSINGD_SIGEXCHANGE')
61
62 # And should put closing into mempool.
63 l1.daemon.wait_for_log('sendrawtx exit 0')
64 l2.daemon.wait_for_log('sendrawtx exit 0')
65
66 # Both nodes should have disabled the channel in gossip
67 wait_for(lambda: not any([c['active'] for c in l1.rpc.listchannels()['channels']]))
68 wait_for(lambda: not any([c['active'] for c in l2.rpc.listchannels()['channels']]))
69
70 assert bitcoind.rpc.getmempoolinfo()['size'] == 1
71
72 # Now grab the close transaction
73 closetxid = only_one(bitcoind.rpc.getrawmempool(False))
74
75 billboard = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['status']
76 assert billboard == [
77 'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of {} satoshi for tx:{}'.format(fee, closetxid),
78 ]
79 bitcoind.generate_block(1)
80
81 outtype = 'p2tr' if not chainparams['elements'] else 'p2wpkh'
82 l1.daemon.wait_for_log(rf'Owning output.* \({outtype}\).* txid %s.* CONFIRMED' % closetxid)
83 l2.daemon.wait_for_log(rf'Owning output.* \({outtype}\).* txid %s.* CONFIRMED' % closetxid)
84

Callers

nothing calls this directly

Calls 15

first_channel_idFunction · 0.90
closing_feeFunction · 0.90
only_oneFunction · 0.90
wait_forFunction · 0.90
account_balanceFunction · 0.90
check_utxos_channelFunction · 0.90
sync_blockheightFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
get_channel_scidMethod · 0.80
listpeerchannelsMethod · 0.80
generate_blockMethod · 0.80

Tested by

no test coverage detected