From c9e189c6b5f0274459ed1c1d21814d7b218b336e Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Mon, 24 Jan 2022 18:07:30 +0100 Subject: [PATCH] Add metadat to v1beta2.NewProposal --- x/auth/middleware/tips_test.go | 2 +- x/gov/keeper/proposal.go | 4 ++-- x/gov/keeper/proposal_test.go | 2 +- x/gov/simulation/operations_test.go | 6 +++--- x/gov/types/v1beta2/proposal.go | 3 ++- x/gov/types/v1beta2/proposals_test.go | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/x/auth/middleware/tips_test.go b/x/auth/middleware/tips_test.go index 7169fbf76f09..2bd6a97276cf 100644 --- a/x/auth/middleware/tips_test.go +++ b/x/auth/middleware/tips_test.go @@ -33,7 +33,7 @@ func (s *MWTestSuite) setupAcctsForTips(ctx sdk.Context) (sdk.Context, []testAcc s.Require().NoError(err) // Create dummy proposal for tipper to vote on. - prop, err := govtypes.NewProposal([]sdk.Msg{banktypes.NewMsgSend(accts[0].acc.GetAddress(), accts[0].acc.GetAddress(), initialRegens)}, 1, time.Now(), time.Now().Add(time.Hour)) + prop, err := govtypes.NewProposal([]sdk.Msg{banktypes.NewMsgSend(accts[0].acc.GetAddress(), accts[0].acc.GetAddress(), initialRegens)}, 1, nil, time.Now(), time.Now().Add(time.Hour)) s.Require().NoError(err) s.app.GovKeeper.SetProposal(ctx, prop) s.app.GovKeeper.ActivateVotingPeriod(ctx, prop) diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 131c858b145f..4c630736c559 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -13,7 +13,7 @@ import ( // SubmitProposal create new proposal given an array of messages func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadata []byte) (v1beta2.Proposal, error) { if metadata != nil && len(metadata) > int(keeper.maxMetadataLen) { - return v1beta2.Proposal{Metadata: metadata}, types.ErrMetadataTooLong.Wrapf("got metadata with length %d", len(metadata)) + return v1beta2.Proposal{}, types.ErrMetadataTooLong.Wrapf("got metadata with length %d", len(metadata)) } // Will hold a comma-separated string of all Msg type URLs. @@ -67,7 +67,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat submitTime := ctx.BlockHeader().Time depositPeriod := keeper.GetDepositParams(ctx).MaxDepositPeriod - proposal, err := v1beta2.NewProposal(messages, proposalID, submitTime, submitTime.Add(*depositPeriod)) + proposal, err := v1beta2.NewProposal(messages, proposalID, metadata, submitTime, submitTime.Add(*depositPeriod)) if err != nil { return v1beta2.Proposal{}, err } diff --git a/x/gov/keeper/proposal_test.go b/x/gov/keeper/proposal_test.go index 66d3d6722c8f..dde5829f8469 100644 --- a/x/gov/keeper/proposal_test.go +++ b/x/gov/keeper/proposal_test.go @@ -95,7 +95,7 @@ func (suite *KeeperTestSuite) TestGetProposalsFiltered() { for _, s := range status { for i := 0; i < 50; i++ { - p, err := v1beta2.NewProposal(TestProposal, proposalID, time.Now(), time.Now()) + p, err := v1beta2.NewProposal(TestProposal, proposalID, nil, time.Now(), time.Now()) suite.Require().NoError(err) p.Status = s diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 5e39e23c8790..26ef7b04bcc9 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -147,7 +147,7 @@ func TestSimulateMsgDeposit(t *testing.T) { submitTime := ctx.BlockHeader().Time depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod - proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod)) + proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, nil, submitTime, submitTime.Add(*depositPeriod)) require.NoError(t, err) app.GovKeeper.SetProposal(ctx, proposal) @@ -191,7 +191,7 @@ func TestSimulateMsgVote(t *testing.T) { submitTime := ctx.BlockHeader().Time depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod - proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod)) + proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, nil, submitTime, submitTime.Add(*depositPeriod)) require.NoError(t, err) app.GovKeeper.ActivateVotingPeriod(ctx, proposal) @@ -234,7 +234,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { submitTime := ctx.BlockHeader().Time depositPeriod := app.GovKeeper.GetDepositParams(ctx).MaxDepositPeriod - proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, submitTime, submitTime.Add(*depositPeriod)) + proposal, err := v1beta2.NewProposal([]sdk.Msg{contentMsg}, 1, nil, submitTime, submitTime.Add(*depositPeriod)) require.NoError(t, err) app.GovKeeper.ActivateVotingPeriod(ctx, proposal) diff --git a/x/gov/types/v1beta2/proposal.go b/x/gov/types/v1beta2/proposal.go index 22c2cb84c1fd..ebe6076d675c 100644 --- a/x/gov/types/v1beta2/proposal.go +++ b/x/gov/types/v1beta2/proposal.go @@ -23,7 +23,7 @@ const ( ) // NewProposal creates a new Proposal instance -func NewProposal(messages []sdk.Msg, id uint64, submitTime, depositEndTime time.Time) (Proposal, error) { +func NewProposal(messages []sdk.Msg, id uint64, metadata []byte, submitTime, depositEndTime time.Time) (Proposal, error) { msgs, err := sdktx.SetMsgs(messages) if err != nil { @@ -35,6 +35,7 @@ func NewProposal(messages []sdk.Msg, id uint64, submitTime, depositEndTime time. p := Proposal{ ProposalId: id, Messages: msgs, + Metadata: metadata, Status: StatusDepositPeriod, FinalTallyResult: &tally, SubmitTime: &submitTime, diff --git a/x/gov/types/v1beta2/proposals_test.go b/x/gov/types/v1beta2/proposals_test.go index a49a3e14958e..7525ba5361f6 100644 --- a/x/gov/types/v1beta2/proposals_test.go +++ b/x/gov/types/v1beta2/proposals_test.go @@ -37,7 +37,7 @@ func TestNestedAnys(t *testing.T) { testProposal := v1beta1.NewTextProposal("Proposal", "testing proposal") msgContent, err := v1beta2.NewLegacyContent(testProposal, "cosmos1govacct") require.NoError(t, err) - proposal, err := v1beta2.NewProposal([]sdk.Msg{msgContent}, 1, time.Now(), time.Now()) + proposal, err := v1beta2.NewProposal([]sdk.Msg{msgContent}, 1, nil, time.Now(), time.Now()) require.NoError(t, err) require.Equal(t, "TODO Fix panic here", proposal.String())