Skip to content
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

Fix decoding of gov props with a ParameterChangeProposal in them. #2198

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/unreleased/bug-fixes/2198-fix-gov-props.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Register the params types with the codecs so old gov props can be read [PR 2198](https://github.com/provenance-io/provenance/pull/2198).
5 changes: 5 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramprops "github.com/cosmos/cosmos-sdk/x/params/types/proposal" //nolint:depguard // Need this here to register old types.
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -786,6 +787,10 @@ func New(
app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)

// We removed the params module, but have several gov props with a ParameterChangeProposal in them.
paramprops.RegisterLegacyAminoCodec(legacyAmino)
paramprops.RegisterInterfaces(interfaceRegistry)

// NOTE: upgrade module is required to be prioritized
app.mm.SetOrderPreBlockers(
upgradetypes.ModuleName,
Expand Down
86 changes: 86 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"sort"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -16,13 +17,16 @@ import (

dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdktypes "github.com/cosmos/cosmos-sdk/codec/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
paramprops "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/gogoproto/proto"

"github.com/provenance-io/provenance/internal/pioconfig"
Expand Down Expand Up @@ -440,3 +444,85 @@ func TestMsgServerProtoAnnotations(t *testing.T) {
err = msgservice.ValidateProtoAnnotations(protoFiles)
assertions.AssertErrorValue(t, err, expErr, "ValidateProtoAnnotations")
}

func TestParamChangeInGovProp(t *testing.T) {
paramChangeProp := &paramprops.ParameterChangeProposal{
Title: "Test Prop Change",
Description: "A proposal for testing decoding",
Changes: []paramprops.ParamChange{
{
Subspace: "mymodule",
Key: "favorite_flower",
Value: "fuchsia",
},
},
}
paramChangePropAny, err := codectypes.NewAnyWithValue(paramChangeProp)
require.NoError(t, err, "codectypes.NewAnyWithValue(paramChangeProp)")
t.Logf("paramChangePropAny.TypeUrl = %q", paramChangePropAny.TypeUrl)

execLeg := &govtypesv1.MsgExecLegacyContent{
Content: paramChangePropAny,
Authority: "jerry",
}

execLegAny, err := codectypes.NewAnyWithValue(execLeg)
require.NoError(t, err, "codectypes.NewAnyWithValue(execLeg)")

submitTime := time.Unix(1618935600, 0)
depositEndTime := submitTime.Add(1 * time.Minute)
votingStartTime := depositEndTime.Add(3500 * time.Millisecond)
votingEndTime := votingStartTime.Add(48 * time.Hour)

prop := govtypesv1.Proposal{
Id: 123,
Messages: []*codectypes.Any{execLegAny},
Status: govtypesv1.StatusPassed,
FinalTallyResult: &govtypesv1.TallyResult{YesCount: "5", AbstainCount: "1", NoCount: "0", NoWithVetoCount: "0"},
SubmitTime: &submitTime,
DepositEndTime: &depositEndTime,
TotalDeposit: []sdk.Coin{sdk.NewInt64Coin("pink", 1000)},
VotingStartTime: &votingStartTime,
VotingEndTime: &votingEndTime,
Metadata: "Prop metadata",
Title: "The prop title",
Summary: "The prop summary",
Proposer: sdk.AccAddress("proposer____________").String(),
}

expJSON := `{"id":"123",` +
`"messages":[{"@type":"/cosmos.gov.v1.MsgExecLegacyContent",` +
`"content":{"@type":"/cosmos.params.v1beta1.ParameterChangeProposal",` +
`"title":"Test Prop Change",` +
`"description":"A proposal for testing decoding",` +
`"changes":[{"subspace":"mymodule","key":"favorite_flower","value":"fuchsia"}]},` +
`"authority":"jerry"}],` +
`"status":"PROPOSAL_STATUS_PASSED",` +
`"final_tally_result":{"yes_count":"5","abstain_count":"1","no_count":"0","no_with_veto_count":"0"},` +
`"submit_time":"2021-04-20T16:20:00Z",` +
`"deposit_end_time":"2021-04-20T16:21:00Z",` +
`"total_deposit":[{"denom":"pink","amount":"1000"}],` +
`"voting_start_time":"2021-04-20T16:21:03.500Z",` +
`"voting_end_time":"2021-04-22T16:21:03.500Z",` +
`"metadata":"Prop metadata",` +
`"title":"The prop title",` +
`"summary":"The prop summary",` +
`"proposer":"cosmos1wpex7ur0wdjhyh6lta047h6lta047h6ljkx24t",` +
`"expedited":false,` +
`"failed_reason":""}`

propBz, err := prop.Marshal()
require.NoError(t, err, "prop.Marshal()")

encCfg := MakeTestEncodingConfig(t)

var actProp govtypesv1.Proposal
err = encCfg.Marshaler.Unmarshal(propBz, &actProp)
require.NoError(t, err, "encCfg.Marshaler.Unmarshal(propBz, &actProp)")

propJSONBz, err := encCfg.Marshaler.MarshalJSON(&actProp)
require.NoError(t, err, "encCfg.Marshaler.MarshalJSON(&actProp)")
propJSON := string(propJSONBz)
t.Logf("prop JSON:\n%s", propJSON)
assert.Equal(t, expJSON, propJSON, "proposal JSON")
}
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
Loading