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

code hygiene: add missing nil check and corresponding tests for query handlers #3462

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra space makes it consistent with the rest of message handlers in this file. :)

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