test: example upgrade handler and systems test (#24182)

This commit is contained in:
Alex | Interchain Labs
2025-03-29 00:46:08 +00:00
committed by GitHub
parent e85a5c0bc1
commit 056bcd7022
5 changed files with 145 additions and 29 deletions
+1 -1
View File
@@ -12,7 +12,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
+4 -22
View File
@@ -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)
@@ -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"}
+133
View File
@@ -0,0 +1,133 @@
//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)
// 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
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"},
}
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)
require.Equal(t, upgradeHeight+1, systest.Sut.CurrentHeight())
// 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)
}