|
| 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