Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"context"

storetypes "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/types/module"
epochstypes "github.com/cosmos/cosmos-sdk/x/epochs/types"
)

// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
// from v047 to v050.
// from v050 to v053.
//
// NOTE: This upgrade defines a reference implementation of what an upgrade
// could look like when an application is migrating from Cosmos SDK version
// v0.47.x to v0.50.x.
const UpgradeName = "v047-to-v050"
// v0.50.x to v0.53.x.
const UpgradeName = "v050-to-v053"

func (app SimApp) RegisterUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
Expand All @@ -34,7 +34,8 @@ func (app SimApp) RegisterUpgradeHandlers() {
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
circuittypes.ModuleName,
epochstypes.ModuleName,
// protocolpooltypes.ModuleName,
},
}

Expand Down
2 changes: 1 addition & 1 deletion systemtests/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (s *SystemUnderTest) AwaitBlockHeight(t *testing.T, targetHeight int64, tim
// Returns the new height
func (s *SystemUnderTest) AwaitNextBlock(t *testing.T, timeout ...time.Duration) int64 {
t.Helper()
maxWaitTime := s.blockTime * 3
maxWaitTime := s.blockTime * 6
if len(timeout) != 0 { // optional argument to overwrite default timeout
maxWaitTime = timeout[0]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/systemtests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ replace (
require (
cosmossdk.io/systemtests v0.0.0-00010101000000-000000000000
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/cosmos-sdk v0.50.13 // indirect
github.com/cosmos/cosmos-sdk v0.50.13
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/cosmos/iavl v1.2.2 // indirect
Expand Down
26 changes: 4 additions & 22 deletions tests/systemtests/unordered_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestTxBackwardsCompatability(t *testing.T) {
var (
denom = "stake"
transferAmount int64 = 1000
testSeed = "scene learn remember glide apple expand quality spawn property shoe lamp carry upset blossom draft reject aim file trash miss script joy only measure"
)
systest.Sut.ResetChain(t)

Expand All @@ -72,27 +71,10 @@ func TestTxBackwardsCompatability(t *testing.T) {
// generate a deterministic account. we'll use this seed again later in the v50 chain.
senderAddr := v53CLI.AddKeyFromSeed("account1", testSeed)

//// Now we're going to switch to a v.50 chain.
legacyBinary := systest.WorkDir + "/binaries/v0.50/simd"

// setup the v50 chain. v53 made some changes to testnet command, so we'll have to adjust here.
// this only uses 1 node.
legacySut := systest.NewSystemUnderTest("simd", systest.Verbose, 1, 1*time.Second)
// we need to explicitly set this here as the constructor infers the exec binary is in the "binaries" directory.
legacySut.SetExecBinary(legacyBinary)
legacySut.SetTestnetInitializer(systest.LegacyInitializerWithBinary(legacyBinary, legacySut))
legacySut.SetupChain()
v50CLI := systest.NewCLIWrapper(t, legacySut, systest.Verbose)
v50CLI.AddKeyFromSeed("account1", testSeed)
legacySut.ModifyGenesisCLI(t,
// add some bogus accounts because the v53 chain had 4 nodes which takes account numbers 1-4.
[]string{"genesis", "add-genesis-account", v50CLI.AddKey("foo"), "10000000000stake"},
[]string{"genesis", "add-genesis-account", v50CLI.AddKey("bar"), "10000000000stake"},
[]string{"genesis", "add-genesis-account", v50CLI.AddKey("baz"), "10000000000stake"},
// we need our sender to be account 5 because that's how it was signed in the v53 scenario.
[]string{"genesis", "add-genesis-account", senderAddr, "10000000000stake"},
)

v50CLI, legacySut := createLegacyBinary(t, initAccount{
address: senderAddr,
balance: "10000000000stake",
})
legacySut.StartChain(t)

bankSendCmdArgs := []string{"tx", "bank", "send", senderAddr, valAddr, fmt.Sprintf("%d%s", transferAmount, denom), "--chain-id=" + v50CLI.ChainID(), "--fees=10stake", "--sign-mode=direct"}
Expand Down
129 changes: 129 additions & 0 deletions tests/systemtests/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//go:build system_test

package systemtests

import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"

systest "cosmossdk.io/systemtests"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
)

const (
testSeed = "scene learn remember glide apple expand quality spawn property shoe lamp carry upset blossom draft reject aim file trash miss script joy only measure"
upgradeHeight int64 = 22
upgradeName = "v050-to-v053" // must match UpgradeName in simapp/upgrades.go
)

type initAccount struct {
address string
balance string
}

func createLegacyBinary(t *testing.T, extraAccounts ...initAccount) (*systest.CLIWrapper, *systest.SystemUnderTest) {
t.Helper()

legacyBinary := systest.WorkDir + "/binaries/v0.50/simd"

//// Now we're going to switch to a v.50 chain.
t.Logf("+++ legacy binary: %s\n", legacyBinary)

// setup the v50 chain. v53 made some changes to testnet command, so we'll have to adjust here.
// this only uses 1 node.
legacySut := systest.NewSystemUnderTest("simd", systest.Verbose, 1, 1*time.Second)
// we need to explicitly set this here as the constructor infers the exec binary is in the "binaries" directory.
legacySut.SetExecBinary(legacyBinary)
legacySut.SetTestnetInitializer(systest.LegacyInitializerWithBinary(legacyBinary, legacySut))
legacySut.SetupChain()
v50CLI := systest.NewCLIWrapper(t, legacySut, systest.Verbose)
v50CLI.AddKeyFromSeed("account1", testSeed)

modifications := [][]string{
{"genesis", "add-genesis-account", v50CLI.AddKey("foo"), "10000000000stake"},
{"genesis", "add-genesis-account", v50CLI.AddKey("bar"), "10000000000stake"},
{"genesis", "add-genesis-account", v50CLI.AddKey("baz"), "10000000000stake"},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add a comment here:

"typically, SystemUnderTest will create a node with 4 validators. In the legacy setup, we create run a single validator network. This means we need to add 3 more accounts in order to make further account additions map to the same account number in state."

for _, extraAccount := range extraAccounts {
modifications = append(modifications, []string{"genesis", "add-genesis-account", extraAccount.address, extraAccount.balance})
}

legacySut.ModifyGenesisCLI(t,
modifications...,
)

return v50CLI, legacySut
}

func TestChainUpgrade(t *testing.T) {
// Scenario:
// start a legacy chain with some state
// when a chain upgrade proposal is executed
// then the chain upgrades successfully
systest.Sut.StopChain()

currentBranchBinary := systest.Sut.ExecBinary()
currentInitializer := systest.Sut.TestnetInitializer()

legacyBinary := systest.WorkDir + "/binaries/v0.50/simd"
systest.Sut.SetExecBinary(legacyBinary)
systest.Sut.SetTestnetInitializer(systest.NewModifyConfigYamlInitializer(legacyBinary, systest.Sut))
systest.Sut.SetupChain()

votingPeriod := 5 * time.Second // enough time to vote
systest.Sut.ModifyGenesisJSON(t, systest.SetGovVotingPeriod(t, votingPeriod))

systest.Sut.StartChain(t, fmt.Sprintf("--halt-height=%d", upgradeHeight+1))

cli := systest.NewCLIWrapper(t, systest.Sut, systest.Verbose)
govAddr := sdk.AccAddress(address.Module("gov")).String()
// submit upgrade proposal
proposal := fmt.Sprintf(`
{
"messages": [
{
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
"authority": %q,
"plan": {
"name": %q,
"height": "%d"
}
}
],
"metadata": "ipfs://CID",
"deposit": "100000000stake",
"title": "my upgrade",
"summary": "testing"
}`, govAddr, upgradeName, upgradeHeight)
proposalID := cli.SubmitAndVoteGovProposal(proposal)
t.Logf("current_height: %d\n", systest.Sut.CurrentHeight())
raw := cli.CustomQuery("q", "gov", "proposal", proposalID)
t.Log(raw)

systest.Sut.AwaitBlockHeight(t, upgradeHeight-1, 60*time.Second)
t.Logf("current_height: %d\n", systest.Sut.CurrentHeight())
raw = cli.CustomQuery("q", "gov", "proposal", proposalID)
proposalStatus := gjson.Get(raw, "proposal.status").String()
require.Equal(t, "PROPOSAL_STATUS_PASSED", proposalStatus, raw)

t.Log("waiting for upgrade info")
systest.Sut.AwaitUpgradeInfo(t)
systest.Sut.StopChain()

t.Log("Upgrade height was reached. Upgrading chain")
systest.Sut.SetExecBinary(currentBranchBinary)
systest.Sut.SetTestnetInitializer(currentInitializer)
systest.Sut.StartChain(t)
Comment on lines +116 to +124
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we assert that the correct height was reached? and that the new chain starts at upgradeHeight + 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added assertion assert block height

// cli = systest.NewCLIWrapper(t, systest.Sut, systest.Verbose)

// smoke test that new version runs
// TODO: add once protocol pool is enabled
// got := cli.Run("tx", "protocolpool", "fund-community-pool", "100stake", "--from=node0")
// systest.RequireTxSuccess(t, got)
}
Loading