chore: Remove legacy code (#17720)

This commit is contained in:
Marko 2023-09-13 16:51:34 +02:00 committed by GitHub
parent 2f4e1094d4
commit 93aa126659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 241 deletions

View File

@ -1,62 +0,0 @@
package types
import (
"strings"
errorsmod "cosmossdk.io/errors"
)
// GetTitle returns the title of a community pool spend proposal.
func (csp *CommunityPoolSpendProposal) GetTitle() string { return csp.Title }
// GetDescription returns the description of a community pool spend proposal.
func (csp *CommunityPoolSpendProposal) GetDescription() string { return csp.Description }
// GetDescription returns the routing key of a community pool spend proposal.
func (csp *CommunityPoolSpendProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of a community pool spend proposal.
func (csp *CommunityPoolSpendProposal) ProposalType() string { return "CommunityPoolSpend" }
// ValidateBasic runs basic stateless validity checks
func (csp *CommunityPoolSpendProposal) ValidateBasic() error {
err := validateAbstract(csp)
if err != nil {
return err
}
if !csp.Amount.IsValid() {
return ErrInvalidProposalAmount
}
if csp.Recipient == "" {
return ErrEmptyProposalRecipient
}
return nil
}
// validateAbstract is semantically duplicated from x/gov/types/v1beta1/proposal.go to avoid a cyclic dependency
// between these two modules (x/distribution and x/gov).
// See: https://github.com/cosmos/cosmos-sdk/blob/4a6a1e3cb8de459891cb0495052589673d14ef51/x/gov/types/v1beta1/proposal.go#L196-L214
func validateAbstract(c *CommunityPoolSpendProposal) error {
const (
MaxTitleLength = 140
MaxDescriptionLength = 10000
)
title := c.GetTitle()
if len(strings.TrimSpace(title)) == 0 {
return errorsmod.Wrap(ErrInvalidProposalContent, "proposal title cannot be blank")
}
if len(title) > MaxTitleLength {
return errorsmod.Wrapf(ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength)
}
description := c.GetDescription()
if len(description) == 0 {
return errorsmod.Wrap(ErrInvalidProposalContent, "proposal description cannot be blank")
}
if len(description) > MaxDescriptionLength {
return errorsmod.Wrapf(ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength)
}
return nil
}

View File

@ -1,74 +0,0 @@
package types
import (
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
const (
ProposalTypeSoftwareUpgrade string = "SoftwareUpgrade"
ProposalTypeCancelSoftwareUpgrade string = "CancelSoftwareUpgrade"
)
// NewSoftwareUpgradeProposal creates a new SoftwareUpgradeProposal instance.
// Deprecated: this proposal is considered legacy and is deprecated in favor of
// Msg-based gov proposals. See MsgSoftwareUpgrade.
func NewSoftwareUpgradeProposal(title, description string, plan Plan) gov.Content {
return &SoftwareUpgradeProposal{title, description, plan}
}
// Implements Proposal Interface
var _ gov.Content = &SoftwareUpgradeProposal{}
func init() {
gov.RegisterProposalType(ProposalTypeSoftwareUpgrade)
gov.RegisterProposalType(ProposalTypeCancelSoftwareUpgrade)
}
// GetTitle gets the proposal's title
func (sup *SoftwareUpgradeProposal) GetTitle() string { return sup.Title }
// GetDescription gets the proposal's description
func (sup *SoftwareUpgradeProposal) GetDescription() string { return sup.Description }
// ProposalRoute gets the proposal's router key
func (sup *SoftwareUpgradeProposal) ProposalRoute() string { return RouterKey }
// ProposalType is "SoftwareUpgrade"
func (sup *SoftwareUpgradeProposal) ProposalType() string { return ProposalTypeSoftwareUpgrade }
// ValidateBasic validates the proposal
func (sup *SoftwareUpgradeProposal) ValidateBasic() error {
if err := sup.Plan.ValidateBasic(); err != nil {
return err
}
return gov.ValidateAbstract(sup)
}
// NewCancelSoftwareUpgradeProposal creates a new CancelSoftwareUpgradeProposal
// instance. Deprecated: this proposal is considered legacy and is deprecated in
// favor of Msg-based gov proposals. See MsgCancelUpgrade.
func NewCancelSoftwareUpgradeProposal(title, description string) gov.Content {
return &CancelSoftwareUpgradeProposal{title, description}
}
// Implements Proposal Interface
var _ gov.Content = &CancelSoftwareUpgradeProposal{}
// GetTitle gets the proposal's title
func (csup *CancelSoftwareUpgradeProposal) GetTitle() string { return csup.Title }
// GetDescription gets the proposal's description
func (csup *CancelSoftwareUpgradeProposal) GetDescription() string { return csup.Description }
// ProposalRoute gets the proposal's router key
func (csup *CancelSoftwareUpgradeProposal) ProposalRoute() string { return RouterKey }
// ProposalType is "CancelSoftwareUpgrade"
func (csup *CancelSoftwareUpgradeProposal) ProposalType() string {
return ProposalTypeCancelSoftwareUpgrade
}
// ValidateBasic validates the proposal
func (csup *CancelSoftwareUpgradeProposal) ValidateBasic() error {
return gov.ValidateAbstract(csup)
}

View File

@ -1,105 +0,0 @@
package types_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
type ProposalWrapper struct {
Prop gov.Content
}
func TestContentAccessors(t *testing.T) {
cases := map[string]struct {
p gov.Content
title string
desc string
typ string
str string
}{
"upgrade": {
p: types.NewSoftwareUpgradeProposal("Title", "desc", types.Plan{
Name: "due_height",
Info: "https://foo.bar",
Height: 99999999999,
}),
title: "Title",
desc: "desc",
typ: "SoftwareUpgrade",
str: "title:\"Title\" description:\"desc\" plan:<name:\"due_height\" time:<seconds:-62135596800 > height:99999999999 info:\"https://foo.bar\" > ",
},
"cancel": {
p: types.NewCancelSoftwareUpgradeProposal("Cancel", "bad idea"),
title: "Cancel",
desc: "bad idea",
typ: "CancelSoftwareUpgrade",
str: "title:\"Cancel\" description:\"bad idea\" ",
},
}
cdc := codec.NewLegacyAmino()
gov.RegisterLegacyAminoCodec(cdc)
types.RegisterLegacyAminoCodec(cdc)
for name, tc := range cases {
tc := tc // copy to local variable for scopelint
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.title, tc.p.GetTitle())
assert.Equal(t, tc.desc, tc.p.GetDescription())
assert.Equal(t, tc.typ, tc.p.ProposalType())
assert.Equal(t, "upgrade", tc.p.ProposalRoute())
assert.Equal(t, tc.str, tc.p.String())
// try to encode and decode type to ensure codec works
wrap := ProposalWrapper{tc.p}
bz, err := cdc.Marshal(&wrap)
require.NoError(t, err)
unwrap := ProposalWrapper{}
err = cdc.Unmarshal(bz, &unwrap)
require.NoError(t, err)
// all methods should look the same
assert.Equal(t, tc.title, unwrap.Prop.GetTitle())
assert.Equal(t, tc.desc, unwrap.Prop.GetDescription())
assert.Equal(t, tc.typ, unwrap.Prop.ProposalType())
assert.Equal(t, "upgrade", unwrap.Prop.ProposalRoute())
assert.Equal(t, tc.str, unwrap.Prop.String())
})
}
}
// tests a software update proposal can be marshaled and unmarshaled
func TestMarshalSoftwareUpdateProposal(t *testing.T) {
// create proposal
plan := types.Plan{
Name: "upgrade",
Height: 1000,
}
content := types.NewSoftwareUpgradeProposal("title", "description", plan)
sup, ok := content.(*types.SoftwareUpgradeProposal)
require.True(t, ok)
// create codec
ir := codectypes.NewInterfaceRegistry()
types.RegisterInterfaces(ir)
gov.RegisterInterfaces(ir)
cdc := codec.NewProtoCodec(ir)
// marshal message
bz, err := cdc.MarshalJSON(sup)
require.NoError(t, err)
// unmarshal proposal
newSup := &types.SoftwareUpgradeProposal{}
err = cdc.UnmarshalJSON(bz, newSup)
require.NoError(t, err)
}