fix: make submit-legacy-proposal --type field not case-sensitive (#11967)
This commit is contained in:
parent
ac9754f367
commit
542e9f07cd
@ -180,7 +180,11 @@ $ %s tx gov submit-legacy-proposal --title="Test Proposal" --description="My awe
|
||||
return err
|
||||
}
|
||||
|
||||
content := v1beta1.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)
|
||||
content, ok := v1beta1.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to create proposal content: unknown proposal type %s", proposal.Type)
|
||||
}
|
||||
|
||||
msg, err := v1beta1.NewMsgSubmitProposal(content, amount, clientCtx.GetFromAddress())
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid message: %w", err)
|
||||
|
||||
@ -27,7 +27,8 @@ func TestDecodeStore(t *testing.T) {
|
||||
dec := simulation.NewDecodeStore(cdc)
|
||||
|
||||
endTime := time.Now().UTC()
|
||||
content := v1beta1.ContentFromProposalType("test", "test", v1beta1.ProposalTypeText)
|
||||
content, ok := v1beta1.ContentFromProposalType("test", "test", v1beta1.ProposalTypeText)
|
||||
require.True(t, ok)
|
||||
proposalA, err := v1beta1.NewProposal(content, 1, endTime, endTime.Add(24*time.Hour))
|
||||
require.NoError(t, err)
|
||||
proposalB, err := v1beta1.NewProposal(content, 2, endTime, endTime.Add(24*time.Hour))
|
||||
|
||||
@ -43,8 +43,11 @@ func TestMsgSubmitProposal(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, tc := range tests {
|
||||
content, ok := ContentFromProposalType(tc.title, tc.description, tc.proposalType)
|
||||
require.True(t, ok)
|
||||
|
||||
msg, err := NewMsgSubmitProposal(
|
||||
ContentFromProposalType(tc.title, tc.description, tc.proposalType),
|
||||
content,
|
||||
tc.initialDeposit,
|
||||
tc.proposerAddr,
|
||||
)
|
||||
|
||||
@ -246,14 +246,12 @@ func RegisterProposalType(ty string) {
|
||||
}
|
||||
|
||||
// ContentFromProposalType returns a Content object based on the proposal type.
|
||||
func ContentFromProposalType(title, desc, ty string) Content {
|
||||
switch ty {
|
||||
case ProposalTypeText:
|
||||
return NewTextProposal(title, desc)
|
||||
|
||||
default:
|
||||
return nil
|
||||
func ContentFromProposalType(title, desc, ty string) (Content, bool) {
|
||||
if strings.EqualFold(ty, ProposalTypeText) {
|
||||
return NewTextProposal(title, desc), true
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// IsValidProposalType returns a boolean determining if the proposal type is
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
package v1beta1
|
||||
package v1beta1_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestProposalStatus_Format(t *testing.T) {
|
||||
statusDepositPeriod, _ := ProposalStatusFromString("PROPOSAL_STATUS_DEPOSIT_PERIOD")
|
||||
statusDepositPeriod, _ := v1beta1.ProposalStatusFromString("PROPOSAL_STATUS_DEPOSIT_PERIOD")
|
||||
tests := []struct {
|
||||
pt ProposalStatus
|
||||
pt v1beta1.ProposalStatus
|
||||
sprintFArgs string
|
||||
expectedStringOutput string
|
||||
}{
|
||||
@ -22,3 +23,36 @@ func TestProposalStatus_Format(t *testing.T) {
|
||||
require.Equal(t, tt.expectedStringOutput, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentFromProposalType(t *testing.T) {
|
||||
tests := []struct {
|
||||
proposalType string
|
||||
expectedType string
|
||||
}{
|
||||
{
|
||||
proposalType: "TextProposal",
|
||||
expectedType: "",
|
||||
},
|
||||
{
|
||||
proposalType: "text",
|
||||
expectedType: v1beta1.ProposalTypeText,
|
||||
},
|
||||
{
|
||||
proposalType: "Text",
|
||||
expectedType: v1beta1.ProposalTypeText,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
content, ok := v1beta1.ContentFromProposalType("title", "foo", test.proposalType)
|
||||
if test.expectedType == "" {
|
||||
require.False(t, ok)
|
||||
continue
|
||||
}
|
||||
|
||||
require.True(t, ok)
|
||||
require.NotNil(t, content)
|
||||
require.Equal(t, test.expectedType, content.ProposalType())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user