diff --git a/tests/e2e/action_rapid_test.go b/tests/e2e/action_rapid_test.go index 366f7f61c0..6a7bc7e9ea 100644 --- a/tests/e2e/action_rapid_test.go +++ b/tests/e2e/action_rapid_test.go @@ -269,15 +269,12 @@ func GetSubmitConsumerRemovalProposalActionGen() *rapid.Generator[SubmitConsumer }) } -func GetSubmitParamChangeProposalActionGen() *rapid.Generator[SubmitParamChangeLegacyProposalAction] { - return rapid.Custom(func(t *rapid.T) SubmitParamChangeLegacyProposalAction { - return SubmitParamChangeLegacyProposalAction{ - Chain: GetChainIDGen().Draw(t, "Chain"), - From: GetValidatorIDGen().Draw(t, "From"), - Deposit: rapid.Uint().Draw(t, "Deposit"), - Subspace: rapid.String().Draw(t, "Subspace"), - Key: rapid.String().Draw(t, "Key"), - Value: rapid.String().Draw(t, "Value"), // could make this more generic in the future, since Value takes interfaces +func GetSubmitParamChangeProposalActionGen() *rapid.Generator[SubmitLegacyTextProposalAction] { + return rapid.Custom(func(t *rapid.T) SubmitLegacyTextProposalAction { + return SubmitLegacyTextProposalAction{ + Chain: GetChainIDGen().Draw(t, "Chain"), + From: GetValidatorIDGen().Draw(t, "From"), + Deposit: rapid.Uint().Draw(t, "Deposit"), } }) } diff --git a/tests/e2e/actions.go b/tests/e2e/actions.go index 86b3470682..c000fb5f40 100644 --- a/tests/e2e/actions.go +++ b/tests/e2e/actions.go @@ -390,66 +390,24 @@ func (tr TestConfig) submitConsumerRemovalProposal( tr.waitBlocks(ChainID("provi"), 2, 20*time.Second) } -type SubmitParamChangeLegacyProposalAction struct { - Chain ChainID - From ValidatorID - Deposit uint - Subspace string - Key string - Value interface{} -} - -type paramChangeProposalJSON struct { - Title string `json:"title"` - Summary string `json:"summary"` - Description string `json:"description"` - Changes []paramChangeJSON `json:"changes"` - Deposit string `json:"deposit"` -} - -type paramChangeJSON struct { - Subspace string `json:"subspace"` - Key string `json:"key"` - Value interface{} `json:"value"` +type SubmitLegacyTextProposalAction struct { + Chain ChainID + From ValidatorID + Deposit uint } -func (tr TestConfig) submitParamChangeProposal( - action SubmitParamChangeLegacyProposalAction, +func (tr TestConfig) submitLegacyTextProposal( + action SubmitLegacyTextProposalAction, target ExecutionTarget, verbose bool, ) { - prop := paramChangeProposalJSON{ - Title: "Legacy Param change", - Summary: "Changing legacy module params", - Description: "Changing legacy module params", - Changes: []paramChangeJSON{{Subspace: action.Subspace, Key: action.Key, Value: action.Value}}, - Deposit: fmt.Sprint(action.Deposit) + `stake`, - } - - bz, err := json.Marshal(prop) - if err != nil { - log.Fatal(err) - } - - jsonStr := string(bz) - if strings.Contains(jsonStr, "'") { - log.Fatal("prop json contains single quote") - } - - //#nosec G204 -- bypass unsafe quoting warning (no production code) - bz, err = target.ExecCommand( - "/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/params-proposal.json"), - ).CombinedOutput() - - if err != nil { - log.Fatal(err, "\n", string(bz)) - } - cmd := target.ExecCommand( tr.chainConfigs[action.Chain].BinaryName, - - "tx", "gov", "submit-legacy-proposal", "param-change", "/params-proposal.json", - + "tx", "gov", "submit-legacy-proposal", + "--type", "Text", + "--title", "Test Proposal", + "--description", "testing", + "--deposit", fmt.Sprintf("%dstake", action.Deposit), `--from`, `validator`+fmt.Sprint(action.From), `--chain-id`, string(tr.chainConfigs[action.Chain].ChainId), `--home`, tr.getValidatorHome(action.Chain, action.From), @@ -459,13 +417,17 @@ func (tr TestConfig) submitParamChangeProposal( `-y`, ) - bz, err = cmd.CombinedOutput() + if verbose { + fmt.Println("submitLegacyTextProposal cmd:", cmd.String()) + } + + bz, err := cmd.CombinedOutput() if err != nil { log.Fatal(err, "\n", string(bz)) } // wait for inclusion in a block -> '--broadcast-mode block' is deprecated - tr.waitBlocks(action.Chain, 2, 60*time.Second) + tr.waitBlocks(action.Chain, 2, 10*time.Second) } type VoteGovProposalAction struct { @@ -1883,6 +1845,19 @@ func (tr TestConfig) registerRepresentative( target ExecutionTarget, verbose bool, ) { + fileTempl := `{ + "pubkey": %s, + "amount": "%s", + "moniker": "%s", + "identity": "", + "website": "", + "security": "", + "details": "", + "commission-rate": "0.1", + "commission-max-rate": "0.2", + "commission-max-change-rate": "0.01", + "min-self-delegation": "1" + }` var wg sync.WaitGroup for i, val := range action.Representatives { wg.Add(1) @@ -1900,22 +1875,46 @@ func (tr TestConfig) registerRepresentative( log.Fatal(err, "\n", string(bzPubKey)) } - bz, err := target.ExecCommand(tr.chainConfigs[action.Chain].BinaryName, + fileContent := fmt.Sprintf(fileTempl, string(bzPubKey), fmt.Sprint(stake)+"stake", fmt.Sprint(val)) + fileName := fmt.Sprintf("%s_democracy_representative.json", val) + file, err := os.CreateTemp("", fileName) + if err != nil { + panic(fmt.Sprintf("failed writing ccv consumer file : %v", err)) + } + defer file.Close() + err = os.WriteFile(file.Name(), []byte(fileContent), 0600) + if err != nil { + log.Fatalf("Failed writing consumer genesis to file: %v", err) + } + + containerInstance := tr.containerConfig.InstanceName + targetFile := fmt.Sprintf("/tmp/%s", fileName) + sourceFile := file.Name() + //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. + copyCmd := exec.Command("docker", "cp", sourceFile, + fmt.Sprintf("%s:%s", containerInstance, targetFile)) + writeResult, err := copyCmd.CombinedOutput() + if err != nil { + log.Fatal(err, "\n", string(writeResult)) + } + + cmd := target.ExecCommand(tr.chainConfigs[action.Chain].BinaryName, "tx", "staking", "create-validator", - `--amount`, fmt.Sprint(stake)+"stake", - `--pubkey`, string(bzPubKey), - `--moniker`, fmt.Sprint(val), - `--commission-rate`, "0.1", - `--commission-max-rate`, "0.2", - `--commission-max-change-rate`, "0.01", - `--min-self-delegation`, "1", + targetFile, `--from`, `validator`+fmt.Sprint(val), `--chain-id`, string(tr.chainConfigs[action.Chain].ChainId), `--home`, tr.getValidatorHome(action.Chain, val), `--node`, tr.getValidatorNode(action.Chain, val), `--keyring-backend`, `test`, `-y`, - ).CombinedOutput() + ) + + if verbose { + fmt.Println("register representative cmd:", cmd.String()) + fmt.Println("Tx json:", fileContent) + } + + bz, err := cmd.CombinedOutput() if err != nil { log.Fatal(err, "\n", string(bz)) } diff --git a/tests/e2e/json_utils.go b/tests/e2e/json_utils.go index aeb59eee3a..d852359b0a 100644 --- a/tests/e2e/json_utils.go +++ b/tests/e2e/json_utils.go @@ -95,8 +95,8 @@ func UnmarshalMapToActionType(rawAction json.RawMessage, actionTypeString string if err == nil { return a, nil } - case "main.SubmitParamChangeLegacyProposalAction": - var a SubmitParamChangeLegacyProposalAction + case "main.SubmitLegacyTextProposalAction": + var a SubmitLegacyTextProposalAction err := json.Unmarshal(rawAction, &a) if err == nil { return a, nil diff --git a/tests/e2e/state.go b/tests/e2e/state.go index e094ab81e3..c19711053f 100644 --- a/tests/e2e/state.go +++ b/tests/e2e/state.go @@ -331,17 +331,18 @@ func (tr TestConfig) getReward(chain ChainID, validator ValidatorID, blockHeight } //#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments. - bz, err := exec.Command("docker", "exec", tr.containerConfig.InstanceName, tr.chainConfigs[chain].BinaryName, - - "query", "distribution", "rewards", - delAddresss, - + cmd := exec.Command("docker", "exec", tr.containerConfig.InstanceName, tr.chainConfigs[chain].BinaryName, + "query", "distribution", "delegation-total-rewards", + "--delegator-address", delAddresss, `--height`, fmt.Sprint(blockHeight), `--node`, tr.getQueryNode(chain), `-o`, `json`, - ).CombinedOutput() + ) + + bz, err := cmd.CombinedOutput() + if err != nil { - log.Fatal(err, "\n", string(bz)) + log.Fatal("failed getting rewards: ", err, "\n", string(bz)) } denomCondition := `total.#(denom!="stake").amount` @@ -473,7 +474,7 @@ func (tr TestConfig) getProposal(chain ChainID, proposal uint) Proposal { StopTime: int(stopTime.Milliseconds()), } case "/cosmos.params.v1beta1.ParameterChangeProposal": - // deprecated for most modules + // deprecated for all modules, keeping for posterity return ParamsProposal{ Deposit: uint(deposit), Status: status, @@ -481,6 +482,16 @@ func (tr TestConfig) getProposal(chain ChainID, proposal uint) Proposal { Key: rawContent.Get("changes.0.key").String(), Value: rawContent.Get("changes.0.value").String(), } + case "cosmos-sdk/TextProposal": + title := rawContent.Get("title").String() + description := rawContent.Get("description").String() + + return TextProposal{ + Deposit: uint(deposit), + Status: status, + Title: title, + Description: description, + } } log.Fatal("unknown proposal type", string(bz)) @@ -590,7 +601,7 @@ func (tr TestConfig) getValStakedTokens(chain ChainID, validator ValidatorID) ui log.Fatal(err, "\n", string(bz)) } - amount := gjson.Get(string(bz), `tokens`) + amount := gjson.Get(string(bz), `validator.tokens`) return uint(amount.Uint()) } diff --git a/tests/e2e/steps_democracy.go b/tests/e2e/steps_democracy.go index 78f737e36e..f03b64d185 100644 --- a/tests/e2e/steps_democracy.go +++ b/tests/e2e/steps_democracy.go @@ -31,6 +31,12 @@ func stepsDemocracy(consumerName string) []Step { IsIncrementalReward: true, IsNativeDenom: true, }, + // Check that delegating on gov-consumer does not change validator powers + ValPowers: &map[ValidatorID]uint{ + ValidatorID("alice"): 511, + ValidatorID("bob"): 500, + ValidatorID("carol"): 500, + }, }, }, }, @@ -69,13 +75,10 @@ func stepsDemocracy(consumerName string) []Step { }, { // whitelisted legacy proposal can only handle ibctransfer.SendEnabled/ReceiveEnabled - Action: SubmitParamChangeLegacyProposalAction{ - Chain: ChainID(consumerName), - From: ValidatorID("alice"), - Deposit: 10000001, - Subspace: "transfer", - Key: "SendEnabled", - Value: true, + Action: SubmitLegacyTextProposalAction{ + Chain: ChainID(consumerName), + From: ValidatorID("alice"), + Deposit: 10000001, }, State: State{ ChainID(consumerName): ChainState{ @@ -83,15 +86,13 @@ func stepsDemocracy(consumerName string) []Step { ValidatorID("alice"): 9889999998, ValidatorID("bob"): 9960000001, }, - // Check that the "SendEnabled" transfer parameter is set to false - Params: &([]Param{{Subspace: "transfer", Key: "SendEnabled", Value: "false"}}), + // confirm the Proposals: &map[uint]Proposal{ - 1: ParamsProposal{ - Deposit: 10000001, - Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)), - Subspace: "transfer", - Key: "SendEnabled", - Value: "true", + 1: TextProposal{ + Deposit: 10000001, + Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)), + Title: "Test Proposal", + Description: "testing", }, }, }, @@ -114,16 +115,13 @@ func stepsDemocracy(consumerName string) []Step { }, // Check that the prop passed Proposals: &map[uint]Proposal{ - 1: ParamsProposal{ - Deposit: 10000001, - Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_PASSED)), - Subspace: "transfer", - Key: "SendEnabled", - Value: "true", + 1: TextProposal{ + Deposit: 10000001, + Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_PASSED)), + Title: "Test Proposal", + Description: "testing", }, }, - // Check that the parameter is changed on gov-consumer chain - Params: &([]Param{{Subspace: "transfer", Key: "SendEnabled", Value: "true"}}), }, }, }, diff --git a/tests/e2e/steps_reward_denom.go b/tests/e2e/steps_reward_denom.go index b05f62296b..ecf1cfe1fa 100644 --- a/tests/e2e/steps_reward_denom.go +++ b/tests/e2e/steps_reward_denom.go @@ -66,14 +66,11 @@ func stepsRewardDenomConsumer(consumerName string) []Step { }, }, { - // whitelisted legacy proposal can only handle ibctransfer.SendEnabled/ReceiveEnabled - Action: SubmitParamChangeLegacyProposalAction{ - Chain: ChainID(consumerName), - From: ValidatorID("alice"), - Deposit: 10000001, - Subspace: "transfer", - Key: "SendEnabled", - Value: true, + // whitelisted legacy proposal can only be Text + Action: SubmitLegacyTextProposalAction{ + Chain: ChainID(consumerName), + From: ValidatorID("alice"), + Deposit: 10000001, }, State: State{ ChainID(consumerName): ChainState{ @@ -81,15 +78,12 @@ func stepsRewardDenomConsumer(consumerName string) []Step { ValidatorID("alice"): 9889999998, ValidatorID("bob"): 9960000001, }, - // Check that the "SendEnabled" transfer parameter is set to false - Params: &([]Param{{Subspace: "transfer", Key: "SendEnabled", Value: "false"}}), Proposals: &map[uint]Proposal{ - 1: ParamsProposal{ - Deposit: 10000001, - Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)), - Subspace: "transfer", - Key: "SendEnabled", - Value: "true", + 1: TextProposal{ + Deposit: 10000001, + Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)), + Title: "Test Proposal", + Description: "testing", }, }, }, @@ -112,16 +106,13 @@ func stepsRewardDenomConsumer(consumerName string) []Step { }, // Check that the prop passed Proposals: &map[uint]Proposal{ - 1: ParamsProposal{ - Deposit: 10000001, - Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_PASSED)), - Subspace: "transfer", - Key: "SendEnabled", - Value: "true", + 1: TextProposal{ + Deposit: 10000001, + Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_PASSED)), + Title: "Test Proposal", + Description: "testing", }, }, - // Check that the parameter is changed on gov-consumer chain - Params: &([]Param{{Subspace: "transfer", Key: "SendEnabled", Value: "true"}}), }, }, }, diff --git a/tests/e2e/test_driver.go b/tests/e2e/test_driver.go index 052559b3ba..509c7fff1f 100644 --- a/tests/e2e/test_driver.go +++ b/tests/e2e/test_driver.go @@ -80,8 +80,8 @@ func (td *DefaultDriver) runAction(action interface{}) error { td.testCfg.submitConsumerAdditionProposal(action, td.target, td.verbose) case SubmitConsumerRemovalProposalAction: td.testCfg.submitConsumerRemovalProposal(action, td.target, td.verbose) - case SubmitParamChangeLegacyProposalAction: - td.testCfg.submitParamChangeProposal(action, td.target, td.verbose) + case SubmitLegacyTextProposalAction: + td.testCfg.submitLegacyTextProposal(action, td.target, td.verbose) case VoteGovProposalAction: td.testCfg.voteGovProposal(action, td.target, td.verbose) case StartConsumerChainAction: