diff --git a/e2e/helpers/gov.go b/e2e/helpers/gov.go index 8ac4466..1a4c70a 100644 --- a/e2e/helpers/gov.go +++ b/e2e/helpers/gov.go @@ -6,6 +6,7 @@ import ( "strconv" "testing" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" @@ -13,10 +14,9 @@ import ( "github.com/stretchr/testify/require" ) -func ValidatorVote(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, proposalID string, voteOp string, searchHeightDelta int64) { - if err := chain.VoteOnProposalAllValidators(ctx, proposalID, voteOp); err != nil { - t.Fatal(err) - } +func ValidatorVoteV1(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, proposalID string, voteOp string, searchHeightDelta int64) { + err := chain.VoteOnProposalAllValidators(ctx, proposalID, voteOp) + require.NoError(t, err, "failed to vote on proposal", proposalID, "with all validators") height, err := chain.Height(ctx) require.NoError(t, err, "failed to get height") @@ -24,14 +24,36 @@ func ValidatorVote(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, propID, err := strconv.ParseUint(proposalID, 10, 64) require.NoError(t, err, "failed to parse proposalID") - resp, _ := cosmos.PollForProposalStatus(ctx, chain, height, (height-2)+searchHeightDelta, propID, govv1beta1.StatusPassed) - t.Log("PollForProposalStatusV1beta1 resp", resp) + // try this, if NPE then try the other\ + resp, err := cosmos.PollForProposalStatusV1(ctx, chain, height, height+searchHeightDelta, propID, govv1.ProposalStatus_PROPOSAL_STATUS_PASSED) + require.NoError(t, err, "failed to poll for proposal status", err) + require.NotNil(t, resp, "ValidatorVote proposal not found:", fmt.Sprintf("proposalID: %s", proposalID)) + t.Log("PollForProposalStatusV1 resp", resp) require.EqualValues(t, govv1beta1.StatusPassed, resp.Status, "proposal status did not change to passed in expected number of blocks") } -func SubmitParamChangeProp(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, updatedParams []cosmos.ProtoMessage, sender string, waitForBlocks int64) string { +func ValidatorVoteV1Beta1(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, proposalID string, voteOp string, searchHeightDelta int64) { + err := chain.VoteOnProposalAllValidators(ctx, proposalID, voteOp) + require.NoError(t, err, "failed to vote on proposal", proposalID, "with all validators") + + height, err := chain.Height(ctx) + require.NoError(t, err, "failed to get height") + + propID, err := strconv.ParseUint(proposalID, 10, 64) + require.NoError(t, err, "failed to parse proposalID") + + resp, err := cosmos.PollForProposalStatus(ctx, chain, height, height+searchHeightDelta, propID, govv1beta1.StatusPassed) + require.NoError(t, err, "failed to poll for proposal status", err) + + require.NotNil(t, resp, "ValidatorVote proposal not found:", fmt.Sprintf("proposalID: %s", proposalID)) + t.Log("PollForProposalStatusV1 resp", resp) + + require.EqualValues(t, govv1beta1.StatusPassed, resp.Status, "proposal status did not change to passed in expected number of blocks") +} + +func SubmitParamChangeProp(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, updatedParams []cosmos.ProtoMessage, sender string) string { expedited := false proposal, err := chain.BuildProposal(updatedParams, "UpdateParams", "params", "ipfs://CID", fmt.Sprintf(`50%s`, chain.Config().Denom), sender, expedited) require.NoError(t, err, "error building proposal") @@ -40,7 +62,5 @@ func SubmitParamChangeProp(t *testing.T, ctx context.Context, chain *cosmos.Cosm t.Log("txProp", txProp) require.NoError(t, err, "error submitting proposal") - ValidatorVote(t, ctx, chain, txProp.ProposalID, cosmos.ProposalVoteYes, waitForBlocks) - return txProp.ProposalID } diff --git a/e2e/poa_gov_test.go b/e2e/poa_gov_test.go index 4e6c72d..150f3b7 100644 --- a/e2e/poa_gov_test.go +++ b/e2e/poa_gov_test.go @@ -15,7 +15,10 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -var GovModuleAddress = "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" +var ( + GovModuleAddress = "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" + RandAcc = "cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrql8a" +) func TestPOAGovernance(t *testing.T) { if testing.Short() { @@ -35,9 +38,6 @@ func TestPOAGovernance(t *testing.T) { t.Fatal(err) } - users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, chain) - incorrectUser := users[0] - // get validator operator addresses validators := helpers.GetValidatorsOperatingAddresses(t, ctx, chain) require.Equal(t, len(validators), numVals) @@ -46,16 +46,32 @@ func TestPOAGovernance(t *testing.T) { // === Test Cases === testGovernance(t, ctx, chain, acc0, validators) - testUpdatePOAParams(t, ctx, chain, acc0, incorrectUser) + testUpdatePOAParams(t, ctx, chain, acc0) } func testGovernance(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, acc0 ibc.Wallet, validators []string) { t.Log("\n===== TEST GOVERNANCE =====") + t.Run("success: gov proposal update params", func(t *testing.T) { + require.Equal(t, len(helpers.GetPOAParams(t, ctx, chain).Admins), 2) + + updatedParams := []cosmos.ProtoMessage{ + &poa.MsgUpdateParams{ + Sender: GovModuleAddress, + Params: poa.Params{ + Admins: []string{acc0.FormattedAddress(), GovModuleAddress, RandAcc}, + }, + }, + } + propId := helpers.SubmitParamChangeProp(t, ctx, chain, acc0, updatedParams, GovModuleAddress) + helpers.ValidatorVoteV1(t, ctx, chain, propId, cosmos.ProposalVoteYes, 25) + require.Equal(t, len(helpers.GetPOAParams(t, ctx, chain).Admins), 3) + }) + t.Run("success: gov proposal validator change", func(t *testing.T) { // ibc.ChainConfig key: app_state.poa.params.admins must contain the governance address. propID := helpers.SubmitGovernanceProposalForValidatorChanges(t, ctx, chain, acc0, validators[0], 1_234_567, true, GovModuleAddress) - helpers.ValidatorVote(t, ctx, chain, propID, cosmos.ProposalVoteYes, 25) + helpers.ValidatorVoteV1(t, ctx, chain, propID, cosmos.ProposalVoteYes, 25) // validate the validator[0] was set to 1_234_567 val := helpers.GetValidators(t, ctx, chain).Validators[0] @@ -63,14 +79,16 @@ func testGovernance(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain p := helpers.GetPOAConsensusPower(t, ctx, chain, val.OperatorAddress) require.EqualValues(t, 1_234_567/1_000_000, p) }) - } -func testUpdatePOAParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, acc0, incorrectUser ibc.Wallet) { +func testUpdatePOAParams(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, acc0 ibc.Wallet) { t.Log("\n===== TEST UPDATE POA PARAMS =====") var tx helpers.TxResponse var err error + users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, chain) + incorrectUser := users[0] + t.Run("fail: update-params message from a non authorized user", func(t *testing.T) { tx, err = helpers.POAUpdateParams(t, ctx, chain, incorrectUser, []string{incorrectUser.FormattedAddress()}, true) if err != nil { @@ -140,21 +158,4 @@ func testUpdatePOAParams(t *testing.T, ctx context.Context, chain *cosmos.Cosmos } }) - t.Run("success: gov proposal update params", func(t *testing.T) { - randAcc := "cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrql8a" - - require.Equal(t, len(helpers.GetPOAParams(t, ctx, chain).Admins), 4) - - updatedParams := []cosmos.ProtoMessage{ - &poa.MsgUpdateParams{ - Sender: GovModuleAddress, - Params: poa.Params{ - Admins: []string{acc0.FormattedAddress(), GovModuleAddress, randAcc}, - }, - }, - } - helpers.SubmitParamChangeProp(t, ctx, chain, acc0, updatedParams, GovModuleAddress, 25) - require.Equal(t, len(helpers.GetPOAParams(t, ctx, chain).Admins), 3) - }) - }