Skip to content

Commit

Permalink
fix tests in 03-connection
Browse files Browse the repository at this point in the history
  • Loading branch information
likesToEatFish committed Dec 11, 2024
1 parent fe835d5 commit 3123326
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 139 deletions.
92 changes: 61 additions & 31 deletions modules/core/03-connection/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ package keeper_test
import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

errorsmod "cosmossdk.io/errors"

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

clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper"
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"

host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)
Expand All @@ -21,21 +28,21 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connectionID",
func() {
req = &types.QueryConnectionRequest{}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -44,7 +51,10 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
ConnectionId: ibctesting.InvalidID,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrConnectionNotFound, "IDisInvalid").Error(),
),
},
{
"success",
Expand All @@ -62,7 +72,7 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
ConnectionId: path.EndpointA.ConnectionID,
}
},
true,
nil,
},
}

Expand All @@ -78,12 +88,13 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.Connection(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(&expConnection, res.Connection)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -104,21 +115,21 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"empty pagination",
func() {
req = &types.QueryConnectionsRequest{}
},
true,
nil,
},
{
"success",
Expand Down Expand Up @@ -155,7 +166,7 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
},
}
},
true,
nil,
},
}

Expand All @@ -171,12 +182,13 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.Connections(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expConnections, res.Connections)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -191,21 +203,21 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connectionID",
func() {
req = &types.QueryClientConnectionsRequest{}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -214,7 +226,10 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
ClientId: ibctesting.InvalidID,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, "IDisInvalid").Error(),
),
},
{
"success",
Expand All @@ -236,7 +251,7 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
ClientId: path1.EndpointA.ClientID,
}
},
true,
nil,
},
}

Expand All @@ -252,12 +267,13 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.ClientConnections(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expPaths, res.ConnectionPaths)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -272,14 +288,14 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connection ID",
Expand All @@ -288,7 +304,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
ConnectionId: "",
}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -297,7 +313,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
ConnectionId: "test-connection-id",
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrConnectionNotFound, "connection-id: test-connection-id").Error(),
),
},
{
"client state not found",
Expand All @@ -311,7 +330,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
req = &types.QueryConnectionClientStateRequest{
ConnectionId: path.EndpointA.ConnectionID,
}
}, false,
}, status.Error(
codes.NotFound,
errorsmod.Wrap(clienttypes.ErrClientNotFound, "client-id: ").Error(),
),
},
{
"success",
Expand All @@ -326,7 +348,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
ConnectionId: path.EndpointA.ConnectionID,
}
},
true,
nil,
},
}

Expand All @@ -342,7 +364,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.ConnectionClientState(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(&expIdentifiedClientState, res.IdentifiedClientState)
Expand All @@ -352,6 +374,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -367,14 +390,14 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connection ID",
Expand All @@ -385,7 +408,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionHeight: 1,
}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -396,7 +419,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionHeight: 1,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrConnectionNotFound, "connection-id: test-connection-id").Error(),
),
},
{
"consensus state not found",
Expand All @@ -409,7 +435,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionNumber: 0,
RevisionHeight: uint64(suite.chainA.GetContext().BlockHeight()), // use current height
}
}, false,
}, status.Error(
codes.NotFound,
errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "client-id: 07-tendermint-0").Error(),
),
},
{
"success",
Expand All @@ -429,7 +458,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionHeight: clientHeight.GetRevisionHeight(),
}
},
true,
nil,
},
}

Expand All @@ -445,7 +474,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.ConnectionConsensusState(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
consensusState, err := clienttypes.UnpackConsensusState(res.ConsensusState)
Expand All @@ -458,6 +487,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand Down
Loading

0 comments on commit 3123326

Please sign in to comment.