Skip to content

Commit

Permalink
increase coverage back
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Ivanov committed Dec 15, 2023
1 parent 6b1fba8 commit 7754d04
Showing 1 changed file with 111 additions and 100 deletions.
211 changes: 111 additions & 100 deletions x/vesting/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -1,102 +1,113 @@
package keeper_test

//func (suite *KeeperTestSuite) TestBalances() {
// var (
// req *types.QueryBalancesRequest
// expRes *types.QueryBalancesResponse
// )
// addr := sdk.AccAddress(tests.GenerateAddress().Bytes())
//
// testCases := []struct {
// name string
// malleate func()
// expPass bool
// }{
// {
// "empty req",
// func() {
// req = &types.QueryBalancesRequest{}
// },
// false,
// },
// {
// "invalid address",
// func() {
// req = &types.QueryBalancesRequest{
// Address: "haqq1",
// }
// },
// false,
// },
// {
// "invalid account - not found",
// func() {
// req = &types.QueryBalancesRequest{
// Address: addr.String(),
// }
// },
// false,
// },
// {
// "invalid account - not clawback vesting account",
// func() {
// baseAccount := authtypes.NewBaseAccountWithAddress(addr)
// acc := suite.app.AccountKeeper.NewAccount(suite.ctx, baseAccount)
// suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
//
// req = &types.QueryBalancesRequest{
// Address: addr.String(),
// }
// },
// false,
// },
// {
// "valid",
// func() {
// vestingStart := s.ctx.BlockTime()
// funder := sdk.AccAddress(types.ModuleName)
// err := testutil.FundAccount(suite.ctx, suite.app.BankKeeper, funder, balances)
// suite.Require().NoError(err)
//
// msg := types.NewMsgCreateClawbackVestingAccount(
// funder,
// addr,
// vestingStart,
// lockupPeriods,
// vestingPeriods,
// false,
// )
// ctx := sdk.WrapSDKContext(suite.ctx)
// _, err = suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, msg)
// suite.Require().NoError(err)
//
// req = &types.QueryBalancesRequest{
// Address: addr.String(),
// }
// expRes = &types.QueryBalancesResponse{
// Locked: balances,
// Unvested: balances,
// Vested: nil,
// }
// },
// true,
// },
// }
//
// for _, tc := range testCases {
// suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
// suite.SetupTest() // reset
// ctx := sdk.WrapSDKContext(suite.ctx)
// tc.malleate()
// suite.Commit()
//
// res, err := suite.queryClient.Balances(ctx, req)
// if tc.expPass {
// suite.Require().NoError(err)
// suite.Require().Equal(expRes, res)
// } else {
// suite.Require().Error(err)
// }
// })
// }
//}
import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/haqq-network/haqq/tests"
"github.com/haqq-network/haqq/testutil"
"github.com/haqq-network/haqq/x/vesting/types"
)

func (suite *KeeperTestSuite) TestBalances() {
var (
req *types.QueryBalancesRequest
expRes *types.QueryBalancesResponse
)
addr := sdk.AccAddress(tests.GenerateAddress().Bytes())

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"empty req",
func() {
req = &types.QueryBalancesRequest{}
},
false,
},
{
"invalid address",
func() {
req = &types.QueryBalancesRequest{
Address: "haqq1",
}
},
false,
},
{
"invalid account - not found",
func() {
req = &types.QueryBalancesRequest{
Address: addr.String(),
}
},
false,
},
{
"invalid account - not clawback vesting account",
func() {
baseAccount := authtypes.NewBaseAccountWithAddress(addr)
acc := suite.app.AccountKeeper.NewAccount(suite.ctx, baseAccount)
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

req = &types.QueryBalancesRequest{
Address: addr.String(),
}
},
false,
},
{
"valid",
func() {
vestingStart := s.ctx.BlockTime()
funder := sdk.AccAddress(types.ModuleName)
err := testutil.FundAccount(suite.ctx, suite.app.BankKeeper, funder, balances)
suite.Require().NoError(err)

msg := types.NewMsgCreateClawbackVestingAccount(
funder,
addr,
vestingStart,
lockupPeriods,
vestingPeriods,
false,
)
ctx := sdk.WrapSDKContext(suite.ctx)
_, err = suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, msg)
suite.Require().NoError(err)

req = &types.QueryBalancesRequest{
Address: addr.String(),
}
expRes = &types.QueryBalancesResponse{
Locked: balances,
Unvested: balances,
Vested: nil,
}
},
true,
},
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
suite.SetupTest() // reset
ctx := sdk.WrapSDKContext(suite.ctx)
tc.malleate()
suite.Commit()

res, err := suite.queryClient.Balances(ctx, req)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(expRes, res)
} else {
suite.Require().Error(err)
}
})
}
}

0 comments on commit 7754d04

Please sign in to comment.