Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Dec 4, 2024
1 parent 9f9a93c commit 8cb8339
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 87 deletions.
32 changes: 32 additions & 0 deletions integration_tests/configs/cosmovisor_with_ibc.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local ibc = import 'ibc.jsonnet';

ibc {
'cronos_777-1'+: {
'app-config'+: {
'app-db-backend': 'rocksdb',
'iavl-lazy-loading':: super['iavl-lazy-loading'],
},
validators: [super.validators[0] {
'app-config'+: {
store: {
streamers: ['versiondb'],
},
},
}] + super.validators[1:],
genesis+: {
consensus_params: {
block: {
max_bytes: '1048576',
max_gas: '81500000',
},
},
app_state+: {
gov+: {
params+: {
expedited_voting_period:: super['expedited_voting_period'],
},
},
},
},
},
}
33 changes: 33 additions & 0 deletions integration_tests/configs/upgrade-test-package-recent.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
let
pkgs = import ../../nix { };
fetchFlake =
repo: rev:
(pkgs.flake-compat {
src = {
outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz";
inherit rev;
shortRev = builtins.substring 0 7 rev;
};
}).defaultNix;
# release/v1.3.x
releasedGenesis =
(fetchFlake "crypto-org-chain/cronos" "e1d819c862b30f0ce978baf2addb12516568639e").default;
# release/v1.4.x
released1_4 =
(fetchFlake "crypto-org-chain/cronos" "ce797fa995000530ee53cd1fbeb3c67180648002").default;
current = pkgs.callPackage ../../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{
name = "genesis";
path = releasedGenesis;
}
{
name = "v1.4";
path = released1_4;
}
{
name = "v1.4.0-rc5-testnet";
path = current;
}
]
35 changes: 35 additions & 0 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,41 @@ def ica_query_account(self, connid, owner, **kwargs):
)
)

def icaauth_register_account(self, connid, event_query_tx=True, **kwargs):
default_kwargs = {
"home": self.data_dir,
"node": self.node_rpc,
"chain_id": self.chain_id,
"keyring_backend": "test",
}
args = ["icaauth", "register-account"]
rsp = json.loads(
self.raw(
"tx",
*args,
connid,
"-y",
**(default_kwargs | kwargs),
)
)
if rsp["code"] == 0 and event_query_tx:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def icaauth_query_account(self, connid, owner, **kwargs):
default_kwargs = {
"node": self.node_rpc,
"output": "json",
}
args = ["icaauth", "interchain-account-address", connid, owner]
return json.loads(
self.raw(
"q",
*args,
**(default_kwargs | kwargs),
)
)

