From 6d764319ced65a89c7e17e43445615885f344a05 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 28 Feb 2024 19:15:54 +0530 Subject: [PATCH] Add remaining bond module keeper tests --- .../bond/keeper/query_server_test.go | 127 ++++++++++++++++++ tests/integration/common.go | 2 +- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/tests/integration/bond/keeper/query_server_test.go b/tests/integration/bond/keeper/query_server_test.go index efc69a8a..e652326e 100644 --- a/tests/integration/bond/keeper/query_server_test.go +++ b/tests/integration/bond/keeper/query_server_test.go @@ -67,6 +67,133 @@ func (kts *KeeperTestSuite) TestGrpcQueryBondsList() { } } +func (kts *KeeperTestSuite) TestGrpcQueryBondByBondId() { + testCases := []struct { + msg string + req *types.QueryGetBondByIdRequest + createBonds bool + errResponse bool + bondId string + }{ + { + "empty request", + &types.QueryGetBondByIdRequest{}, + false, + true, + "", + }, + { + "Get Bond By ID", + &types.QueryGetBondByIdRequest{}, + true, + false, + "", + }, + } + + for _, test := range testCases { + kts.Run(fmt.Sprintf("Case %s ", test.msg), func() { + if test.createBonds { + bond, err := kts.createBond() + kts.Require().NoError(err) + test.req.Id = bond.Id + } + resp, err := kts.queryClient.GetBondById(context.Background(), test.req) + if !test.errResponse { + kts.Require().Nil(err) + kts.Require().NotNil(resp.GetBond()) + kts.Require().Equal(test.req.Id, resp.GetBond().GetId()) + } else { + kts.Require().NotNil(err) + kts.Require().Error(err) + } + }) + } +} + +func (kts *KeeperTestSuite) TestGrpcGetBondsByOwner() { + testCases := []struct { + msg string + req *types.QueryGetBondsByOwnerRequest + noOfBonds int + createBonds bool + errResponse bool + bondId string + }{ + { + "empty request", + &types.QueryGetBondsByOwnerRequest{}, + 0, + false, + true, + "", + }, + { + "Get Bond By Owner", + &types.QueryGetBondsByOwnerRequest{}, + 1, + true, + false, + "", + }, + } + + for _, test := range testCases { + kts.Run(fmt.Sprintf("Case %s ", test.msg), func() { + if test.createBonds { + bond, err := kts.createBond() + kts.Require().NoError(err) + test.req.Owner = bond.Owner + } + resp, err := kts.queryClient.GetBondsByOwner(context.Background(), test.req) + if !test.errResponse { + kts.Require().Nil(err) + kts.Require().NotNil(resp.GetBonds()) + kts.Require().Equal(test.noOfBonds, len(resp.GetBonds())) + } else { + kts.Require().NotNil(err) + kts.Require().Error(err) + } + }) + } +} + +func (kts *KeeperTestSuite) TestGrpcGetModuleBalance() { + testCases := []struct { + msg string + req *types.QueryGetBondModuleBalanceRequest + noOfBonds int + createBonds bool + errResponse bool + }{ + { + "empty request", + &types.QueryGetBondModuleBalanceRequest{}, + 0, + true, + false, + }, + } + + for _, test := range testCases { + kts.Run(fmt.Sprintf("Case %s ", test.msg), func() { + if test.createBonds { + _, err := kts.createBond() + kts.Require().NoError(err) + } + resp, err := kts.queryClient.GetBondsModuleBalance(context.Background(), test.req) + if !test.errResponse { + kts.Require().Nil(err) + kts.Require().NotNil(resp.GetBalance()) + kts.Require().Equal(resp.GetBalance(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(10)))) + } else { + kts.Require().NotNil(err) + kts.Require().Error(err) + } + }) + } +} + func (kts *KeeperTestSuite) createBond() (*types.Bond, error) { ctx, k := kts.SdkCtx, kts.BondKeeper accCount := 1 diff --git a/tests/integration/common.go b/tests/integration/common.go index ce93ec65..70ead0ab 100644 --- a/tests/integration/common.go +++ b/tests/integration/common.go @@ -98,7 +98,7 @@ func (tf *TestFixture) Setup() error { auctionKeeper := auctionkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[auctionTypes.StoreKey]), accountKeeper, bankKeeper) - bondKeeper := bondkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[auctionTypes.StoreKey]), accountKeeper, bankKeeper) + bondKeeper := bondkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[bondTypes.StoreKey]), accountKeeper, bankKeeper) authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)