Skip to content

Commit

Permalink
cleanup and add testcase for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilkumarpilli committed Nov 13, 2024
1 parent a01cf48 commit f623b96
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tests/integration/server/grpc/out_of_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grpc_test

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/suite"
Expand All @@ -12,6 +11,7 @@ import (

"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
"cosmossdk.io/math"
"cosmossdk.io/x/bank"
bankkeeper "cosmossdk.io/x/bank/keeper"
banktypes "cosmossdk.io/x/bank/types"
Expand Down Expand Up @@ -41,7 +41,6 @@ import (
type IntegrationTestOutOfGasSuite struct {
suite.Suite

grpcCtx context.Context
conn *grpc.ClientConn
address sdk.AccAddress
}
Expand Down Expand Up @@ -124,29 +123,39 @@ func (s *IntegrationTestOutOfGasSuite) SetupSuite() {
banktypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), bankkeeper.NewMsgServerImpl(bankKeeper))
banktypes.RegisterQueryServer(integrationApp.GRPCQueryRouter(), bankkeeper.NewQuerier(&bankKeeper))
testdata.RegisterQueryServer(integrationApp.GRPCQueryRouter(), testdata.QueryImpl{})

banktypes.RegisterInterfaces(encodingCfg.InterfaceRegistry)

grpcCfg := srvconfig.DefaultConfig().GRPC

msgSend := banktypes.MsgSend{
FromAddress: addr2.String(),
ToAddress: s.address.String(),
Amount: sdk.NewCoins(sdk.NewInt64Coin("stake", 50)),
}

_, err := integrationApp.RunMsg(
&msgSend,
&banktypes.MsgSend{
FromAddress: addr2.String(),
ToAddress: s.address.String(),
Amount: sdk.NewCoins(sdk.NewInt64Coin("stake", 50)),
},
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
s.Require().NoError(err)
s.Require().Equal(integrationApp.LastBlockHeight(), int64(2))

grpcSrv := grpc.NewServer(grpc.ForceServerCodec(codec.NewProtoCodec(encodingCfg.InterfaceRegistry).GRPCCodec()))
resp, err := bankKeeper.Balance(integrationApp.Context(), &banktypes.QueryBalanceRequest{Address: s.address.String(), Denom: "stake"})
s.Require().NoError(err)
s.Require().Equal(int64(50), resp.Balance.Amount.Int64())

grpcSrv := grpc.NewServer(
grpc.ForceServerCodec(codec.NewProtoCodec(encodingCfg.InterfaceRegistry).GRPCCodec()),
)
integrationApp.RegisterGRPCServer(grpcSrv)

grpcCfg := srvconfig.DefaultConfig().GRPC
go func() {
s.Require().NoError(servergrpc.StartGRPCServer(context.Background(), integrationApp.Logger(), grpcCfg, grpcSrv))
err := servergrpc.StartGRPCServer(
integrationApp.Context(),
integrationApp.Logger(),
grpcCfg,
grpcSrv,
)
s.Require().NoError(err)
defer grpcSrv.GracefulStop()
}()

s.conn, err = grpc.NewClient(
Expand Down Expand Up @@ -181,8 +190,7 @@ func (s *IntegrationTestOutOfGasSuite) TestGRPCServer_BankBalance_OutOfGas() {
&banktypes.QueryBalanceRequest{Address: s.address.String(), Denom: "stake"},
)

fmt.Println("Res....", res)

s.Require().Equal(math.NewInt(50).Int64(), res.Balance.Amount.Int64())
s.Require().ErrorContains(err, sdkerrors.ErrOutOfGas.Error())
}

Expand Down

0 comments on commit f623b96

Please sign in to comment.