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

chore: SDK 0.47 related cleanups #2334

Merged
merged 2 commits into from
Nov 21, 2023
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
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Highlights:

### Validators

**Upgrade Title** (for Cosmovisor): **v6.2**.

#### Price Feeder

Price Feeder `< umee/v2.3.0` is not compatible with Cosmos SDK v0.47. Validators must update to `umee/v2.3.0` or newer.
Expand Down
32 changes: 11 additions & 21 deletions x/incentive/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
"gotest.tools/v3/assert"

"github.com/umee-network/umee/v6/util/coin"
Expand Down Expand Up @@ -57,33 +58,22 @@ func TestMsgs(t *testing.T) {
}
}

// functions required in msgs.go which are not part of sdk.Msg
type sdkmsg interface {
Route() string
Type() string
GetSignBytes() []byte
}

func TestRoutes(t *testing.T) {
func TestLegacyMsg(t *testing.T) {
t.Parallel()

msgs := []sdkmsg{
*incentive.NewMsgBond(testAddr, uToken),
*incentive.NewMsgBeginUnbonding(testAddr, uToken),
*incentive.NewMsgEmergencyUnbond(testAddr, uToken),
*incentive.NewMsgClaim(testAddr),
*incentive.NewMsgSponsor(testAddr, 3),
*incentive.NewMsgGovCreatePrograms(govAddr, []incentive.IncentiveProgram{program}),
*incentive.NewMsgGovSetParams(govAddr, incentive.DefaultParams()),
msgs := []legacytx.LegacyMsg{
incentive.NewMsgBond(testAddr, uToken),
incentive.NewMsgBeginUnbonding(testAddr, uToken),
incentive.NewMsgEmergencyUnbond(testAddr, uToken),
incentive.NewMsgClaim(testAddr),
incentive.NewMsgSponsor(testAddr, 3),
incentive.NewMsgGovCreatePrograms(govAddr, []incentive.IncentiveProgram{program}),
incentive.NewMsgGovSetParams(govAddr, incentive.DefaultParams()),
}

for _, msg := range msgs {
// check for non-empty returns for now
assert.Assert(t, len(msg.GetSignBytes()) != 0)
// exact match required
assert.Equal(t,
// example: "/umee.incentive.v1.MsgBond"
// with %T returning "incentive.MsgBond"
addV1ToType(fmt.Sprintf("/umee.%T", msg)),
msg.Type(),
)
Expand All @@ -92,5 +82,5 @@ func TestRoutes(t *testing.T) {

// addV1ToType replaces "incentive." with "incentive.v1."
func addV1ToType(s string) string {
return strings.Replace(s, "incentive", "incentive.v1", 1)
return strings.Replace(s, "*incentive", "incentive.v1", 1)
}
139 changes: 62 additions & 77 deletions x/leverage/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ func NewMsgSupply(supplier sdk.AccAddress, asset sdk.Coin) *MsgSupply {
}
}

func (msg MsgSupply) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgSupply) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgSupply) ValidateBasic() error {
return validateSenderAndAsset(msg.Supplier, &msg.Asset)
}
Expand All @@ -26,10 +23,12 @@ func (msg *MsgSupply) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Supplier)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgSupply) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations

func (msg MsgSupply) Route() string { return "" }
func (msg MsgSupply) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgSupply) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgWithdraw(supplier sdk.AccAddress, asset sdk.Coin) *MsgWithdraw {
Expand All @@ -39,9 +38,6 @@ func NewMsgWithdraw(supplier sdk.AccAddress, asset sdk.Coin) *MsgWithdraw {
}
}

func (msg MsgWithdraw) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgWithdraw) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgWithdraw) ValidateBasic() error {
return validateSenderAndAsset(msg.Supplier, &msg.Asset)
}
Expand All @@ -50,10 +46,12 @@ func (msg *MsgWithdraw) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Supplier)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgWithdraw) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations

func (msg MsgWithdraw) Route() string { return "" }
func (msg MsgWithdraw) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgWithdraw) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgMaxWithdraw(supplier sdk.AccAddress, denom string) *MsgMaxWithdraw {
Expand All @@ -63,9 +61,6 @@ func NewMsgMaxWithdraw(supplier sdk.AccAddress, denom string) *MsgMaxWithdraw {
}
}

func (msg MsgMaxWithdraw) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgMaxWithdraw) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgMaxWithdraw) ValidateBasic() error {
return validateSenderAndDenom(msg.Supplier, msg.Denom)
}
Expand All @@ -74,10 +69,12 @@ func (msg *MsgMaxWithdraw) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Supplier)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgMaxWithdraw) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations

func (msg MsgMaxWithdraw) Route() string { return "" }
func (msg MsgMaxWithdraw) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgMaxWithdraw) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgCollateralize(borrower sdk.AccAddress, asset sdk.Coin) *MsgCollateralize {
Expand All @@ -87,9 +84,6 @@ func NewMsgCollateralize(borrower sdk.AccAddress, asset sdk.Coin) *MsgCollateral
}
}

func (msg MsgCollateralize) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgCollateralize) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgCollateralize) ValidateBasic() error {
return validateSenderAndAsset(msg.Borrower, &msg.Asset)
}
Expand All @@ -98,10 +92,12 @@ func (msg *MsgCollateralize) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Borrower)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgCollateralize) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations

