Skip to content

Commit

Permalink
fixing cwica test
Browse files Browse the repository at this point in the history
  • Loading branch information
spoo-bar committed Mar 4, 2024
1 parent 3852b47 commit 00bf839
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions proto/archway/cwica/v1/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions x/cwica/keeper/ibc_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 2 additions & 4 deletions x/cwica/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions x/cwica/types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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() })
}

}

Check failure on line 114 in x/cwica/types/tx_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
}

Expand Down

0 comments on commit 00bf839

Please sign in to comment.