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

Function test_segwit_shutdown_script

tests/test_closing.py:3738–3810  ·  view source on GitHub ↗

Try a range of future segwit versions as shutdown scripts. We create many nodes, so this is quite slow under valgrind

(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

3736
3737@pytest.mark.slow_test
3738def test_segwit_shutdown_script(node_factory, bitcoind, executor):
3739 """
3740Try a range of future segwit versions as shutdown scripts. We create many nodes, so this is quite slow under valgrind
3741"""
3742 l1 = node_factory.get_node(allow_warning=True)
3743
3744 # BOLT #2:
3745 # 3. if (and only if) `option_shutdown_anysegwit` is negotiated:
3746 # * `OP_1` through `OP_16` inclusive, followed by a single push of 2 to 40 bytes
3747 # (witness program versions 1 through 16)
3748 edge_valid = ['51020000', '5128' + '00' * 0x28,
3749 '60020000', '6028' + '00' * 0x28]
3750 other_valid = ['52020000', '5228' + '00' * 0x28,
3751 '53020000', '5328' + '00' * 0x28,
3752 '54020000', '5428' + '00' * 0x28,
3753 '55020000', '5528' + '00' * 0x28,
3754 '56020000', '5628' + '00' * 0x28,
3755 '57020000', '5728' + '00' * 0x28,
3756 '58020000', '5828' + '00' * 0x28,
3757 '59020000', '5928' + '00' * 0x28,
3758 '5A020000', '5A28' + '00' * 0x28,
3759 '5B020000', '5B28' + '00' * 0x28,
3760 '5C020000', '5C28' + '00' * 0x28,
3761 '5D020000', '5D28' + '00' * 0x28,
3762 '5E020000', '5E28' + '00' * 0x28,
3763 '5F020000', '5F28' + '00' * 0x28]
3764
3765 invalid = ['50020000', # Not OP_1-OP_16
3766 '61020000', # Not OP_1-OP_16
3767 '5102000000', # Extra bytes
3768 '510100', # Too short
3769 '5129' + '00' * 0x29] # Too long
3770
3771 # Don't stress CI; just test edge cases
3772 if SLOW_MACHINE:
3773 valid = edge_valid
3774 else:
3775 valid = edge_valid + other_valid
3776
3777 # More efficient to create them all up-front.
3778 nodes = node_factory.get_nodes(len(valid) + len(invalid))
3779
3780 # Give it one UTXO to spend for each node.
3781 addresses = {}
3782 for n in nodes:
3783 addresses[l1.rpc.newaddr('bech32')['bech32']] = (10**6 + 100000) / 10**8
3784 bitcoind.rpc.sendmany("", addresses)
3785 bitcoind.generate_block(1)
3786 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == len(addresses))
3787
3788 # FIXME: Since we don't support other non-v0 encodings, we need a protocol
3789 # test for this (we're actually testing our upfront check, not the real
3790 # shutdown one!),
3791 for script in valid:
3792 # Insist on upfront script we're not going to match.
3793 l1.stop()
3794 l1.daemon.env["DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT"] = script
3795 l1.start()

Callers

nothing calls this directly

Calls 10

wait_forFunction · 0.90
get_nodesMethod · 0.80
generate_blockMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
listfundsMethod · 0.45
stopMethod · 0.45
startMethod · 0.45
connectMethod · 0.45
fundchannelMethod · 0.45

Tested by

no test coverage detected