Skip to content

Commit

Permalink
fix upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jul 19, 2024
1 parent de29a5e commit 06e4598
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ nix-integration-test-solomachine: check-network
nix-shell ./integration_tests/shell.nix --run "pytest -v -m solomachine"

nix-integration-test-upgrade: check-network
nix-shell ./integration_tests/shell.nix --run "pytest -v -m upgrade"
nix-shell ./integration_tests/shell.nix --run "pytest -v -s ./integration_tests/test_upgrade.py"

nix-integration-test-ledger: check-network
nix-shell ./integration_tests/shell.nix --run "pytest -v -m ledger"
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func (app *ChainApp) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) {
planName := "v5.0.0"
planName := "v5.0"
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let
in
buildGoApplication rec {
pname = "chain-maind";
version = "v5.0.0";
version = "v5.0";
go = buildPackages.go_1_22;
src = lib.cleanSourceWith {
name = "src";
Expand Down
71 changes: 71 additions & 0 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,62 @@ def gov_propose_legacy(
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def gov_propose_new(
self,
proposer,
kind,
proposal,
**kwargs,
):
if kind == "software-upgrade":
rsp = json.loads(
self.raw(
"tx",
"upgrade",
kind,
proposal["name"],
"-y",
"--no-validate",
from_=proposer,
# content
title=proposal.get("title"),
summary=proposal.get("summary"),
upgrade_height=proposal.get("upgrade-height"),
upgrade_time=proposal.get("upgrade-time"),
upgrade_info=proposal.get("upgrade-info", "info"),
deposit=proposal.get("deposit"),
# basic
home=self.data_dir,
node=self.node_rpc,
keyring_backend="test",
chain_id=self.chain_id,
**kwargs,
)
)
else:
rsp = json.loads(
self.raw(
"tx",
"upgrade",
kind,
"-y",
from_=proposer,
# content
title=proposal.get("title"),
summary=proposal.get("summary"),
deposit=proposal.get("deposit"),
# basic
home=self.data_dir,
node=self.node_rpc,
keyring_backend="test",
chain_id=self.chain_id,
**kwargs,
)
)
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def transfer(
self,
from_,
Expand Down Expand Up @@ -288,6 +344,21 @@ def gov_propose_legacy(
**kwargs,
)

def gov_propose_new(
self,
proposer,
kind,
proposal,
i=0,
**kwargs,
):
return self.cosmos_cli(i).gov_propose_new(
proposer,
kind,
proposal,
**kwargs,
)

def transfer(self, from_, to, coins, i=0, generate_only=False, **kwargs):
return self.cosmos_cli(i).transfer(from_, to, coins, generate_only, **kwargs)

Expand Down
76 changes: 67 additions & 9 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .utils import (
cluster_fixture,
find_log_event_attrs,
get_proposal_id,
parse_events,
wait_for_block,
wait_for_block_time,
wait_for_new_blocks,
Expand Down Expand Up @@ -80,6 +80,24 @@ def migrate_genesis_time(cluster, i=0):
(cluster.home(i) / "config/genesis.json").write_text(json.dumps(genesis))


def find_log_event_attrs_legacy(logs, ev_type, cond=None):
for ev in logs[0]["events"]:
if ev["type"] == ev_type:
attrs = {attr["key"]: attr["value"] for attr in ev["attributes"]}
if cond is None or cond(attrs):
return attrs
return None


def get_proposal_id_legacy(rsp, msg=",/cosmos.gov.v1.MsgExecLegacyContent"):
def cb(attrs):
return "proposal_id" in attrs

ev = find_log_event_attrs_legacy(rsp["logs"], "submit_proposal", cb)
assert ev["proposal_messages"] == msg, rsp
return ev["proposal_id"]


# use function scope to re-initialize for each test case
@pytest.fixture(scope="function")
def cosmovisor_cluster(worker_index, pytestconfig, tmp_path_factory):
Expand Down Expand Up @@ -123,7 +141,7 @@ def test_cosmovisor(cosmovisor_cluster):
assert rsp["code"] == 0, rsp

# get proposal_id
ev = find_log_event_attrs(rsp["events"], "submit_proposal")
ev = find_log_event_attrs_legacy(rsp["logs"], "submit_proposal")
assert ev["proposal_messages"] == ",/cosmos.gov.v1.MsgExecLegacyContent", rsp
proposal_id = ev["proposal_id"]

Expand Down Expand Up @@ -168,9 +186,9 @@ def propose_and_pass(
assert rsp["code"] == 0, rsp["raw_log"]
# get proposal_id
if propose_legacy:
proposal_id = get_proposal_id(rsp, ",/cosmos.gov.v1.MsgExecLegacyContent")
proposal_id = get_proposal_id_legacy(rsp)
else:
ev = find_log_event_attrs(rsp["events"], "submit_proposal")
ev = parse_events(rsp["logs"])["submit_proposal"]
assert ev["proposal_type"] == "SoftwareUpgrade", rsp
proposal_id = ev["proposal_id"]
proposal = cluster.query_proposal(proposal_id)
Expand All @@ -195,6 +213,46 @@ def propose_and_pass(
return proposal


def propose_and_pass_new(
cluster,
kind,
proposal,
**kwargs,
):
rsp = cluster.gov_propose_new(
"community",
kind,
proposal,
**kwargs,
)
assert rsp["code"] == 0, rsp["raw_log"]
# get proposal_id
ev = find_log_event_attrs(rsp["events"], "submit_proposal")
proposal_messages = "SoftwareUpgrade"
if kind == "cancel-software-upgrade":
proposal_messages = "MsgCancelUpgrade"
assert proposal_messages in ev["proposal_messages"], rsp
proposal_id = ev["proposal_id"]
proposal = cluster.query_proposal(proposal_id)
assert proposal["status"] == "PROPOSAL_STATUS_VOTING_PERIOD", proposal
for i in range(2):
rsp = cluster.gov_vote(
"validator",
proposal_id,
"yes",
i=i,
)
assert rsp["code"] == 0, rsp["raw_log"]

proposal = cluster.query_proposal(proposal_id)
wait_for_block_time(
cluster, isoparse(proposal["voting_end_time"]) + timedelta(seconds=1)
)
proposal = cluster.query_proposal(proposal_id)
assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal
return proposal


def upgrade(cluster, plan_name, target_height, propose_legacy=True):
print("upgrade height", target_height)
propose_and_pass(
Expand Down Expand Up @@ -375,7 +433,7 @@ def assert_commission(adr, expected):
denomname = "testdenomname"
creator = cluster.address("community")
rsp = cluster.create_nft(creator, denomid, denomname, event_query_tx=False)
ev = find_log_event_attrs(rsp["events"], "issue_denom")
ev = find_log_event_attrs_legacy(rsp["logs"], "issue_denom")
assert ev == {
"denom_id": denomid,
"denom_name": denomname,
Expand Down Expand Up @@ -442,25 +500,25 @@ def test_cancel_upgrade(cluster):
upgrade_height = cluster.block_height() + 30
print("propose upgrade plan")
print("upgrade height", upgrade_height)
propose_and_pass(
propose_and_pass_new(
cluster,
"software-upgrade",
{
"name": plan_name,
"title": "upgrade test",
"description": "ditto",
"summary": "summary",
"upgrade-height": upgrade_height,
"deposit": "0.1cro",
},
)

print("cancel upgrade plan")
propose_and_pass(
propose_and_pass_new(
cluster,
"cancel-software-upgrade",
{
"title": "there is bug, cancel upgrade",
"description": "there is bug, cancel upgrade",
"summary": "summary",
"deposit": "0.1cro",
},
)
Expand Down
8 changes: 5 additions & 3 deletions integration_tests/upgrade-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ let
shortRev = builtins.substring 0 7 rev;
};
}).defaultNix;
released4 = (fetchFlake "crypto-org-chain/chain-main" "b3226f06fd2a236f9957304c4d83b0ea06ed2604").default;
released4_2 = (fetchFlake "crypto-org-chain/chain-main" "b3226f06fd2a236f9957304c4d83b0ea06ed2604").default;
released4_3 = (fetchFlake "crypto-org-chain/chain-main" "7598bc46226a1b58116da2e6bd3903aca5b5313b").default;
current = pkgs.callPackage ../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released; }
{ name = "v2.0.0"; path = released2; }
{ name = "v3.0.0"; path = released3; }
{ name = "v4.2.0"; path = released4; }
{ name = "v4.3.0"; path = current; }
{ name = "v4.2.0"; path = released4_2; }
{ name = "v4.3.0"; path = released4_3; }
{ name = "v5.0"; path = current; }
]
7 changes: 7 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ def get_ledger():
return ledger.Ledger()


def parse_events(logs):
return {
ev["type"]: {attr["key"]: attr["value"] for attr in ev["attributes"]}
for ev in logs[0]["events"]
}


def find_log_event_attrs(events, ev_type, cond=None):
for ev in events:
if ev["type"] == ev_type:
Expand Down

0 comments on commit 06e4598

Please sign in to comment.