Skip to content

Commit

Permalink
Add metadat to v1beta2.NewProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Jan 24, 2022
1 parent 5364942 commit c9e189c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion x/auth/middleware/tips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions x/gov/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion x/gov/types/v1beta2/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x/gov/types/v1beta2/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit c9e189c

Please sign in to comment.