Skip to content

Commit

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

* add edit_ini_sections

* Problem: start with exported genesis is not tested
  • Loading branch information
mmsqe authored Sep 7, 2023
1 parent 4565d75 commit 2101dd6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
2 changes: 1 addition & 1 deletion integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,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
51 changes: 29 additions & 22 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,10 +13,12 @@
ADDRS,
CONTRACTS,
deploy_contract,
edit_ini_sections,
parse_events,
send_transaction,
wait_for_block,
wait_for_block_time,
wait_for_new_blocks,
wait_for_port,
)

Expand All @@ -37,28 +38,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 @@ -99,7 +92,7 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):

custom_cronos.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1")
wait_for_port(ports.evmrpc_port(custom_cronos.base_port(0)))

wait_for_new_blocks(cli, 1)
height = cli.block_height()
target_height = height + 15
print("upgrade height", target_height)
Expand Down Expand Up @@ -210,3 +203,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")
42 changes: 19 additions & 23 deletions integration_tests/test_upgrade_gravity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import configparser
import json
import re
import subprocess
from pathlib import Path

Expand All @@ -10,7 +8,13 @@
from pystarport.cluster import SUPERVISOR_CONFIG_FILE

from .network import Cronos, setup_custom_cronos
from .utils import parse_events, wait_for_block, wait_for_block_time, wait_for_port
from .utils import (
edit_ini_sections,
parse_events,
wait_for_block,
wait_for_block_time,
wait_for_port,
)


def init_cosmovisor(home):
Expand All @@ -28,29 +32,21 @@ 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}"
f" --trace --unsafe-experimental",
"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}"
f" --trace --unsafe-experimental",
"environment": f"DAEMON_NAME=cronosd,DAEMON_HOME=%(here)s/node{i}",
},
)


@pytest.fixture(scope="module")
Expand Down
14 changes: 14 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,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 2101dd6

Please sign in to comment.