|
1 | 1 | import json |
2 | | -import shutil |
3 | | -import stat |
4 | | -import subprocess |
5 | | -from contextlib import contextmanager |
6 | 2 | from datetime import datetime, timedelta |
7 | 3 | from pathlib import Path |
8 | 4 |
|
9 | 5 | import pytest |
10 | 6 | from pystarport import ports |
11 | | -from pystarport.cluster import SUPERVISOR_CONFIG_FILE |
12 | 7 |
|
13 | 8 | from .cosmoscli import DEFAULT_GAS_PRICE |
14 | | -from .network import Cronos, setup_custom_cronos |
| 9 | +from .network import Cronos, setup_upgrade_cronos |
15 | 10 | from .utils import ( |
16 | 11 | ADDRS, |
17 | 12 | CONTRACTS, |
18 | 13 | KEYS, |
19 | 14 | approve_proposal, |
20 | 15 | deploy_contract, |
21 | | - edit_ini_sections, |
22 | 16 | get_consensus_params, |
23 | 17 | get_send_enable, |
24 | 18 | send_transaction, |
|
33 | 27 |
|
34 | 28 | @pytest.fixture(scope="module") |
35 | 29 | def custom_cronos(tmp_path_factory): |
36 | | - yield from setup_cronos_test(tmp_path_factory) |
37 | | - |
38 | | - |
39 | | -def init_cosmovisor(home): |
40 | | - """ |
41 | | - build and setup cosmovisor directory structure in each node's home directory |
42 | | - """ |
43 | | - cosmovisor = home / "cosmovisor" |
44 | | - cosmovisor.mkdir() |
45 | | - (cosmovisor / "upgrades").symlink_to("../../../upgrades") |
46 | | - (cosmovisor / "genesis").symlink_to("./upgrades/genesis") |
47 | | - |
48 | | - |
49 | | -def post_init(path, base_port, config): |
50 | | - """ |
51 | | - prepare cosmovisor for each node |
52 | | - """ |
53 | | - chain_id = "cronos_777-1" |
54 | | - data = path / chain_id |
55 | | - cfg = json.loads((data / "config.json").read_text()) |
56 | | - for i, _ in enumerate(cfg["validators"]): |
57 | | - home = data / f"node{i}" |
58 | | - init_cosmovisor(home) |
59 | | - |
60 | | - edit_ini_sections( |
61 | | - chain_id, |
62 | | - data / SUPERVISOR_CONFIG_FILE, |
63 | | - lambda i, _: { |
64 | | - "command": f"cosmovisor run start --home %(here)s/node{i}", |
65 | | - "environment": ( |
66 | | - "DAEMON_NAME=cronosd," |
67 | | - "DAEMON_SHUTDOWN_GRACE=1m," |
68 | | - "UNSAFE_SKIP_BACKUP=true," |
69 | | - f"DAEMON_HOME=%(here)s/node{i}" |
70 | | - ), |
71 | | - }, |
72 | | - ) |
73 | | - |
74 | | - |
75 | | -def setup_cronos_test(tmp_path_factory): |
76 | | - path = tmp_path_factory.mktemp("upgrade") |
77 | 30 | port = 26200 |
78 | 31 | nix_name = "upgrade-test-package" |
79 | 32 | cfg_name = "cosmovisor" |
80 | | - configdir = Path(__file__).parent |
81 | | - cmd = [ |
82 | | - "nix-build", |
83 | | - configdir / f"configs/{nix_name}.nix", |
84 | | - ] |
85 | | - print(*cmd) |
86 | | - subprocess.run(cmd, check=True) |
87 | | - |
88 | | - # copy the content so the new directory is writable. |
89 | | - upgrades = path / "upgrades" |
90 | | - shutil.copytree("./result", upgrades) |
91 | | - mod = stat.S_IRWXU |
92 | | - upgrades.chmod(mod) |
93 | | - for d in upgrades.iterdir(): |
94 | | - d.chmod(mod) |
95 | | - |
96 | | - # init with genesis binary |
97 | | - with contextmanager(setup_custom_cronos)( |
98 | | - path, |
99 | | - port, |
100 | | - configdir / f"configs/{cfg_name}.jsonnet", |
101 | | - post_init=post_init, |
102 | | - chain_binary=str(upgrades / "genesis/bin/cronosd"), |
103 | | - ) as cronos: |
104 | | - yield cronos |
| 33 | + yield from setup_upgrade_cronos(tmp_path_factory, port, nix_name, cfg_name) |
105 | 34 |
|
106 | 35 |
|
107 | 36 | def exec(c, tmp_path_factory): |
|
0 commit comments