-
Notifications
You must be signed in to change notification settings - Fork 4k
test: example upgrade handler and systems test #24182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c38514
update
66bae83
resolve
dd3b598
try
970530d
ok
0875489
ook-for-now
19370c4
Merge branch 'release/v0.53.x' into upgrade-test
d33709e
fixingtown
60768fa
lint-fix
29216eb
Merge branch 'release/v0.53.x' into upgrade-test
9259c15
Merge branch 'release/v0.53.x' into upgrade-test
0c55c09
assert block height
39715a1
Merge branch 'release/v0.53.x' into upgrade-test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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