Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Apr 18, 2024
1 parent 71df6a3 commit f0a0de1
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 55 deletions.
25 changes: 14 additions & 11 deletions integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@ config {
'app-config'+: {
'app-db-backend': 'rocksdb',
'minimum-gas-prices': '100000000000basetcro',
store:: super.store,
streamers:: super.streamers,
'iavl-lazy-loading':: super['iavl-lazy-loading'],
},
validators: [super.validators[0] {
'app-config':: super['app-config'],
}] + super.validators[1:],
genesis+: {
app_state+: {
bank+: {
params: {
send_enabled: [
{
denom: 'stake',
enabled: true,
},
{
denom: 'basetcro',
enabled: false,
},
evm+: {
params+: {
// emulate the environment on production network
extra_eips: [
'2929',
'2200',
'1884',
'1344',
],
},
},
feemarket+: {
params+: {
no_base_fee: false,
base_fee:: super.base_fee,
initial_base_fee: super.base_fee,
},
},
gov: {
Expand Down
20 changes: 8 additions & 12 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
let
pkgs = import ../../nix { };
fetchFlake0 = 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;
# v1.0.15
released0 = (fetchFlake0 "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
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;
# v0.8.0
releasedGenesis = (fetchFlake "crypto-org-chain/cronos" "2f2cc88b501b47149690fdef05afbbbe5bc116c9").default;
# v1.0.15
released1_1 = (fetchFlake "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
# v1.1.1
released = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
released1_2 = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
current = pkgs.callPackage ../../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released0; }
{ name = "v1.1.0"; path = released; }
{ name = "genesis"; path = releasedGenesis; }
{ name = "v1.0.0"; path = released1_1; }
{ name = "v1.1.0"; path = released1_2; }
{ name = "v1.2"; path = current; }
]
36 changes: 20 additions & 16 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def __init__(self, cmd):
def __call__(self, cmd, *args, stdin=None, stderr=subprocess.STDOUT, **kwargs):
"execute chain-maind"
args = " ".join(build_cli_args_safe(cmd, *args, **kwargs))
return interact(f"{self.cmd} {args}", input=stdin, stderr=stderr)
cli = f"{self.cmd} {args}"
print("mm-cli", cli)
return interact(cli, input=stdin, stderr=stderr)


class CosmosCLI:
Expand Down Expand Up @@ -670,7 +672,7 @@ def edit_validator(
)
)

def gov_propose_legacy(self, proposer, kind, proposal, mode="block", **kwargs):
def gov_propose_legacy(self, proposer, kind, proposal, mode="block", method="submit-legacy-proposal", **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
kwargs.setdefault("gas", DEFAULT_GAS)
if mode:
Expand All @@ -680,11 +682,11 @@ def gov_propose_legacy(self, proposer, kind, proposal, mode="block", **kwargs):
self.raw(
"tx",
"gov",
"submit-legacy-proposal",
method,
kind,
proposal["name"],
"-y",
"--no-validate",
"--no-validate" if method == "submit-legacy-proposal" else None,
from_=proposer,
# content
title=proposal.get("title"),
Expand Down Expand Up @@ -746,19 +748,21 @@ def gov_propose_legacy(self, proposer, kind, proposal, mode="block", **kwargs):

def gov_vote(self, voter, proposal_id, option, event_query_tx=True, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
rsp = json.loads(
self.raw(
"tx",
"gov",
"vote",
proposal_id,
option,
"-y",
from_=voter,
home=self.data_dir,
**kwargs,
)
raw = self.raw(
"tx",
"gov",
"vote",
proposal_id,
option,
"-y",
from_=voter,
home=self.data_dir,
**kwargs,
)
# skip success log info that breaks json.loads
brace_index = raw.index(b"{")
json_part = raw[brace_index:]
rsp = json.loads(json_part)
if rsp["code"] == 0 and event_query_tx:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp
Expand Down
58 changes: 43 additions & 15 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
deploy_contract,
edit_ini_sections,
get_consensus_params,
get_send_enable,
send_transaction,
wait_for_block,
wait_for_new_blocks,
Expand Down Expand Up @@ -98,8 +97,6 @@ def exec(c, tmp_path_factory):
{"denom": "basetcro", "enabled": False},
{"denom": "stake", "enabled": True},
]
p = get_send_enable(port)
assert sorted(p, key=lambda x: x["denom"]) == send_enable

# export genesis from old version
c.supervisorctl("stop", "all")
Expand All @@ -113,11 +110,7 @@ def exec(c, tmp_path_factory):
wait_for_port(ports.evmrpc_port(c.base_port(0)))
wait_for_new_blocks(cli, 1)

height = cli.block_height()
target_height0 = height + 15
print("upgrade v1.1 height", target_height0)

def do_upgrade(plan_name, target, mode=None):
def do_upgrade(plan_name, target, mode=None, method="submit-legacy-proposal"):
rsp = cli.gov_propose_legacy(
"community",
"software-upgrade",
Expand All @@ -129,6 +122,7 @@ def do_upgrade(plan_name, target, mode=None):
"deposit": "10000basetcro",
},
mode=mode,
method=method,
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(c, rsp)
Expand All @@ -141,11 +135,31 @@ def do_upgrade(plan_name, target, mode=None):
wait_for_block(c.cosmos_cli(), target + 2, timeout=480)
wait_for_port(ports.rpc_port(c.base_port(0)))

do_upgrade("v1.1.0", target_height0, "block")
target_height00 = cli.block_height() + 15
print("upgrade v1.0 height", target_height00)
do_upgrade("v1.0.0", target_height00, "block", method="submit-proposal")
cli = c.cosmos_cli()

wait_for_port(ports.evmrpc_port(c.base_port(0)))
receipt = send_transaction(
c.w3,
{
"to": ADDRS["community"],
"value": 1000,
"maxFeePerGas": 10000000000000,
"maxPriorityFeePerGas": 10000,
},
)
assert receipt.status == 1

# test migrate keystore
cli.migrate_keystore()
height = cli.block_height()
target_height0 = height + 15
print("upgrade v1.1 height", target_height0)

do_upgrade("v1.1.0", target_height0, "block")
cli = c.cosmos_cli()

# check basic tx works
wait_for_port(ports.evmrpc_port(c.base_port(0)))
Expand Down Expand Up @@ -181,6 +195,7 @@ def do_upgrade(plan_name, target, mode=None):
print("old values", old_height, old_balance, old_base_fee)

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

# check basic tx works
wait_for_port(ports.evmrpc_port(c.base_port(0)))
Expand Down Expand Up @@ -218,17 +233,21 @@ def do_upgrade(plan_name, target, mode=None):

# check bank send enable
p = cli.query_bank_send()
assert sorted(p, key=lambda x: x["denom"]) == send_enable
print("mm-query_bank_send", p)
# assert sorted(p, key=lambda x: x["denom"]) == send_enable

rsp = cli.query_params("icaauth")
assert rsp["params"]["min_timeout_duration"] == "3600s", rsp
max_callback_gas = cli.query_params()["max_callback_gas"]
assert max_callback_gas == "50000", max_callback_gas

e = cli.query_params("evm", height=target_height0 - 1)["params"]["evm_denom"]
assert e == "basetcro", e
e = cli.query_params("evm", height=target_height1 - 1)["params"]["evm_denom"]
assert e == "basetcro", e
e0 = cli.query_params("evm", height=target_height0 - 1)["params"]
assert e0["evm_denom"] == "basetcro", e0
e1 = cli.query_params("evm", height=target_height1 - 1)["params"]
assert e1["evm_denom"] == "basetcro", e1

f0 = cli.query_params("feemarket", height=target_height0 - 1)["params"]
f1 = cli.query_params("feemarket", height=target_height1 - 1)["params"]

# update the genesis time = current time + 5 secs
newtime = datetime.utcnow() + timedelta(seconds=5)
Expand All @@ -242,7 +261,16 @@ def do_upgrade(plan_name, target, mode=None):
file.write_text(json.dumps(genesis))
c.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1")
wait_for_new_blocks(c.cosmos_cli(), 1)
c.supervisorctl("stop", "all")

e00 = cli.query_params("evm", height=target_height0 - 1)["params"]
assert e00 == e0, e00
e11 = cli.query_params("evm", height=target_height1 - 1)["params"]
assert e11 == e1, e1

f00 = cli.query_params("feemarket", height=target_height0 - 1)["params"]
assert f00 == f0, f00
f11 = cli.query_params("feemarket", height=target_height1 - 1)["params"]
assert f11 == f1, f1


def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
Expand Down
4 changes: 3 additions & 1 deletion integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ def cb(attrs):
rsp = n.cosmos_cli(i).gov_vote("validator", proposal_id, "yes", event_query_tx)
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_new_blocks(cli, 1)
res = cli.query_tally(proposal_id)
count = res.get("yes") or res.get("yes_count")
assert (
int(cli.query_tally(proposal_id)["yes_count"]) == cli.staking_pool()
int(count) == cli.staking_pool()
), "all validators should have voted yes"
print("wait for proposal to be activated")
proposal = cli.query_proposal(proposal_id)
Expand Down

0 comments on commit f0a0de1

Please sign in to comment.