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

Remove GetSigners from sdk.Msg implementations #5305

Merged
merged 15 commits into from
Dec 6, 2023
Merged
30 changes: 0 additions & 30 deletions modules/apps/27-interchain-accounts/controller/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ func (msg MsgRegisterInterchainAccount) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgRegisterInterchainAccount) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Owner)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}

// NewMsgSendTx creates a new instance of MsgSendTx
func NewMsgSendTx(owner, connectionID string, relativeTimeoutTimestamp uint64, packetData icatypes.InterchainAccountPacketData) *MsgSendTx {
return &MsgSendTx{
Expand Down Expand Up @@ -95,16 +85,6 @@ func (msg MsgSendTx) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgSendTx) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Owner)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}

// NewMsgUpdateParams creates a new MsgUpdateParams instance
func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams {
return &MsgUpdateParams{
Expand All @@ -122,13 +102,3 @@ func (msg MsgUpdateParams) ValidateBasic() error {

return nil
}

// GetSigners implements sdk.Msg
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}
52 changes: 32 additions & 20 deletions modules/apps/27-interchain-accounts/controller/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"
testifysuite "github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
Expand All @@ -17,6 +18,12 @@ import (
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

type TypesTestSuite struct {
ThanhNhann marked this conversation as resolved.
Show resolved Hide resolved
testifysuite.Suite

chainA *ibctesting.TestChain
}

func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
var msg *types.MsgRegisterInterchainAccount

Expand Down Expand Up @@ -93,12 +100,14 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
}
}

func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestMsgRegisterInterchainAccountGetSigners() {
ThanhNhann marked this conversation as resolved.
Show resolved Hide resolved
expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress)
require.NoError(t, err)
suite.Require().NoError(err)

msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "")
require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners())
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg)
suite.Require().NoError(err)
suite.Require().Equal(expSigner.Bytes(), signers[0])
}

func TestMsgSendTxValidateBasic(t *testing.T) {
Expand Down Expand Up @@ -188,9 +197,9 @@ func TestMsgSendTxValidateBasic(t *testing.T) {
}
}

func TestMsgSendTxGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestMsgSendTxGetSigners() {
expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress)
require.NoError(t, err)
suite.Require().NoError(err)

msgBankSend := &banktypes.MsgSend{
FromAddress: ibctesting.TestAccAddress,
Expand All @@ -201,7 +210,7 @@ func TestMsgSendTxGetSigners(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{})

data, err := icatypes.SerializeCosmosTx(encodingConfig.Codec, []proto.Message{msgBankSend}, icatypes.EncodingProtobuf)
require.NoError(t, err)
suite.Require().NoError(err)

packetData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Expand All @@ -214,7 +223,9 @@ func TestMsgSendTxGetSigners(t *testing.T) {
100000,
packetData,
)
require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners())
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg)
suite.Require().NoError(err)
suite.Require().Equal(expSigner.Bytes(), signers[0])
}

// TestMsgUpdateParamsValidateBasic tests ValidateBasic for MsgUpdateParams
Expand Down Expand Up @@ -242,7 +253,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) {
}

// TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams
func TestMsgUpdateParamsGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners(t *testing.T) {
testCases := []struct {
name string
address sdk.AccAddress
Expand All @@ -254,17 +265,18 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {

for _, tc := range testCases {
tc := tc

msg := types.MsgUpdateParams{
Signer: tc.address.String(),
Params: types.DefaultParams(),
}
if tc.expPass {
require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners())
} else {
require.Panics(t, func() {
msg.GetSigners()
})
}
suite.Run(tc.name, func() {
msg := types.MsgUpdateParams{
Signer: tc.address.String(),
Params: types.DefaultParams(),
}
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(tc.address.Bytes(), signers[0])
} else {
suite.Require().Error(err)
}
})
}
}
10 changes: 0 additions & 10 deletions modules/apps/27-interchain-accounts/host/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,3 @@ func (msg MsgUpdateParams) ValidateBasic() error {

return msg.Params.Validate()
}

// GetSigners implements sdk.Msg
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}
28 changes: 18 additions & 10 deletions modules/apps/27-interchain-accounts/host/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import (
"testing"

"github.com/stretchr/testify/require"
testifysuite "github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

type TypesTestSuite struct {
testifysuite.Suite

chainA *ibctesting.TestChain
}

func TestMsgUpdateParamsValidateBasic(t *testing.T) {
testCases := []struct {
name string
Expand Down Expand Up @@ -48,7 +55,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) {
}
}

func TestMsgUpdateParamsGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() {
testCases := []struct {
name string
address sdk.AccAddress
Expand All @@ -60,14 +67,15 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {

for _, tc := range testCases {
tc := tc

msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams())
if tc.expPass {
require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners())
} else {
require.Panics(t, func() {
msg.GetSigners()
})
}
suite.Run(tc.name, func() {
msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams())
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(tc.address.Bytes(), signers[0])
} else {
suite.Require().Error(err)
}
})
}
}
39 changes: 0 additions & 39 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ func (msg MsgRegisterPayee) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgRegisterPayee) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Relayer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{signer}
}

