Test that we move files correctly on old testnet upgrade (even without specifying the network)
(node_factory)
| 2712 | |
| 2713 | @unittest.skipIf(env('COMPAT') != 1, "Upgrade code requires COMPAT_V073") |
| 2714 | def test_testnet_upgrade(node_factory): |
| 2715 | """Test that we move files correctly on old testnet upgrade (even without specifying the network)""" |
| 2716 | l1 = node_factory.get_node(start=False, may_fail=True) |
| 2717 | |
| 2718 | basedir = l1.daemon.opts.get("lightning-dir") |
| 2719 | # Make it old-style |
| 2720 | os.rename(os.path.join(basedir, TEST_NETWORK, 'hsm_secret'), |
| 2721 | os.path.join(basedir, 'hsm_secret')) |
| 2722 | shutil.rmtree(os.path.join(basedir, TEST_NETWORK)) |
| 2723 | # Add (empty!) config file; it should be left in place. |
| 2724 | with open(os.path.join(basedir, 'config'), 'wb') as f: |
| 2725 | f.write(b"# Test config file") |
| 2726 | with open(os.path.join(basedir, 'another_file'), 'wb') as f: |
| 2727 | pass |
| 2728 | |
| 2729 | # We need to allow this, otherwise no upgrade! |
| 2730 | del l1.daemon.opts['allow-deprecated-apis'] |
| 2731 | # We want to test default network |
| 2732 | del l1.daemon.opts['network'] |
| 2733 | |
| 2734 | # Wrong chain, will fail to start, but that's OK. |
| 2735 | with pytest.raises(ValueError): |
| 2736 | l1.start() |
| 2737 | |
| 2738 | netdir = os.path.join(basedir, "testnet") |
| 2739 | assert l1.daemon.is_in_log("Moving hsm_secret into {}/".format(netdir)) |
| 2740 | assert l1.daemon.is_in_log("Moving another_file into {}/".format(netdir)) |
| 2741 | assert not l1.daemon.is_in_log("Moving config into {}/".format(netdir)) |
| 2742 | assert not l1.daemon.is_in_log("Moving lightningd-testnet.pid into {}/" |
| 2743 | .format(netdir)) |
| 2744 | |
| 2745 | # Should move these |
| 2746 | assert os.path.isfile(os.path.join(netdir, "hsm_secret")) |
| 2747 | assert not os.path.isfile(os.path.join(basedir, "hsm_secret")) |
| 2748 | assert os.path.isfile(os.path.join(netdir, "another_file")) |
| 2749 | assert not os.path.isfile(os.path.join(basedir, "another_file")) |
| 2750 | |
| 2751 | # Should NOT move these |
| 2752 | assert not os.path.isfile(os.path.join(netdir, "lightningd-testnet.pid")) |
| 2753 | assert os.path.isfile(os.path.join(basedir, "lightningd-testnet.pid")) |
| 2754 | assert not os.path.isfile(os.path.join(netdir, "config")) |
| 2755 | assert os.path.isfile(os.path.join(basedir, "config")) |
| 2756 | |
| 2757 | restore_valgrind(l1, netdir) |
| 2758 | |
| 2759 | |
| 2760 | @unittest.skipIf(env('COMPAT') != 1, "Upgrade code requires COMPAT_V073") |