Skip to content

Commit

Permalink
Merge branch 'main' into gjermund/spend-all-vesting-account
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Dec 11, 2024
2 parents a9b1fad + 741d5cb commit 9ca5f96
Show file tree
Hide file tree
Showing 23 changed files with 426 additions and 323 deletions.
14 changes: 9 additions & 5 deletions internal/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"

"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cosmos/ibc-go/v9/internal/validate"
)
Expand All @@ -18,35 +20,37 @@ func TestGRPCRequest(t *testing.T) {
msg string
portID string
channelID string
expPass bool
expErr error
}{
{
"success",
validID,
validID,
true,
nil,
},
{
"invalid portID",
invalidID,
validID,
false,
status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"),
},
{
"invalid channelID",
validID,
invalidID,
false,
status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"),
},
}

for _, tc := range testCases {
t.Run(fmt.Sprintf("Case %s", tc.msg), func(t *testing.T) {
err := validate.GRPCRequest(tc.portID, tc.channelID)
if tc.expPass {

if tc.expErr == nil {
require.NoError(t, err, tc.msg)
} else {
require.Error(t, err, tc.msg)
require.EqualError(t, err, tc.expErr.Error(), tc.msg)
}
})
}
Expand Down
91 changes: 60 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,17 @@ 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 +27,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 +50,10 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
ConnectionId: ibctesting.InvalidID,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrConnectionNotFound, "IDisInvalid").Error(),
),
},
{
"success",
Expand All @@ -62,7 +71,7 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
ConnectionId: path.EndpointA.ConnectionID,
}
},
true,
nil,
},
}

Expand All @@ -78,12 +87,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 +114,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 +165,7 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
},
}
},
true,
nil,
},
}

Expand All @@ -171,12 +181,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 +202,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 +225,10 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
ClientId: ibctesting.InvalidID,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, "IDisInvalid").Error(),
),
},
{
"success",
Expand All @@ -236,7 +250,7 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
ClientId: path1.EndpointA.ClientID,
}
},
true,
nil,
},
}

Expand All @@ -252,12 +266,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 +287,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 +303,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 +312,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 +329,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 +347,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
ConnectionId: path.EndpointA.ConnectionID,
}
},
true,
nil,
},
}

Expand All @@ -342,7 +363,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 +373,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -367,14 +389,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 +407,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 +418,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 +434,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 +457,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionHeight: clientHeight.GetRevisionHeight(),
}
},
true,
nil,
},
}

Expand All @@ -445,7 +473,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 +486,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 9ca5f96

Please sign in to comment.