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

Function test_testnet_upgrade

tests/test_misc.py:2684–2727  ·  view source on GitHub ↗

Test that we move files correctly on old testnet upgrade (even without specifying the network)

(node_factory)

Source from the content-addressed store, hash-verified

2682
2683@unittest.skipIf(env('COMPAT') != 1, "Upgrade code requires COMPAT_V073")
2684def test_testnet_upgrade(node_factory):
2685 """Test that we move files correctly on old testnet upgrade (even without specifying the network)"""
2686 l1 = node_factory.get_node(start=False, may_fail=True)
2687
2688 basedir = l1.daemon.opts.get("lightning-dir")
2689 # Make it old-style
2690 os.rename(os.path.join(basedir, TEST_NETWORK, 'hsm_secret'),
2691 os.path.join(basedir, 'hsm_secret'))
2692 shutil.rmtree(os.path.join(basedir, TEST_NETWORK))
2693 # Add (empty!) config file; it should be left in place.
2694 with open(os.path.join(basedir, 'config'), 'wb') as f:
2695 f.write(b"# Test config file")
2696 with open(os.path.join(basedir, 'another_file'), 'wb') as f:
2697 pass
2698
2699 # We need to allow this, otherwise no upgrade!
2700 del l1.daemon.opts['allow-deprecated-apis']
2701 # We want to test default network
2702 del l1.daemon.opts['network']
2703
2704 # Wrong chain, will fail to start, but that's OK.
2705 with pytest.raises(ValueError):
2706 l1.start()
2707
2708 netdir = os.path.join(basedir, "testnet")
2709 assert l1.daemon.is_in_log("Moving hsm_secret into {}/".format(netdir))
2710 assert l1.daemon.is_in_log("Moving another_file into {}/".format(netdir))
2711 assert not l1.daemon.is_in_log("Moving config into {}/".format(netdir))
2712 assert not l1.daemon.is_in_log("Moving lightningd-testnet.pid into {}/"
2713 .format(netdir))
2714
2715 # Should move these
2716 assert os.path.isfile(os.path.join(netdir, "hsm_secret"))
2717 assert not os.path.isfile(os.path.join(basedir, "hsm_secret"))
2718 assert os.path.isfile(os.path.join(netdir, "another_file"))
2719 assert not os.path.isfile(os.path.join(basedir, "another_file"))
2720
2721 # Should NOT move these
2722 assert not os.path.isfile(os.path.join(netdir, "lightningd-testnet.pid"))
2723 assert os.path.isfile(os.path.join(basedir, "lightningd-testnet.pid"))
2724 assert not os.path.isfile(os.path.join(netdir, "config"))
2725 assert os.path.isfile(os.path.join(basedir, "config"))
2726
2727 restore_valgrind(l1, netdir)
2728
2729
2730@unittest.skipIf(env('COMPAT') != 1, "Upgrade code requires COMPAT_V073")

Callers

nothing calls this directly

Calls 7

restore_valgrindFunction · 0.85
joinMethod · 0.80
is_in_logMethod · 0.80
get_nodeMethod · 0.45
getMethod · 0.45
writeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected