Skip to content

Commit 48e3c83

Browse files
test: v0.4.1 -> main upgrade test (cosmos#498)
* wip upgrade test * upgrade test complete * make script * fix the order * remove that * fixes * fetch tags
1 parent 03083a8 commit 48e3c83

File tree

4 files changed

+151
-3
lines changed

4 files changed

+151
-3
lines changed

.github/workflows/system-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
with:
3030
version: stable
3131
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
fetch-tags: true
3235
- uses: technote-space/[email protected]
3336
with:
3437
PATTERNS: |

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,18 @@ test-rpc-compat-stop:
378378

379379
.PHONY: localnet-start localnet-stop localnet-build-env localnet-build-nodes test-rpc-compat test-rpc-compat-stop
380380

381-
test-system: build
382-
ulimit -n 1300
381+
test-system: build-v04 build
383382
mkdir -p ./tests/systemtests/binaries/
384383
cp $(BUILDDIR)/evmd ./tests/systemtests/binaries/
385384
$(MAKE) -C tests/systemtests test
386385

386+
build-v04:
387+
mkdir -p ./tests/systemtests/binaries/v0.4
388+
git checkout v0.4.1
389+
make build
390+
cp $(BUILDDIR)/evmd ./tests/systemtests/binaries/v0.4
391+
git checkout -
392+
387393
mocks:
388394
@echo "--> generating mocks"
389395
@go get github.com/vektra/mockery/v2

evmd/upgrades.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
package evmd
22

3+
import (
4+
"context"
5+
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"github.com/cosmos/cosmos-sdk/types/module"
8+
9+
storetypes "cosmossdk.io/store/types"
10+
upgradetypes "cosmossdk.io/x/upgrade/types"
11+
)
12+
13+
// UpgradeName defines the on-chain upgrade name for the sample EVMD upgrade
14+
// from v0.4.0 to v0.5.0.
15+
//
16+
// NOTE: This upgrade defines a reference implementation of what an upgrade
17+
// could look like when an application is migrating from EVMD version
18+
// v0.4.0 to v0.5.x
19+
const UpgradeName = "v0.4.0-to-v0.5.0"
20+
321
func (app EVMD) RegisterUpgradeHandlers() {
4-
// No upgrades registered yet
22+
app.UpgradeKeeper.SetUpgradeHandler(
23+
UpgradeName,
24+
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
25+
sdk.UnwrapSDKContext(ctx).Logger().Debug("this is a debug level message to test that verbose logging mode has properly been enabled during a chain upgrade")
26+
return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
27+
},
28+
)
29+
30+
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
31+
if err != nil {
32+
panic(err)
33+
}
34+
35+
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
36+
storeUpgrades := storetypes.StoreUpgrades{
37+
Added: []string{},
38+
}
39+
// configure store loader that checks if version == upgradeHeight and applies store upgrades
40+
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
41+
}
542
}

