diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index e8085cb57a..6972d301d2 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -888,7 +888,7 @@ def export(self): return self.raw("export", home=self.data_dir) def unsaferesetall(self): - return self.raw("unsafe-reset-all") + return self.raw("tendermint", "unsafe-reset-all") def create_nft(self, from_addr, denomid, denomname, schema, fees): return json.loads( diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index 1ddb6345e6..151c183f2f 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -1,7 +1,6 @@ -import configparser import json -import re import subprocess +from datetime import datetime, timedelta from pathlib import Path import pytest @@ -14,6 +13,7 @@ CONTRACTS, approve_proposal, deploy_contract, + edit_ini_sections, send_transaction, wait_for_block, wait_for_new_blocks, @@ -36,28 +36,20 @@ def post_init(path, base_port, config): prepare cosmovisor for each node """ chain_id = "cronos_777-1" - cfg = json.loads((path / chain_id / "config.json").read_text()) + data = path / chain_id + cfg = json.loads((data / "config.json").read_text()) for i, _ in enumerate(cfg["validators"]): - home = path / chain_id / f"node{i}" + home = data / f"node{i}" init_cosmovisor(home) - # patch supervisord ini config - ini_path = path / chain_id / SUPERVISOR_CONFIG_FILE - ini = configparser.RawConfigParser() - ini.read(ini_path) - reg = re.compile(rf"^program:{chain_id}-node(\d+)") - for section in ini.sections(): - m = reg.match(section) - if m: - i = m.group(1) - ini[section].update( - { - "command": f"cosmovisor start --home %(here)s/node{i}", - "environment": f"DAEMON_NAME=cronosd,DAEMON_HOME=%(here)s/node{i}", - } - ) - with ini_path.open("w") as fp: - ini.write(fp) + edit_ini_sections( + chain_id, + data / SUPERVISOR_CONFIG_FILE, + lambda i, _: { + "command": f"cosmovisor start --home %(here)s/node{i}", + "environment": f"DAEMON_NAME=cronosd,DAEMON_HOME=%(here)s/node{i}", + }, + ) @pytest.fixture(scope="module") @@ -206,3 +198,17 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory): json.dump(cli.migrate_cronos_genesis(cronos_version, str(file_path1)), fp) fp.flush() print(cli.validate_genesis(str(file_path2))) + + # update the genesis time = current time + 5 secs + newtime = datetime.utcnow() + timedelta(seconds=5) + newtime = newtime.replace(tzinfo=None).isoformat("T") + "Z" + config = custom_cronos.config + config["genesis-time"] = newtime + for i, _ in enumerate(config["validators"]): + genesis = json.load(open(file_path2)) + genesis["genesis_time"] = config.get("genesis-time") + file = custom_cronos.cosmos_cli(i).data_dir / "config/genesis.json" + file.write_text(json.dumps(genesis)) + custom_cronos.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1") + wait_for_new_blocks(custom_cronos.cosmos_cli(), 1) + custom_cronos.supervisorctl("stop", "all") diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 4914a330e8..2d2b264cbe 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -296,6 +296,20 @@ def add_ini_sections(inipath, sections): ini.write(fp) +def edit_ini_sections(chain_id, ini_path, callback): + ini = configparser.RawConfigParser() + ini.read(ini_path) + reg = re.compile(rf"^program:{chain_id}-node(\d+)") + for section in ini.sections(): + m = reg.match(section) + if m: + i = m.group(1) + old = ini[section] + ini[section].update(callback(i, old)) + with ini_path.open("w") as fp: + ini.write(fp) + + def supervisorctl(inipath, *args): return subprocess.check_output( (sys.executable, "-msupervisor.supervisorctl", "-c", inipath, *args),