Skip to content

Commit

Permalink
test: Fix cosmovisor upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Jul 5, 2024
1 parent 179a38d commit 8d592bd
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 55 deletions.
8 changes: 7 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
Expand Down Expand Up @@ -1085,8 +1087,12 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint: staticcheck
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName) // TODO(dudong2): withkeytable
paramsKeeper.Subspace(ibctransfertypes.ModuleName)

keyTable := ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)

// ethermint subspaces
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())
Expand Down
15 changes: 5 additions & 10 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
ibcclientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations"
evmtypes "github.com/evmos/ethermint/x/evm/types"
Expand All @@ -49,7 +49,7 @@ import (

func (app *EthermintApp) RegisterUpgradeHandlers(
cdc codec.BinaryCodec,
clientKeeper clientkeeper.Keeper,
ibcClientKeeper ibcclientkeeper.Keeper,
consensusParamsKeeper consensusparamskeeper.Keeper,
paramsKeeper paramskeeper.Keeper,

Check warning on line 54 in app/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

unused-parameter: parameter 'paramsKeeper' seems to be unused, consider removing or renaming it as _ (revive)
) {
Expand Down Expand Up @@ -100,20 +100,15 @@ func (app *EthermintApp) RegisterUpgradeHandlers(

// ibc v7
// OPTIONAL: prune expired tendermint consensus states to save storage space
if _, err := ibctmmigrations.PruneExpiredConsensusStates(sdkCtx, cdc, clientKeeper); err != nil {
return fromVM, err
}

legacyBaseAppSubspace := paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
if err := baseapp.MigrateParams(sdkCtx, legacyBaseAppSubspace, &consensusParamsKeeper.ParamsStore); err != nil {
if _, err := ibctmmigrations.PruneExpiredConsensusStates(sdkCtx, cdc, ibcClientKeeper); err != nil {
return fromVM, err
}

// ibc v7.1
// explicitly update the IBC 02-client params, adding the localhost client type
params := clientKeeper.GetParams(sdkCtx)
params := ibcClientKeeper.GetParams(sdkCtx)
params.AllowedClients = append(params.AllowedClients, exported.Localhost)
clientKeeper.SetParams(sdkCtx, params)
ibcClientKeeper.SetParams(sdkCtx, params)

// cosmos-sdk v047
// Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module.
Expand Down
6 changes: 6 additions & 0 deletions tests/integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ config {
'minimum-gas-prices': '100000000000aphoton',
},
genesis+: {
consensus_params+: {
block+: {
bax_bytes: '1048576',
max_gas: '81500000',
},
},
app_state+: {
feemarket+: {
params+: {
Expand Down
127 changes: 83 additions & 44 deletions tests/integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import re
import subprocess
import time
from pathlib import Path

import pytest
Expand All @@ -17,7 +18,8 @@
parse_events,
send_transaction,
wait_for_block,
wait_for_block_time,
wait_for_new_blocks_legacy,
wait_for_block_time_legacy,

Check failure on line 22 in tests/integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_upgrade.py:22:1: I001 isort found an import in the wrong position
wait_for_port,
)

Expand Down Expand Up @@ -53,9 +55,9 @@ def post_init(path, base_port, config):
i = m.group(1)
ini[section].update(
{
"command": f"cosmovisor start --home %(here)s/node{i}",
"command": f"cosmovisor run start --home %(here)s/node{i}",
"environment": (
f"DAEMON_NAME=ethermintd,DAEMON_HOME=%(here)s/node{i}"
f"DAEMON_NAME=ethermintd,DAEMON_HOME=%(here)s/node{i},DAEMON_RESTART_AFTER_UPGRADE=false"

Check failure on line 60 in tests/integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_upgrade.py:60:89: E501 line too long (113 > 88 characters)
),
}
)
Expand Down Expand Up @@ -119,7 +121,10 @@ def test_cosmovisor_upgrade(custom_ethermint: Ethermint):
assert rsp["code"] == 0, rsp["raw_log"]

# get proposal_id
ev = parse_events(rsp["logs"])["submit_proposal"]
wait_for_new_blocks_legacy(cli, 1, sleep=0.1)
logs = cli.query_tx("hash", rsp["txhash"])["logs"]

Check failure on line 126 in tests/integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_upgrade.py:126:1: W293 blank line contains whitespace
ev = parse_events(logs)["submit_proposal"]
proposal_id = ev["proposal_id"]

rsp = cli.gov_vote("validator", proposal_id, "yes")
Expand All @@ -128,7 +133,7 @@ def test_cosmovisor_upgrade(custom_ethermint: Ethermint):
# assert rsp["code"] == 0, rsp["raw_log"]

proposal = cli.query_proposal(proposal_id)
wait_for_block_time(cli, isoparse(proposal["voting_end_time"]))
wait_for_block_time_legacy(cli, isoparse(proposal["voting_end_time"]))
proposal = cli.query_proposal(proposal_id)
assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal

Expand All @@ -137,46 +142,80 @@ def test_cosmovisor_upgrade(custom_ethermint: Ethermint):
Path(custom_ethermint.chain_binary).parent.parent.parent
/ f"{plan_name}/bin/ethermintd"
)
cli = custom_ethermint.cosmos_cli()

# block should pass the target height
wait_for_block(cli, target_height + 1, timeout=480)
wait_for_port(ports.rpc_port(custom_ethermint.base_port(0)))

# test migrate keystore
cli.migrate_keystore()

# check basic tx works after upgrade
wait_for_port(ports.evmrpc_port(custom_ethermint.base_port(0)))
# wait until cosmovosor finished
proc = []
for i in range(2):
while True:
try:
c = custom_ethermint.cosmos_cli(i)
c.status()
except:

Check failure on line 153 in tests/integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_upgrade.py:153:13: E722 do not use bare 'except'
break
finally:
time.sleep(5)

# start ethermint
for i in range(2):
with (custom_ethermint.base_dir / f"node{i}.log").open("a") as logfile:
p = subprocess.Popen(
[
custom_ethermint.chain_binary,
"start",
"--home",
custom_ethermint.base_dir / f"node{i}",
],
stdout=logfile,
stderr=subprocess.STDOUT,
)
proc.append(p)
cli = custom_ethermint.cosmos_cli()

receipt = send_transaction(
w3,
{
"to": ADDRS["community"],
"value": 1000,
"maxFeePerGas": 1000000000000,
"maxPriorityFeePerGas": 10000,
},
)
assert receipt.status == 1
try:
# block should pass the target height
wait_for_block(cli, target_height + 1, timeout=20)
wait_for_port(ports.rpc_port(custom_ethermint.base_port(0)))

# test migrate keystore
cli.migrate_keystore()

# check basic tx works after upgrade
wait_for_port(ports.evmrpc_port(custom_ethermint.base_port(0)))

receipt = send_transaction(
w3,
{
"to": ADDRS["community"],
"value": 1000,
"maxFeePerGas": 1000000000000,
"maxPriorityFeePerGas": 10000,
},
)
assert receipt.status == 1

# check json-rpc query on older blocks works
assert old_balance == w3.eth.get_balance(
ADDRS["validator"], block_identifier=old_height
)
assert old_base_fee == w3.eth.get_block(old_height).baseFeePerGas

# check eth_call on older blocks works
assert old_erc20_balance == contract.caller(
block_identifier=target_height - 2
).balanceOf(ADDRS["validator"])
p = json.loads(
cli.raw(
"query",
"ibc",
"client",
"params",
home=cli.data_dir,
# check json-rpc query on older blocks works
assert old_balance == w3.eth.get_balance(
ADDRS["validator"], block_identifier=old_height
)
)
assert p == {"allowed_clients": ["06-solomachine", "07-tendermint", "09-localhost"]}
assert old_base_fee == w3.eth.get_block(old_height).baseFeePerGas

# check eth_call on older blocks works
assert old_erc20_balance == contract.caller(
block_identifier=target_height - 2
).balanceOf(ADDRS["validator"])
p = json.loads(
cli.raw(
"query",
"ibc",
"client",
"params",
home=cli.data_dir,
node=cli.node_rpc,
output="json",
)
)
assert p == {"allowed_clients": ["06-solomachine", "07-tendermint", "09-localhost"]}

Check failure on line 217 in tests/integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_upgrade.py:217:89: E501 line too long (92 > 88 characters)
finally:
for p in proc:
p.terminate()
p.wait()

Check failure on line 221 in tests/integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_upgrade.py:221:21: W292 no newline at end of file
18 changes: 18 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def wait_for_new_blocks(cli, n, sleep=0.5):
return cur_height


def wait_for_new_blocks_legacy(cli, n, sleep=0.5):
cur_height = begin_height = int((cli.status())["SyncInfo"]["latest_block_height"])
while cur_height - begin_height < n:
time.sleep(sleep)
cur_height = int((cli.status())["SyncInfo"]["latest_block_height"])
return cur_height


def wait_for_block(cli, height, timeout=240):
for _ in range(timeout * 2):
try:
Expand Down Expand Up @@ -124,6 +132,16 @@ def wait_for_block_time(cli, t):
time.sleep(0.5)


def wait_for_block_time_legacy(cli, t):
print("wait for block time", t)
while True:
now = isoparse((cli.status())["SyncInfo"]["latest_block_time"])
print("block time now: ", now)
if now >= t:
break
time.sleep(0.5)


def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]):
"""
deploy contract and return the deployed contract instance
Expand Down

0 comments on commit 8d592bd

Please sign in to comment.