Skip to content

Commit

Permalink
test: fix e2e changeover test (#2116)
Browse files Browse the repository at this point in the history
* Fix changeover e2e test

* rename e2e upgrade action

* nits
  • Loading branch information
bermuell authored Jul 31, 2024
1 parent 38826fa commit 80d4ca9
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 58 deletions.
1 change: 0 additions & 1 deletion app/consumer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ func New(
vestingtypes.ModuleName,
ibcconsumertypes.ModuleName,
)
app.SetPreBlocker(app.PreBlocker)

app.MM.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand Down
3 changes: 2 additions & 1 deletion app/sovereign/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import (
const (
AppName = "interchain-security-s"
upgradeName = "v07-Theta" // arbitrary name, define your own appropriately named upgrade
AccountAddressPrefix = "cosmos"
AccountAddressPrefix = "consumer"
)

var (
Expand Down Expand Up @@ -602,6 +602,7 @@ func New(
app.SetAnteHandler(anteHandler)

app.SetInitChainer(app.InitChainer)
app.SetPreBlocker(app.PreBlocker)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

Expand Down
3 changes: 3 additions & 0 deletions cmd/interchain-security-sd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (

svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"

appparams "github.com/cosmos/interchain-security/v5/app/params"
app "github.com/cosmos/interchain-security/v5/app/sovereign"

"github.com/cosmos/interchain-security/v5/cmd/interchain-security-sd/cmd"
)

func main() {
appparams.SetAddressPrefixes(app.AccountAddressPrefix)
rootCmd := cmd.NewRootCmd()

if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/action_rapid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ func GetStartSovereignChainActionGen() *rapid.Generator[StartSovereignChainActio
})
}

func GetSubmitLegacyUpgradeProposalActionGen() *rapid.Generator[LegacyUpgradeProposalAction] {
return rapid.Custom(func(t *rapid.T) LegacyUpgradeProposalAction {
return LegacyUpgradeProposalAction{
func GetSubmitLegacyUpgradeProposalActionGen() *rapid.Generator[UpgradeProposalAction] {
return rapid.Custom(func(t *rapid.T) UpgradeProposalAction {
return UpgradeProposalAction{
ChainID: GetChainIDGen().Draw(t, "ChainID"),
UpgradeTitle: rapid.String().Draw(t, "UpgradeTitle"),
Proposer: GetValidatorIDGen().Draw(t, "Proposer"),
Expand Down
101 changes: 72 additions & 29 deletions tests/e2e/actions_sovereign_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,48 +103,91 @@ func (tr Chain) startSovereignChain(
}, verbose)
}

type LegacyUpgradeProposalAction struct {
type UpgradeProposalAction struct {
ChainID ChainID
UpgradeTitle string
Proposer ValidatorID
UpgradeHeight uint64
Expedited bool
}

func (tr *Chain) submitLegacyUpgradeProposal(action LegacyUpgradeProposalAction, verbose bool) {
submit := fmt.Sprintf(
`%s tx gov submit-legacy-proposal software-upgrade %s \
--title %s \
--deposit 10000000stake \
--upgrade-height %s \
--upgrade-info "perform changeover" \
--description "perform changeover" \
--gas 900000 \
--from validator%s \
--keyring-backend test \
--chain-id %s \
--home %s \
--node %s \
--no-validate \
-y`,
tr.testConfig.chainConfigs[ChainID("sover")].BinaryName,
action.UpgradeTitle,
action.UpgradeTitle,
fmt.Sprint(action.UpgradeHeight),
action.Proposer,
tr.testConfig.chainConfigs[ChainID("sover")].ChainId,
tr.getValidatorHome(ChainID("sover"), action.Proposer),
tr.getValidatorNode(ChainID("sover"), action.Proposer),
)
cmd := tr.target.ExecCommand("/bin/bash", "-c", submit)
func (tr *Chain) submitUpgradeProposal(action UpgradeProposalAction, verbose bool) {

// Get authority address
binary := tr.testConfig.chainConfigs[ChainID("sover")].BinaryName
cmd := tr.target.ExecCommand(binary,
"query", "upgrade", "authority",
"--node", tr.getValidatorNode(ChainID("sover"), action.Proposer),
"-o", "json")
bz, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("failed running command '%s': %v", cmd, err)
}

var authority struct {
Address string `json:"address"`
}
err = json.Unmarshal(bz, &authority)
if err != nil {
log.Fatalf("Failed getting authority: err=%v, data=%s", err, string(bz))
}

// Upgrade Proposal Content
metadata := "ipfs://CID"
deposit := "10000000stake"
summary := "my summary"
proposalJson := fmt.Sprintf(`
{
"messages": [
{
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
"authority": "%s",
"plan": {
"name": "sovereign-changeover",
"height": "%d",
"info": "my upgrade info",
"upgraded_client_state": null
}
}
],
"metadata": "%s",
"title": "%s",
"summary": "%s",
"deposit": "%s",
"expedited": %t
}`, authority.Address, action.UpgradeHeight, metadata, action.UpgradeTitle, summary, deposit, action.Expedited)

//#nosec G204 -- bypass unsafe quoting warning (no production code)
proposalPath := "/temp-proposal.json"
bz, err = tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, proposalJson, proposalPath),
).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

// Submit Proposal
cmd = tr.target.ExecCommand(binary,
"tx", "gov", "submit-proposal", proposalPath,
"--gas", "900000",
"--from", "validator"+string(action.Proposer),
"--keyring-backend", "test",
"--chain-id", string(tr.testConfig.chainConfigs[ChainID("sover")].ChainId),
"--home", tr.getValidatorHome(ChainID("sover"), action.Proposer),
"--node", tr.getValidatorNode(ChainID("sover"), action.Proposer),
"-y")

if verbose {
fmt.Println("submitUpgradeProposal cmd:", cmd.String())
fmt.Println("Submit proposal:", cmd.String())
}

bz, err := cmd.CombinedOutput()
bz, err = cmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}
if verbose {
log.Println("Response to submit-proposal: ", string(bz))
}

tr.waitBlocks(action.ChainID, 1, 15*time.Second)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/json_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func UnmarshalMapToActionType(rawAction json.RawMessage, actionTypeString string
return a, nil
}
case "main.LegacyUpgradeProposalAction":
var a LegacyUpgradeProposalAction
var a UpgradeProposalAction
err := json.Unmarshal(rawAction, &a)
if err == nil {
return a, nil
Expand Down
38 changes: 21 additions & 17 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,36 +389,39 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
var noProposalRegex = regexp.MustCompile(`doesn't exist: key not found`)

binaryName := tr.chainConfigs[chain].BinaryName
bz, err := tr.target.ExecCommand(binaryName,
cmd := tr.target.ExecCommand(binaryName,
"query", "gov", "proposal",
fmt.Sprint(proposal),
`--node`, tr.GetQueryNode(chain),
`-o`, `json`,
).CombinedOutput()
`-o`, `json`)
bz, err := cmd.CombinedOutput()
if err != nil {
log.Println("Error getting governance proposal", proposal, "\n\t cmd: ", cmd, "\n\t err:", err, "\n\t out: ", string(bz))
}

prop := TextProposal{}

propRaw := string(bz)
if err != nil {
if noProposalRegex.Match(bz) {
return prop
}

log.Fatal(err, "\n", string(bz))
log.Fatal(err, "\n", propRaw)
}

// for legacy proposal types submitted using "tx submit-legacyproposal" (cosmos-sdk/v1/MsgExecLegacyContent)
propType := gjson.Get(string(bz), `proposal.messages.0.value.content.type`).String()
rawContent := gjson.Get(string(bz), `proposal.messages.0.value.content.value`)
propType := gjson.Get(propRaw, `proposal.messages.0.value.content.type`).String()
rawContent := gjson.Get(propRaw, `proposal.messages.0.value.content.value`)

// for current (>= v47) prop types submitted using "tx submit-proposal"
if propType == "" {
propType = gjson.Get(string(bz), `proposal.messages.0.type`).String()
rawContent = gjson.Get(string(bz), `proposal.messages.0.value`)
propType = gjson.Get(propRaw, `proposal.messages.0.type`).String()
rawContent = gjson.Get(propRaw, `proposal.messages.0.value`)
}

title := gjson.Get(string(bz), `proposal.title`).String()
deposit := gjson.Get(string(bz), `proposal.total_deposit.#(denom=="stake").amount`).Uint()
status := gjson.Get(string(bz), `proposal.status`).String()
title := gjson.Get(propRaw, `proposal.title`).String()
deposit := gjson.Get(propRaw, `proposal.total_deposit.#(denom=="stake").amount`).Uint()
status := gjson.Get(propRaw, `proposal.status`).String()

switch propType {
case "/cosmos.gov.v1beta1.TextProposal":
Expand Down Expand Up @@ -454,6 +457,7 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
},
}
case "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal":
case "cosmos-sdk/MsgSoftwareUpgrade":
height := rawContent.Get("plan.height").Uint()
title := rawContent.Get("plan.name").String()
return UpgradeProposal{
Expand Down Expand Up @@ -484,7 +488,7 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
case "/ibc.applications.transfer.v1.MsgUpdateParams":
var params IBCTransferParams
if err := json.Unmarshal([]byte(rawContent.Get("params").String()), &params); err != nil {
log.Fatal("cannot unmarshal ibc-transfer params: ", err, "\n", string(bz))
log.Fatal("cannot unmarshal ibc-transfer params: ", err, "\n", propRaw)
}

return IBCTransferParamsProposal{
Expand Down Expand Up @@ -514,13 +518,13 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
return ParamsProposal{
Deposit: uint(deposit),
Status: status,
Subspace: gjson.Get(string(bz), `messages.0.content.changes.0.subspace`).String(),
Key: gjson.Get(string(bz), `messages.0.content.changes.0.key`).String(),
Value: gjson.Get(string(bz), `messages.0.content.changes.0.value`).String(),
Subspace: gjson.Get(propRaw, `messages.0.content.changes.0.subspace`).String(),
Key: gjson.Get(propRaw, `messages.0.content.changes.0.key`).String(),
Value: gjson.Get(propRaw, `messages.0.content.changes.0.value`).String(),
}
}

log.Fatal("received unknown proposal type: ", propType, "proposal JSON:", string(bz))
log.Fatal("received unknown proposal type: ", propType, "proposal JSON:", propRaw)

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/steps_sovereign_changeover.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ func stepRunSovereignChain() []Step {
func stepsUpgradeChain() []Step {
return []Step{
{
Action: LegacyUpgradeProposalAction{
Action: UpgradeProposalAction{
ChainID: ChainID("sover"),
UpgradeTitle: "sovereign-changeover",
Proposer: ValidatorID("alice"),
UpgradeHeight: 110,
Expedited: false,
},
State: State{
ChainID("sover"): ChainState{
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func (td *DefaultDriver) runAction(action interface{}) error {
target.startChain(action, td.verbose)
case StartSovereignChainAction:
target.startSovereignChain(action, td.verbose)
case LegacyUpgradeProposalAction:
target.submitLegacyUpgradeProposal(action, td.verbose)
case UpgradeProposalAction:
target.submitUpgradeProposal(action, td.verbose)
case WaitUntilBlockAction:
target.waitUntilBlockOnChain(action)
case ChangeoverChainAction:
Expand Down
24 changes: 22 additions & 2 deletions tests/e2e/testnet-scripts/sovereign-genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,20 @@
"threshold": "0.500000000000000000",
"veto_threshold": "0.334000000000000000",
"min_initial_deposit_ratio": "0.000000000000000000",
"proposal_cancel_ratio": "0.500000000000000000",
"proposal_cancel_dest": "",
"expedited_voting_period": "10s",
"expedited_threshold": "0.667000000000000000",
"expedited_min_deposit": [
{
"denom": "stake",
"amount": "50000000"
}
],
"burn_vote_quorum": false,
"burn_proposal_deposit_prevote": false,
"burn_vote_veto": true
"burn_vote_veto": true,
"min_deposit_ratio": "0.010000000000000000"
}
},
"ibc": {
Expand Down Expand Up @@ -228,7 +239,16 @@
"send_sequences": [],
"recv_sequences": [],
"ack_sequences": [],
"next_channel_sequence": "0"
"next_channel_sequence": "0",
"params": {
"upgrade_timeout": {
"height": {
"revision_number": "0",
"revision_height": "0"
},
"timestamp": "600000000000"
}
}
}
},
"mint": {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/testnet-scripts/start-changeover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ QUERY_NODE_SUFFIX=$(echo "$VALIDATORS" | jq -r ".[0].ip_suffix")
echo "NODE SUFFIX: $QUERY_NODE_SUFFIX"
# poll for chain start
set +e
until $BIN query block query block --type=height 0 --node "tcp://$CHAIN_IP_PREFIX.$QUERY_NODE_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done
until $BIN query block --type=height 0 --node "tcp://$CHAIN_IP_PREFIX.$QUERY_NODE_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done
set -e

echo "done!!!!!!!!"
Expand Down

0 comments on commit 80d4ca9

Please sign in to comment.