Skip to content

Commit

Permalink
Problem: start with exported genesis is not tested (crypto-org-chain#…
Browse files Browse the repository at this point in the history
…1140)

* add edit_ini_sections

* Problem: start with exported genesis is not tested
  • Loading branch information
mmsqe authored Aug 23, 2023
1 parent 21ec1ad commit cc7f377
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
48 changes: 27 additions & 21 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import configparser
import json
import re
import subprocess
from datetime import datetime, timedelta
from pathlib import Path

import pytest
Expand All @@ -14,6 +13,7 @@
CONTRACTS,
approve_proposal,
deploy_contract,
edit_ini_sections,
send_transaction,
wait_for_block,
wait_for_new_blocks,
Expand All @@ -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")
Expand Down Expand Up @@ -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")
14 changes: 14 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit cc7f377

Please sign in to comment.