func (msg MsgCollateralize) Route() string { return "" }
func (msg MsgCollateralize) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgCollateralize) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgSupplyCollateral(supplier sdk.AccAddress, asset sdk.Coin) *MsgSupplyCollateral {
Expand All @@ -111,9 +107,6 @@ func NewMsgSupplyCollateral(supplier sdk.AccAddress, asset sdk.Coin) *MsgSupplyC
}
}

func (msg MsgSupplyCollateral) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgSupplyCollateral) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgSupplyCollateral) ValidateBasic() error {
return validateSenderAndAsset(msg.Supplier, &msg.Asset)
}
Expand All @@ -122,10 +115,12 @@ func (msg *MsgSupplyCollateral) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Supplier)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgSupplyCollateral) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations

func (msg MsgSupplyCollateral) Route() string { return "" }
func (msg MsgSupplyCollateral) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgSupplyCollateral) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgDecollateralize(borrower sdk.AccAddress, asset sdk.Coin) *MsgDecollateralize {
Expand All @@ -135,9 +130,6 @@ func NewMsgDecollateralize(borrower sdk.AccAddress, asset sdk.Coin) *MsgDecollat
}
}

func (msg MsgDecollateralize) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgDecollateralize) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgDecollateralize) ValidateBasic() error {
return validateSenderAndAsset(msg.Borrower, &msg.Asset)
}
Expand All @@ -146,10 +138,11 @@ func (msg *MsgDecollateralize) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Borrower)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgDecollateralize) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations
func (msg MsgDecollateralize) Route() string { return "" }
func (msg MsgDecollateralize) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgDecollateralize) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgBorrow(borrower sdk.AccAddress, asset sdk.Coin) *MsgBorrow {
Expand All @@ -159,9 +152,6 @@ func NewMsgBorrow(borrower sdk.AccAddress, asset sdk.Coin) *MsgBorrow {
}
}

func (msg MsgBorrow) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgBorrow) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgBorrow) ValidateBasic() error {
return validateSenderAndAsset(msg.Borrower, &msg.Asset)
}
Expand All @@ -170,10 +160,11 @@ func (msg *MsgBorrow) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Borrower)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgBorrow) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations
func (msg MsgBorrow) Route() string { return "" }
func (msg MsgBorrow) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgBorrow) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgMaxBorrow(borrower sdk.AccAddress, denom string) *MsgMaxBorrow {
Expand All @@ -183,9 +174,6 @@ func NewMsgMaxBorrow(borrower sdk.AccAddress, denom string) *MsgMaxBorrow {
}
}

func (msg MsgMaxBorrow) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgMaxBorrow) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgMaxBorrow) ValidateBasic() error {
return validateSenderAndDenom(msg.Borrower, msg.Denom)
}
Expand All @@ -194,10 +182,11 @@ func (msg *MsgMaxBorrow) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Borrower)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgMaxBorrow) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations
func (msg MsgMaxBorrow) Route() string { return "" }
func (msg MsgMaxBorrow) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgMaxBorrow) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgRepay(borrower sdk.AccAddress, asset sdk.Coin) *MsgRepay {
Expand All @@ -207,9 +196,6 @@ func NewMsgRepay(borrower sdk.AccAddress, asset sdk.Coin) *MsgRepay {
}
}

func (msg MsgRepay) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgRepay) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgRepay) ValidateBasic() error {
return validateSenderAndAsset(msg.Borrower, &msg.Asset)
}
Expand All @@ -218,10 +204,11 @@ func (msg *MsgRepay) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Borrower)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgRepay) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations
func (msg MsgRepay) Route() string { return "" }
func (msg MsgRepay) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgRepay) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgLiquidate(liquidator, borrower sdk.AccAddress, repayment sdk.Coin, rewardDenom string) *MsgLiquidate {
Expand All @@ -233,9 +220,6 @@ func NewMsgLiquidate(liquidator, borrower sdk.AccAddress, repayment sdk.Coin, re
}
}

func (msg MsgLiquidate) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgLiquidate) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgLiquidate) ValidateBasic() error {
if err := validateSenderAndAsset(msg.Borrower, &msg.Repayment); err != nil {
return err
Expand All @@ -251,10 +235,11 @@ func (msg *MsgLiquidate) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Liquidator)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgLiquidate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations
func (msg MsgLiquidate) Route() string { return "" }
func (msg MsgLiquidate) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgLiquidate) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func NewMsgLeveragedLiquidate(
Expand All @@ -271,9 +256,6 @@ func NewMsgLeveragedLiquidate(
}
}

func (msg MsgLeveragedLiquidate) Route() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgLeveragedLiquidate) Type() string { return sdk.MsgTypeURL(&msg) }

func (msg *MsgLeveragedLiquidate) ValidateBasic() error {
if msg.RepayDenom != "" {
if err := sdk.ValidateDenom(msg.RepayDenom); err != nil {
Expand All @@ -300,12 +282,15 @@ func (msg *MsgLeveragedLiquidate) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Liquidator)
}

// GetSignBytes get the bytes for the message signer to sign on
func (msg *MsgLeveragedLiquidate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
// LegacyMsg.Type implementations
func (msg MsgLeveragedLiquidate) Route() string { return "" }
func (msg MsgLeveragedLiquidate) Type() string { return sdk.MsgTypeURL(&msg) }
func (msg MsgLeveragedLiquidate) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

// -- helper methods -- //

func validateSenderAndAsset(sender string, asset *sdk.Coin) error {
_, err := sdk.AccAddressFromBech32(sender)
if err != nil {
Expand Down
Loading