Skip to content

Commit

Permalink
test(ics): add valid test case for query delegator intent integration…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
tuantran1702 committed Mar 26, 2024
1 parent 89a83ad commit f1b7c11
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
50 changes: 43 additions & 7 deletions x/interchainstaking/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"
)

const (
testDelegator = "cosmos1r2dthxctqzhwg299e7aaeqwfkgcc9hg8n9scjg"
)

type IntegrationTestSuite struct {
suite.Suite

Expand Down Expand Up @@ -68,7 +72,6 @@ func (s *IntegrationTestSuite) SetupSuite() {
Is_118: true,
}

// TODO: I think setting validators here isn't enough, we need to set them in the store by using the keeper
zone.Validators = append(zone.Validators,
&types.Validator{ValoperAddress: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000), Score: sdk.ZeroDec(), ValidatorBondShares: sdk.ZeroDec(), LiquidShares: sdk.ZeroDec()},
&types.Validator{ValoperAddress: "cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000), Score: sdk.ZeroDec(), ValidatorBondShares: sdk.ZeroDec(), LiquidShares: sdk.ZeroDec()},
Expand All @@ -77,9 +80,30 @@ func (s *IntegrationTestSuite) SetupSuite() {
&types.Validator{ValoperAddress: "cosmosvaloper1z8zjv3lntpwxua0rtpvgrcwl0nm0tltgpgs6l7", CommissionRate: sdk.MustNewDecFromStr("0.2"), VotingPower: sdk.NewInt(2000), DelegatorShares: sdk.NewDec(2000), Score: sdk.ZeroDec(), ValidatorBondShares: sdk.ZeroDec(), LiquidShares: sdk.ZeroDec()},
)

delegationIntents := []types.DelegatorIntentsForZone{
{
ChainId: zone.ChainId,
DelegationIntent: []*types.DelegatorIntent{
{
Delegator: testDelegator,
Intents: types.ValidatorIntents{
{
ValoperAddress: zone.Validators[0].ValoperAddress,
Weight: sdk.NewDec(1),
},
{
ValoperAddress: zone.Validators[1].ValoperAddress,
Weight: sdk.NewDec(1),
},
},
},
},
},
}
// setup basic genesis state
newGenesis := types.DefaultGenesis()
newGenesis.Zones = []types.Zone{zone}
newGenesis.DelegatorIntents = delegationIntents
updateGenesisConfigState(types.ModuleName, newGenesis)
s.zones = []types.Zone{zone}

Expand Down Expand Up @@ -175,7 +199,6 @@ func (s *IntegrationTestSuite) ZonesEqual(zoneA, zoneB types.Zone) bool {

func (s *IntegrationTestSuite) TestGetDelegatorIntentCmd() {
val := s.network.Validators[0]

tests := []struct {
name string
args []string
Expand Down Expand Up @@ -204,20 +227,33 @@ func (s *IntegrationTestSuite) TestGetDelegatorIntentCmd() {
&types.QueryDelegatorIntentResponse{},
&types.QueryDelegatorIntentResponse{},
},
/* {
{
"valid",
[]string{s.cfg.ChainID, ""},
[]string{s.zones[0].ChainId, testDelegator},
false,
&types.QueryDelegatorIntentResponse{},
&types.QueryDelegatorIntentResponse{},
}, */
&types.QueryDelegatorIntentResponse{
Intent: &types.DelegatorIntent{
Delegator: testDelegator,
Intents: types.ValidatorIntents{
{
ValoperAddress: s.zones[0].Validators[0].ValoperAddress,
Weight: sdk.NewDec(1),
},
{
ValoperAddress: s.zones[0].Validators[1].ValoperAddress,
Weight: sdk.NewDec(1),
},
},
},
},
},
}
for _, tt := range tests {
tt := tt

s.Run(tt.name, func() {
clientCtx := val.ClientCtx

runFlags := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
Expand Down
8 changes: 4 additions & 4 deletions x/interchainstaking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,11 +1453,11 @@ func (suite *KeeperTestSuite) TestKeeper_UserZoneWithdrawalRecords() {
distributions := []*types.Distribution{
{
Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress,
Amount: 10000000,
Amount: sdk.NewInt(10000000),
},
{
Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[1].ValoperAddress,
Amount: 20000000,
Amount: sdk.NewInt(20000000),
},
}

Expand Down Expand Up @@ -1491,11 +1491,11 @@ func (suite *KeeperTestSuite) TestKeeper_UserZoneWithdrawalRecords() {
distributions := []*types.Distribution{
{
Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress,
Amount: 10000000,
Amount: sdk.NewInt(10000000),
},
{
Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[1].ValoperAddress,
Amount: 20000000,
Amount: sdk.NewInt(20000000),
},
}

Expand Down
2 changes: 1 addition & 1 deletion x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ func isNumericString(in string) bool {
// and to parse numeric values, say in the smallest unit of uqck
// MaxInt64: (1<<63)-1 = 9_223_372_036_854_775_807 uqck aka
// 9_223_372_036_854.775 (9.223 Trillion) qck
// so the function is appropriate as its range won't be exceeded.
// so the function is appropriate as its range won't be exceeded.
_, err := strconv.ParseInt(in, 10, 64)
return err == nil
}
Expand Down

0 comments on commit f1b7c11

Please sign in to comment.