// NewMsgRegisterCounterpartyPayee creates a new instance of MsgRegisterCounterpartyPayee
func NewMsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) *MsgRegisterCounterpartyPayee {
return &MsgRegisterCounterpartyPayee{
Expand Down Expand Up @@ -109,16 +99,6 @@ func (msg MsgRegisterCounterpartyPayee) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgRegisterCounterpartyPayee) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Relayer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{signer}
}

// NewMsgPayPacketFee creates a new instance of MsgPayPacketFee
func NewMsgPayPacketFee(fee Fee, sourcePortID, sourceChannelID, signer string, relayers []string) *MsgPayPacketFee {
return &MsgPayPacketFee{
Expand Down Expand Up @@ -155,15 +135,6 @@ func (msg MsgPayPacketFee) ValidateBasic() error {
return msg.Fee.Validate()
}

// GetSigners implements sdk.Msg
func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}

// NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee
func NewMsgPayPacketFeeAsync(packetID channeltypes.PacketId, packetFee PacketFee) *MsgPayPacketFeeAsync {
return &MsgPayPacketFeeAsync{
Expand All @@ -180,13 +151,3 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error {

return msg.PacketFee.Validate()
}

// GetSigners implements sdk.Msg
// The signer of the fee message must be the refund address
func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.PacketFee.RefundAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}
33 changes: 23 additions & 10 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
testifysuite "github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -14,6 +15,12 @@ import (
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

type TypesTestSuite struct {
testifysuite.Suite

chainA *ibctesting.TestChain
}

func TestMsgRegisterPayeeValidation(t *testing.T) {
var msg *types.MsgRegisterPayee

Expand Down Expand Up @@ -85,10 +92,12 @@ func TestMsgRegisterPayeeValidation(t *testing.T) {
}
}

func TestRegisterPayeeGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestRegisterPayeeGetSigners() {
accAddress := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
msg := types.NewMsgRegisterPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress)
require.Equal(t, []sdk.AccAddress{accAddress}, msg.GetSigners())
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg)
suite.Require().NoError(err)
suite.Require().Equal(accAddress.Bytes(), signers[0])
}

func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) {
Expand Down Expand Up @@ -165,10 +174,12 @@ func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) {
}
}

func TestRegisterCountepartyAddressGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestRegisterCountepartyAddressGetSigners() {
accAddress := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
msg := types.NewMsgRegisterCounterpartyPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress)
require.Equal(t, []sdk.AccAddress{accAddress}, msg.GetSigners())
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg)
suite.Require().NoError(err)
suite.Require().Equal(accAddress.Bytes(), signers[0])
}

func TestMsgPayPacketFeeValidation(t *testing.T) {
Expand Down Expand Up @@ -239,12 +250,13 @@ func TestMsgPayPacketFeeValidation(t *testing.T) {
}
}

func TestPayPacketFeeGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestPayPacketFeeGetSigners() {
refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
msg := types.NewMsgPayPacketFee(fee, ibctesting.MockFeePort, ibctesting.FirstChannelID, refundAddr.String(), nil)

require.Equal(t, []sdk.AccAddress{refundAddr}, msg.GetSigners())
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg)
suite.Require().NoError(err)
suite.Require().Equal(refundAddr.Bytes(), signers[0])
}

func TestMsgPayPacketFeeAsyncValidation(t *testing.T) {
Expand Down Expand Up @@ -373,13 +385,14 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) {
}
}

func TestPayPacketFeeAsyncGetSigners(t *testing.T) {
func (suite *TypesTestSuite) TestPayPacketFeeAsyncGetSigners() {
refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
packetID := channeltypes.NewPacketID(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1)
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
packetFee := types.NewPacketFee(fee, refundAddr.String(), nil)

msg := types.NewMsgPayPacketFeeAsync(packetID, packetFee)

require.Equal(t, []sdk.AccAddress{refundAddr}, msg.GetSigners())
signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg)
suite.Require().NoError(err)
suite.Require().Equal(refundAddr.Bytes(), signers[0])
}
Loading
Loading