tests/systemtests/upgrade_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//go:build system_test
2+
3+
package systemtests
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
"time"
9+
10+
"github.com/stretchr/testify/require"
11+
"github.com/tidwall/gjson"
12+
13+
systest "cosmossdk.io/systemtests"
14+
15+
sdk "github.com/cosmos/cosmos-sdk/types"
16+
"github.com/cosmos/cosmos-sdk/types/address"
17+
)
18+
19+
const (
20+
upgradeHeight int64 = 22
21+
upgradeName = "v0.4.0-to-v0.5.0" // must match UpgradeName in evmd/upgrades.go
22+
)
23+
24+
func TestChainUpgrade(t *testing.T) {
25+
// Scenario:
26+
// start a legacy chain with some state
27+
// when a chain upgrade proposal is executed
28+
// then the chain upgrades successfully
29+
systest.Sut.StopChain()
30+
31+
currentBranchBinary := systest.Sut.ExecBinary()
32+
currentInitializer := systest.Sut.TestnetInitializer()
33+
34+
legacyBinary := systest.WorkDir + "/binaries/v0.4/evmd"
35+
systest.Sut.SetExecBinary(legacyBinary)
36+
systest.Sut.SetTestnetInitializer(systest.InitializerWithBinary(legacyBinary, systest.Sut))
37+
systest.Sut.SetupChain()
38+
39+
votingPeriod := 5 * time.Second // enough time to vote
40+
systest.Sut.ModifyGenesisJSON(t, systest.SetGovVotingPeriod(t, votingPeriod))
41+
42+
systest.Sut.StartChain(t, fmt.Sprintf("--halt-height=%d", upgradeHeight+1), "--chain-id=local-4221", "--minimum-gas-prices=0.00atest")
43+
44+
cli := systest.NewCLIWrapper(t, systest.Sut, systest.Verbose)
45+
govAddr := sdk.AccAddress(address.Module("gov")).String()
46+
// submit upgrade proposal
47+
proposal := fmt.Sprintf(`
48+
{
49+
"messages": [
50+
{
51+
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
52+
"authority": %q,
53+
"plan": {
54+
"name": %q,
55+
"height": "%d"
56+
}
57+
}
58+
],
59+
"metadata": "ipfs://CID",
60+
"deposit": "100000000stake",
61+
"title": "my upgrade",
62+
"summary": "testing"
63+
}`, govAddr, upgradeName, upgradeHeight)
64+
rsp := cli.SubmitGovProposal(proposal, "--fees=10000000000000000000atest", "--from=node0")
65+
systest.RequireTxSuccess(t, rsp)
66+
raw := cli.CustomQuery("q", "gov", "proposals", "--depositor", cli.GetKeyAddr("node0"))
67+
proposals := gjson.Get(raw, "proposals.#.id").Array()
68+
require.NotEmpty(t, proposals, raw)
69+
proposalID := proposals[len(proposals)-1].String()
70+
71+
for i := range systest.Sut.NodesCount() {
72+
go func(i int) { // do parallel
73+
systest.Sut.Logf("Voting: validator %d\n", i)
74+
rsp := cli.Run("tx", "gov", "vote", proposalID, "yes", "--fees=10000000000000000000atest", "--from", cli.GetKeyAddr(fmt.Sprintf("node%d", i)))
75+
systest.RequireTxSuccess(t, rsp)
76+
}(i)
77+
}
78+
79+
systest.Sut.AwaitBlockHeight(t, upgradeHeight-1, 60*time.Second)
80+
t.Logf("current_height: %d\n", systest.Sut.CurrentHeight())
81+
raw = cli.CustomQuery("q", "gov", "proposal", proposalID)
82+
proposalStatus := gjson.Get(raw, "proposal.status").String()
83+
require.Equal(t, "PROPOSAL_STATUS_PASSED", proposalStatus, raw)
84+
85+
t.Log("waiting for upgrade info")
86+
systest.Sut.AwaitUpgradeInfo(t)
87+
systest.Sut.StopChain()
88+
89+
t.Log("Upgrade height was reached. Upgrading chain")
90+
systest.Sut.SetExecBinary(currentBranchBinary)
91+
systest.Sut.SetTestnetInitializer(currentInitializer)
92+
systest.Sut.StartChain(t, "--chain-id=local-4221")
93+
94+
require.Equal(t, upgradeHeight+1, systest.Sut.CurrentHeight())
95+
96+
// smoke test to make sure the chain still functions.
97+
cli = systest.NewCLIWrapper(t, systest.Sut, systest.Verbose)
98+
to := cli.GetKeyAddr("node1")
99+
from := cli.GetKeyAddr("node0")
100+
got := cli.Run("tx", "bank", "send", from, to, "1atest", "--from=node0", "--fees=10000000000000000000atest", "--chain-id=local-4221")
101+
systest.RequireTxSuccess(t, got)
102+
}

0 commit comments

Comments
 (0)