Skip to content

Commit

Permalink
fix tests in 08-wasm grpc_query_test
Browse files Browse the repository at this point in the history
  • Loading branch information
likesToEatFish committed Dec 11, 2024
1 parent 632ceae commit f02fcbc
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions modules/light-clients/08-wasm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

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

errorsmod "cosmossdk.io/errors"
wasmtesting "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing"
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
)
Expand All @@ -16,7 +20,7 @@ func (suite *KeeperTestSuite) TestQueryCode() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success",
Expand All @@ -29,21 +33,27 @@ func (suite *KeeperTestSuite) TestQueryCode() {

req = &types.QueryCodeRequest{Checksum: hex.EncodeToString(res.Checksum)}
},
true,
nil,
},
{
"fails with empty request",
func() {
req = &types.QueryCodeRequest{}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrWasmChecksumNotFound, "").Error(),
),
},
{
"fails with non-existent checksum",
func() {
req = &types.QueryCodeRequest{Checksum: "test"}
},
false,
status.Error(
codes.InvalidArgument,
types.ErrInvalidChecksum.Error(),
),
},
}

Expand All @@ -55,12 +65,13 @@ func (suite *KeeperTestSuite) TestQueryCode() {

res, err := GetSimApp(suite.chainA).WasmClientKeeper.Code(suite.chainA.GetContext(), req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().NotEmpty(res.Data)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -72,14 +83,14 @@ func (suite *KeeperTestSuite) TestQueryChecksums() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success with no checksums",
func() {
expChecksums = []string{}
},
true,
nil,
},
{
"success with one checksum",
Expand All @@ -92,7 +103,7 @@ func (suite *KeeperTestSuite) TestQueryChecksums() {

expChecksums = append(expChecksums, hex.EncodeToString(res.Checksum))
},
true,
nil,
},
}

Expand All @@ -105,7 +116,7 @@ func (suite *KeeperTestSuite) TestQueryChecksums() {
req := &types.QueryChecksumsRequest{}
res, err := GetSimApp(suite.chainA).WasmClientKeeper.Checksums(suite.chainA.GetContext(), req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(len(expChecksums), len(res.Checksums))
Expand Down

0 comments on commit f02fcbc

Please sign in to comment.