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

Function test_coinbase_unspendable

tests/test_opening.py:2891–2929  ·  view source on GitHub ↗

A node should not be able to spend a coinbase output before it's mature

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2889
2890
2891def test_coinbase_unspendable(node_factory, bitcoind):
2892 """ A node should not be able to spend a coinbase output
2893 before it's mature """
2894
2895 [l1] = node_factory.get_nodes(1)
2896
2897 addr = l1.rpc.newaddr("bech32")["bech32"]
2898 bitcoind.rpc.generatetoaddress(1, addr)
2899
2900 addr2 = l1.rpc.newaddr("bech32")["bech32"]
2901
2902 # Wait til money in wallet
2903 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 1)
2904 out = only_one(l1.rpc.listfunds()['outputs'])
2905 assert out['status'] == 'immature'
2906
2907 with pytest.raises(RpcError, match='Could not afford all using all 0 available UTXOs'):
2908 l1.rpc.withdraw(addr2, "all")
2909
2910 # Nothing sent to the mempool!
2911 assert len(bitcoind.rpc.getrawmempool()) == 0
2912
2913 # Mine 98 blocks
2914 bitcoind.rpc.generatetoaddress(98, l1.rpc.newaddr('bech32')['bech32'])
2915 assert len([out for out in l1.rpc.listfunds()['outputs'] if out['status'] == 'confirmed']) == 0
2916 with pytest.raises(RpcError, match='Could not afford all using all 0 available UTXOs'):
2917 l1.rpc.withdraw(addr2, "all")
2918
2919 # One more and the first coinbase unlocks
2920 bitcoind.rpc.generatetoaddress(1, l1.rpc.newaddr('bech32')['bech32'])
2921 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 100)
2922 assert len([out for out in l1.rpc.listfunds()['outputs'] if out['status'] == 'confirmed']) == 1
2923 l1.rpc.withdraw(addr2, "all")
2924 # One tx in the mempool now!
2925 assert len(bitcoind.rpc.getrawmempool()) == 1
2926
2927 # Mine one block, assert one more is spendable
2928 bitcoind.rpc.generatetoaddress(1, l1.rpc.newaddr('bech32')['bech32'])
2929 assert len([out for out in l1.rpc.listfunds()['outputs'] if out['status'] == 'confirmed']) == 1
2930
2931
2932@pytest.mark.openchannel('v2')

Callers

nothing calls this directly

Calls 6

wait_forFunction · 0.90
only_oneFunction · 0.90
get_nodesMethod · 0.80
newaddrMethod · 0.45
listfundsMethod · 0.45
withdrawMethod · 0.45

Tested by

no test coverage detected