Skip to content

Commit

Permalink
code hygiene: add missing nil check and corresponding tests for que…
Browse files Browse the repository at this point in the history
…ry handlers (#3462)

* add missing nil check in gprc handlers

* remove unnecessary check
  • Loading branch information
crodriguezvega authored Apr 17, 2023
1 parent c043dbd commit 06d71ba
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 4 deletions.
4 changes: 4 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (k Keeper) IncentivizedPacketsForChannel(goCtx context.Context, req *types.

// TotalRecvFees implements the Query/TotalRecvFees gRPC method
func (k Keeper) TotalRecvFees(goCtx context.Context, req *types.QueryTotalRecvFeesRequest) (*types.QueryTotalRecvFeesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

feesInEscrow, found := k.GetFeesInEscrow(ctx, req.PacketId)
Expand Down
84 changes: 80 additions & 4 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() {
},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"empty pagination",
func() {
Expand Down Expand Up @@ -93,6 +100,13 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"fees not found for packet id",
func() {
Expand Down Expand Up @@ -179,6 +193,13 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketsForChannel() {
},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"no packets for specified channel",
func() {
Expand Down Expand Up @@ -246,6 +267,13 @@ func (suite *KeeperTestSuite) TestQueryTotalRecvFees() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"packet not found",
func() {
Expand Down Expand Up @@ -305,6 +333,13 @@ func (suite *KeeperTestSuite) TestQueryTotalAckFees() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"packet not found",
func() {
Expand Down Expand Up @@ -364,6 +399,13 @@ func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"packet not found",
func() {
Expand Down Expand Up @@ -423,6 +465,13 @@ func (suite *KeeperTestSuite) TestQueryPayee() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"payee address not found: invalid channel",
func() {
Expand Down Expand Up @@ -486,6 +535,13 @@ func (suite *KeeperTestSuite) TestQueryCounterpartyPayee() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"counterparty address not found: invalid channel",
func() {
Expand Down Expand Up @@ -552,6 +608,13 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannels() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
},
false,
},
{
"success: empty pagination",
func() {
Expand Down Expand Up @@ -644,7 +707,10 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannels() {
}

func (suite *KeeperTestSuite) TestQueryFeeEnabledChannel() {
var req *types.QueryFeeEnabledChannelRequest
var (
req *types.QueryFeeEnabledChannelRequest
expEnabled bool
)

testCases := []struct {
name string
Expand All @@ -656,19 +722,29 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannel() {
func() {},
true,
},
{
"empty request",
func() {
req = nil
expEnabled = false
},
false,
},
{
"fee not enabled on channel",
func() {
req.ChannelId = "invalid-channel-id"
req.PortId = "invalid-port-id"
expEnabled = false
},
false,
true,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest() // reset
expEnabled = true

suite.coordinator.Setup(suite.path)

Expand All @@ -684,9 +760,9 @@ func (suite *KeeperTestSuite) TestQueryFeeEnabledChannel() {

if tc.expPass {
suite.Require().NoError(err)
suite.Require().True(res.FeeEnabled)
suite.Require().Equal(expEnabled, res.FeeEnabled)
} else {
suite.Require().False(res.FeeEnabled)
suite.Require().Error(err)
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (k Keeper) ConnectionOpenTry(goCtx context.Context, msg *connectiontypes.Ms
// ConnectionOpenAck defines a rpc handler method for MsgConnectionOpenAck.
func (k Keeper) ConnectionOpenAck(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenAck) (*connectiontypes.MsgConnectionOpenAckResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

targetClient, err := clienttypes.UnpackClientState(msg.ClientState)
if err != nil {
return nil, err
Expand Down Expand Up @@ -340,6 +341,7 @@ func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgC
// ChannelCloseInit defines a rpc handler method for MsgChannelCloseInit.
func (k Keeper) ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgChannelCloseInit) (*channeltypes.MsgChannelCloseInitResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// Lookup module by channel capability
module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId)
if err != nil {
Expand Down

0 comments on commit 06d71ba

Please sign in to comment.