From 00bf839234085d94a937fd0fe4ce69f2b4c56756 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:10:10 +0000 Subject: [PATCH] fixing cwica test --- proto/archway/cwica/v1/errors.proto | 4 ++-- x/cwica/keeper/ibc_handlers_test.go | 14 ++++++++++++-- x/cwica/types/tx.go | 6 ++---- x/cwica/types/tx_test.go | 14 +++++++++++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/proto/archway/cwica/v1/errors.proto b/proto/archway/cwica/v1/errors.proto index 5033bf82..07123358 100644 --- a/proto/archway/cwica/v1/errors.proto +++ b/proto/archway/cwica/v1/errors.proto @@ -13,8 +13,8 @@ message SudoError { ModuleErrors error_code = 2; // payload is any input which caused the error string input_payload = 3; - // error_msg is the error message - string error_msg = 4; + // error_message is the error message + string error_message = 4; } // ModuleErrors defines the module level error codes diff --git a/x/cwica/keeper/ibc_handlers_test.go b/x/cwica/keeper/ibc_handlers_test.go index 5725de1c..5d3e21c5 100644 --- a/x/cwica/keeper/ibc_handlers_test.go +++ b/x/cwica/keeper/ibc_handlers_test.go @@ -111,12 +111,22 @@ func (s *KeeperTestSuite) TestHandleChanOpenAck() { err := cwicaKeeper.HandleChanOpenAck(ctx, "", channelID, counterpartyChannelID, "1") s.Require().ErrorContains(err, "failed to parse contract address: : invalid address") + icaMetadata := icatypes.Metadata{ + Version: "ics27-1", + ControllerConnectionId: "connection-0", + HostConnectionId: "connection-0", + Encoding: icatypes.EncodingProtobuf, + TxType: icatypes.TxTypeSDKMultiMsg, + } + icaMetadataBytes, err := icatypes.ModuleCdc.MarshalJSON(&icaMetadata) + s.Require().NoError(err) + // TEST CASE 2: success contract SudoResponse - err = cwicaKeeper.HandleChanOpenAck(ctx, portID, channelID, counterpartyChannelID, "1") + err = cwicaKeeper.HandleChanOpenAck(ctx, portID, channelID, counterpartyChannelID, string(icaMetadataBytes)) s.Require().NoError(err) // TEST CASE 3: contract callback fails - should not return error - because error is swallowed wmKeeper.SetReturnSudoError(errors.New("SudoOnChanOpenAck error")) - err = cwicaKeeper.HandleChanOpenAck(ctx, portID, channelID, counterpartyChannelID, "1") + err = cwicaKeeper.HandleChanOpenAck(ctx, portID, channelID, counterpartyChannelID, string(icaMetadataBytes)) s.Require().NoError(err) } diff --git a/x/cwica/types/tx.go b/x/cwica/types/tx.go index 3334f275..77cfd216 100644 --- a/x/cwica/types/tx.go +++ b/x/cwica/types/tx.go @@ -27,8 +27,7 @@ func (msg *MsgRegisterInterchainAccount) ValidateBasic() error { } func (msg *MsgRegisterInterchainAccount) GetSigners() []sdk.AccAddress { - fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress) - return []sdk.AccAddress{fromAddress} + return []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.FromAddress)} } func (msg *MsgRegisterInterchainAccount) Route() string { @@ -66,8 +65,7 @@ func (msg *MsgSendTx) ValidateBasic() error { } func (msg *MsgSendTx) GetSigners() []sdk.AccAddress { - fromAddress, _ := sdk.AccAddressFromBech32(msg.FromAddress) - return []sdk.AccAddress{fromAddress} + return []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.FromAddress)} } func (msg *MsgSendTx) Route() string { diff --git a/x/cwica/types/tx_test.go b/x/cwica/types/tx_test.go index 8f0f00a7..5194e721 100644 --- a/x/cwica/types/tx_test.go +++ b/x/cwica/types/tx_test.go @@ -78,15 +78,17 @@ func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { tests := []struct { name string malleate func() sdktypes.Msg + isValid bool }{ { - "valid_signer", + "invalid_signer", func() sdktypes.Msg { return &types.MsgRegisterInterchainAccount{ FromAddress: "👻", ConnectionId: "connection-id", } }, + false, }, { "valid_signer", @@ -96,13 +98,19 @@ func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { ConnectionId: "connection-id", } }, + true, }, } for _, tt := range tests { msg := tt.malleate() - addr, _ := sdktypes.AccAddressFromBech32(TestAddress) - require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + if tt.isValid { + addr, _ := sdktypes.AccAddressFromBech32(TestAddress) + require.Equal(t, msg.GetSigners(), []sdktypes.AccAddress{addr}) + } else { + require.Panics(t, func() { msg.GetSigners() }) + } + } }