def query_ica_params(self, **kwargs):
default_kwargs = {
"node": self.node_rpc,
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/ibc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def prepare_network(
grantee=None,
need_relayer_caller=False,
relayer=cluster.Relayer.HERMES.value,
post_init=None,
chain_binary=None,
):
print("incentivized", incentivized)
print("is_relay", is_relay)
Expand All @@ -162,6 +164,8 @@ def prepare_network(
tmp_path,
26700,
Path(__file__).parent / file,
post_init=post_init,
chain_binary=chain_binary,
relayer=relayer,
) as cronos:
cli = cronos.cosmos_cli()
Expand Down
93 changes: 7 additions & 86 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
import pytest
import requests
from pystarport import ports
from pystarport.cluster import SUPERVISOR_CONFIG_FILE

from .network import Cronos, setup_custom_cronos
from .utils import (
ADDRS,
CONTRACTS,
approve_proposal,
assert_gov_params,
deploy_contract,
edit_ini_sections,
do_upgrade,
get_consensus_params,
get_send_enable,
post_init,
send_transaction,
wait_for_block,
wait_for_new_blocks,
wait_for_port,
)
Expand All @@ -44,42 +42,6 @@ def get_txs(base_port, end):
return res


def init_cosmovisor(home):
"""
build and setup cosmovisor directory structure in each node's home directory
"""
cosmovisor = home / "cosmovisor"
cosmovisor.mkdir()
(cosmovisor / "upgrades").symlink_to("../../../upgrades")
(cosmovisor / "genesis").symlink_to("./upgrades/genesis")


def post_init(path, base_port, config):
"""
prepare cosmovisor for each node
"""
chain_id = "cronos_777-1"
data = path / chain_id
cfg = json.loads((data / "config.json").read_text())
for i, _ in enumerate(cfg["validators"]):
home = data / f"node{i}"
init_cosmovisor(home)

edit_ini_sections(
chain_id,
data / SUPERVISOR_CONFIG_FILE,
lambda i, _: {
"command": f"cosmovisor run start --home %(here)s/node{i}",
"environment": (
"DAEMON_NAME=cronosd,"
"DAEMON_SHUTDOWN_GRACE=1m,"
"UNSAFE_SKIP_BACKUP=true,"
f"DAEMON_HOME=%(here)s/node{i}"
),
},
)


def setup_cronos_test(tmp_path_factory):
path = tmp_path_factory.mktemp("upgrade")
port = 26200
Expand Down Expand Up @@ -163,52 +125,11 @@ def exec(c, tmp_path_factory):
wait_for_port(ports.evmrpc_port(base_port))
wait_for_new_blocks(cli, 1)

def do_upgrade(plan_name, target, mode=None):
print(f"upgrade {plan_name} height: {target}")
if plan_name == "v1.4.0-rc5-testnet":
rsp = cli.software_upgrade(
"community",
{
"name": plan_name,
"title": "upgrade test",
"note": "ditto",
"upgrade-height": target,
"summary": "summary",
"deposit": "10000basetcro",
},
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(c, rsp["events"])
else:
rsp = cli.gov_propose_legacy(
"community",
"software-upgrade",
{
"name": plan_name,
"title": "upgrade test",
"description": "ditto",
"upgrade-height": target,
"deposit": "10000basetcro",
},
mode=mode,
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(c, rsp["logs"][0]["events"])

# update cli chain binary
c.chain_binary = (
Path(c.chain_binary).parent.parent.parent / f"{plan_name}/bin/cronosd"
)
# block should pass the target height
wait_for_block(c.cosmos_cli(), target + 2, timeout=480)
wait_for_port(ports.rpc_port(base_port))
return c.cosmos_cli()

# test migrate keystore
cli.migrate_keystore()
height = cli.block_height()
target_height0 = height + 15
cli = do_upgrade("v1.1.0", target_height0, "block")
cli = do_upgrade(c, "v1.1.0", target_height0, "block")
check_basic_tx(c)

height = cli.block_height()
Expand All @@ -231,7 +152,7 @@ def do_upgrade(plan_name, target, mode=None):
)
print("old values", old_height, old_balance, old_base_fee)

cli = do_upgrade("v1.2", target_height1)
cli = do_upgrade(c, "v1.2", target_height1)
check_basic_tx(c)

# deploy contract should still work
Expand Down Expand Up @@ -287,11 +208,11 @@ def do_upgrade(plan_name, target, mode=None):

height = cli.block_height()
txs = get_txs(base_port, height)
cli = do_upgrade("v1.3", height + 15)
cli = do_upgrade(c, "v1.3", height + 15)
assert txs == get_txs(base_port, height)

gov_param = cli.query_params("gov")
cli = do_upgrade("v1.4", cli.block_height() + 15)
cli = do_upgrade(c, "v1.4", cli.block_height() + 15)

assert_evm_params(cli, e0, target_height0 - 1)
assert_evm_params(cli, e1, target_height1 - 1)
Expand All @@ -302,7 +223,7 @@ def do_upgrade(plan_name, target, mode=None):
cli.query_params("icaauth")
assert_gov_params(cli, gov_param)

cli = do_upgrade("v1.4.0-rc5-testnet", cli.block_height() + 15)
cli = do_upgrade(c, "v1.4.0-rc5-testnet", cli.block_height() + 15)
check_basic_tx(c)


Expand Down
88 changes: 88 additions & 0 deletions integration_tests/test_upgrade_with_ibc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
import shutil
import stat
import subprocess
from pathlib import Path

import pytest
import requests
from pystarport import cluster, ports

from .ibc_utils import (
assert_channel_open_init,
prepare_network,
wait_for_check_channel_ready,
)
from .utils import do_upgrade, post_init

pytestmark = pytest.mark.upgrade


@pytest.fixture(scope="module")
def ibc(tmp_path_factory):
path = tmp_path_factory.mktemp("upgrade")
nix_name = "upgrade-test-package-recent"
configdir = Path(__file__).parent
name = "cosmovisor_with_ibc"
cmd = [
"nix-build",
configdir / f"configs/{nix_name}.nix",
]
print(*cmd)
subprocess.run(cmd, check=True)

# copy the content so the new directory is writable.
upgrades = path / "upgrades"
shutil.copytree("./result", upgrades)
mod = stat.S_IRWXU
upgrades.chmod(mod)
for d in upgrades.iterdir():
d.chmod(mod)

yield from prepare_network(
path,
name,
incentivized=False,
connection_only=True,
post_init=post_init,
chain_binary=str(upgrades / "genesis/bin/cronosd"),
relayer=cluster.Relayer.RLY.value,
)


def get_tx(base_port, hash):
p = ports.api_port(base_port)
url = f"http://127.0.0.1:{p}/cosmos/tx/v1beta1/txs/{hash}"
return requests.get(url).json()


def test_cosmovisor_upgrade(ibc):
c = ibc.cronos
cli = c.cosmos_cli()
connid = "connection-0"
v = json.dumps({"fee_version": "ics29-1", "app_version": ""})
signer = "signer2"
rsp = cli.icaauth_register_account(
connid,
from_=signer,
gas="400000",
version=v,
)
ica_txhash = rsp["txhash"]
_, channel_id = assert_channel_open_init(rsp)
wait_for_check_channel_ready(cli, connid, channel_id)
ica_address = cli.icaauth_query_account(
connid,
cli.address(signer),
)["interchain_account_address"]
print("ica address", ica_address, "channel_id", channel_id)
base_port = c.base_port(0)
ica_bf = get_tx(base_port, ica_txhash)
cli = do_upgrade(c, "v1.4", cli.block_height() + 15)

with pytest.raises(AssertionError):
cli.query_params("icaauth")

cli = do_upgrade(c, "v1.4.0-rc5-testnet", cli.block_height() + 15)
ica_af = get_tx(base_port, ica_txhash)
assert ica_bf == ica_af, ica_af
Loading

0 comments on commit 8cb8339

Please sign in to comment.