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: remove GetSignBytes from 29-fee and transfer msgs #4570

Merged
merged 9 commits into from
Sep 7, 2023
47 changes: 4 additions & 43 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@ import (
errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
legacytx "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
)

// msg types
const (
TypeMsgPayPacketFee = "payPacketFee"
TypeMsgPayPacketFeeAsync = "payPacketFeeAsync"
)

var (
_ sdk.Msg = (*MsgRegisterPayee)(nil)
_ sdk.Msg = (*MsgRegisterCounterpartyPayee)(nil)
_ sdk.Msg = (*MsgPayPacketFee)(nil)
_ sdk.Msg = (*MsgPayPacketFeeAsync)(nil)
_ legacytx.LegacyMsg = (*MsgPayPacketFee)(nil)
_ legacytx.LegacyMsg = (*MsgPayPacketFeeAsync)(nil)
_ sdk.Msg = (*MsgRegisterPayee)(nil)
_ sdk.Msg = (*MsgRegisterCounterpartyPayee)(nil)
_ sdk.Msg = (*MsgPayPacketFee)(nil)
_ sdk.Msg = (*MsgPayPacketFeeAsync)(nil)
)

// NewMsgRegisterPayee creates a new instance of MsgRegisterPayee
Expand Down Expand Up @@ -162,21 +153,6 @@ func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{signer}
}

// Type implements legacytx.LegacyMsg
func (MsgPayPacketFee) Type() string {
return TypeMsgPayPacketFee
}

// Route implements legacytx.LegacyMsg
func (MsgPayPacketFee) Route() string {
return RouterKey
}

// GetSignBytes implements legacytx.LegacyMsg
func (msg MsgPayPacketFee) GetSignBytes() []byte {
return sdk.MustSortJSON(amino.MustMarshalJSON(&msg))
}

// NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee
func NewMsgPayPacketFeeAsync(packetID channeltypes.PacketId, packetFee PacketFee) *MsgPayPacketFeeAsync {
return &MsgPayPacketFeeAsync{
Expand All @@ -203,18 +179,3 @@ func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress {
}
return []sdk.AccAddress{signer}
}

// Type implements legacytx.LegacyMsg
func (MsgPayPacketFeeAsync) Type() string {
return TypeMsgPayPacketFeeAsync
}

// Route implements legacytx.LegacyMsg
func (MsgPayPacketFeeAsync) Route() string {
return RouterKey
}

// GetSignBytes implements legacytx.LegacyMsg
func (msg MsgPayPacketFeeAsync) GetSignBytes() []byte {
return sdk.MustSortJSON(amino.MustMarshalJSON(&msg))
}
31 changes: 0 additions & 31 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,6 @@ func TestPayPacketFeeGetSigners(t *testing.T) {
require.Equal(t, []sdk.AccAddress{refundAddr}, msg.GetSigners())
}

func TestMsgPayPacketFeeRoute(t *testing.T) {
var msg types.MsgPayPacketFee
require.Equal(t, types.RouterKey, msg.Route())
}

func TestMsgPayPacketFeeGetSignBytes(t *testing.T) {
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
msg := types.NewMsgPayPacketFee(fee, ibctesting.MockFeePort, ibctesting.FirstChannelID, defaultAccAddress, nil)

require.NotPanics(t, func() {
_ = msg.GetSignBytes()
})
}

func TestMsgPayPacketFeeAsyncValidation(t *testing.T) {
var msg *types.MsgPayPacketFeeAsync

Expand Down Expand Up @@ -382,20 +368,3 @@ func TestPayPacketFeeAsyncGetSigners(t *testing.T) {

require.Equal(t, []sdk.AccAddress{refundAddr}, msg.GetSigners())
}

func TestMsgPayPacketFeeAsyncRoute(t *testing.T) {
var msg types.MsgPayPacketFeeAsync
require.Equal(t, types.RouterKey, msg.Route())
}

func TestMsgPayPacketFeeAsyncGetSignBytes(t *testing.T) {
packetID := channeltypes.NewPacketID(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1)
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
packetFee := types.NewPacketFee(fee, defaultAccAddress, nil)

msg := types.NewMsgPayPacketFeeAsync(packetID, packetFee)

require.NotPanics(t, func() {
_ = msg.GetSignBytes()
})
}
26 changes: 2 additions & 24 deletions modules/apps/transfer/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@ import (
errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
legacytx "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
)

// msg types
const (
TypeMsgTransfer = "transfer"
)

var (
_ sdk.Msg = (*MsgUpdateParams)(nil)
_ sdk.Msg = (*MsgTransfer)(nil)
_ legacytx.LegacyMsg = (*MsgTransfer)(nil)
_ sdk.Msg = (*MsgUpdateParams)(nil)
_ sdk.Msg = (*MsgTransfer)(nil)
)

// NewMsgUpdateParams creates a new MsgUpdateParams instance
Expand Down Expand Up @@ -71,16 +64,6 @@ func NewMsgTransfer(
}
}

// Type implements legacytx.LegacyMsg
func (MsgTransfer) Type() string {
return TypeMsgTransfer
}

// Route implements legacytx.LegacyMsg
func (MsgTransfer) Route() string {
return RouterKey
}
damiannolan marked this conversation as resolved.
Show resolved Hide resolved

// ValidateBasic performs a basic check of the MsgTransfer fields.
// NOTE: timeout height or timestamp values can be 0 to disable the timeout.
// NOTE: The recipient addresses format is not validated as the format defined by
Expand Down Expand Up @@ -109,11 +92,6 @@ func (msg MsgTransfer) ValidateBasic() error {
return ValidateIBCDenom(msg.Token.Denom)
}

// GetSignBytes implements legacytx.LegacyMsg
func (msg MsgTransfer) GetSignBytes() []byte {
return sdk.MustSortJSON(amino.MustMarshalJSON(&msg))
}

// GetSigners implements sdk.Msg
func (msg MsgTransfer) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Sender)
Expand Down
17 changes: 0 additions & 17 deletions modules/apps/transfer/types/msgs_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -46,22 +45,6 @@ var (
timeoutHeight = clienttypes.NewHeight(0, 10)
)

// TestMsgTransferRoute tests Route for MsgTransfer
func TestMsgTransferRoute(t *testing.T) {
msg := types.NewMsgTransfer(validPort, validChannel, coin, sender, receiver, timeoutHeight, 0, "")

require.Equal(t, types.RouterKey, msg.Route())
}

func TestMsgTransferGetSignBytes(t *testing.T) {
msg := types.NewMsgTransfer(validPort, validChannel, coin, sender, receiver, timeoutHeight, 0, "")
expected := fmt.Sprintf(`{"type":"cosmos-sdk/MsgTransfer","value":{"receiver":"%s","sender":"%s","source_channel":"testchannel","source_port":"testportid","timeout_height":{"revision_height":"10"},"token":{"amount":"100","denom":"atom"}}}`, receiver, sender)
require.NotPanics(t, func() {
res := msg.GetSignBytes()
require.Equal(t, expected, string(res))
})
}

// TestMsgTransferValidation tests ValidateBasic for MsgTransfer
func TestMsgTransferValidation(t *testing.T) {
testCases := []struct {
Expand Down
Loading