From 925b51148215539222c14d94af219415807e027c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Anh=20Minh?= <1phamminh0811@gmail.com> Date: Mon, 9 Oct 2023 13:08:14 +0700 Subject: [PATCH 1/2] add test for get active validator --- x/interchainstaking/keeper/validator_test.go | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/x/interchainstaking/keeper/validator_test.go b/x/interchainstaking/keeper/validator_test.go index 84f444346..43eb807b2 100644 --- a/x/interchainstaking/keeper/validator_test.go +++ b/x/interchainstaking/keeper/validator_test.go @@ -53,3 +53,48 @@ func (suite *KeeperTestSuite) TestStoreGetDeleteValidator() { suite.Equal(count, count3) }) } + +func (suite *KeeperTestSuite) TestGetActiveValidators() { + suite.Run("active validators", func() { + suite.SetupTest() + suite.setupTestZones() + + app := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + + zone, found := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.True(found) + + validators := app.InterchainstakingKeeper.GetActiveValidators(ctx, "not a chain id") + suite.Len(validators, 0) + + validators = app.InterchainstakingKeeper.GetActiveValidators(ctx, zone.ChainId) + count := len(validators) + + validator1 := addressutils.GenerateValAddressForTest() + validator2 := addressutils.GenerateValAddressForTest() + + newValidator1 := types.Validator{ + ValoperAddress: validator1.String(), + CommissionRate: sdk.NewDec(5.0), + DelegatorShares: sdk.NewDec(1000.0), + VotingPower: sdk.NewInt(1000), + Status: stakingtypes.BondStatusBonded, + Score: sdk.NewDec(0), + } + newValidator2 := newValidator1 + newValidator2.ValoperAddress = validator2.String() + newValidator2.Status = stakingtypes.BondStatusUnbonded + + err := app.InterchainstakingKeeper.SetValidator(ctx, zone.ChainId, newValidator1) + suite.NoError(err) + + err = app.InterchainstakingKeeper.SetValidator(ctx, zone.ChainId, newValidator2) + suite.NoError(err) + + validators = app.InterchainstakingKeeper.GetActiveValidators(ctx, zone.ChainId) + count2 := len(validators) + + suite.Equal(count +1, count2) + }) +} \ No newline at end of file From aecab46627497249cd93419d9b69111ca8c06e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Anh=20Minh?= <1phamminh0811@gmail.com> Date: Mon, 9 Oct 2023 13:11:21 +0700 Subject: [PATCH 2/2] lint --- x/interchainstaking/keeper/validator_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/interchainstaking/keeper/validator_test.go b/x/interchainstaking/keeper/validator_test.go index 43eb807b2..f6b37f889 100644 --- a/x/interchainstaking/keeper/validator_test.go +++ b/x/interchainstaking/keeper/validator_test.go @@ -85,7 +85,7 @@ func (suite *KeeperTestSuite) TestGetActiveValidators() { newValidator2 := newValidator1 newValidator2.ValoperAddress = validator2.String() newValidator2.Status = stakingtypes.BondStatusUnbonded - + err := app.InterchainstakingKeeper.SetValidator(ctx, zone.ChainId, newValidator1) suite.NoError(err) @@ -95,6 +95,6 @@ func (suite *KeeperTestSuite) TestGetActiveValidators() { validators = app.InterchainstakingKeeper.GetActiveValidators(ctx, zone.ChainId) count2 := len(validators) - suite.Equal(count +1, count2) + suite.Equal(count+1, count2) }) -} \ No newline at end of file +}