Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: end point to get intents across all zones for a delegator address #466 #468

Merged
merged 36 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3f9412a
front-port v1.2.13
Jun 2, 2023
c1056cd
fix delegation flush test
May 29, 2023
f59917a
add tests for HandleDepositTransaction
May 29, 2023
2637729
update tests for new error handling
May 30, 2023
cd44c38
remove superflous field in proto
Jun 2, 2023
f9a1f71
final v1.2.13 front-port and test fixes
Jun 2, 2023
c8f0205
s/s/suite/
Jun 2, 2023
be20f50
remove fmt.Printlns used for debugging
Jun 2, 2023
b18cd9f
update participation rewards and protocoldatas, to add validation, au…
Jun 2, 2023
6a77679
front-port v1.2.13
Jun 2, 2023
058bd08
remove balancerPoolPretty json marshal/unmarshal, as we deal with raw…
Jun 5, 2023
5502cb3
fix: allow support for multiple denoms from same zone in tvl calc
Jun 5, 2023
43f0dcf
lint
Jun 5, 2023
48ef8cc
fix: refactor utils/address.go to avoid import cycle when using in os…
Jun 8, 2023
a8333ed
add test for randomutils
Jun 8, 2023
08c6382
fix: remove potential non-det by iterating over maps using sorted keys
Jun 8, 2023
a8bc5eb
resolve outstanding nits
Jun 8, 2023
8f9c1a5
lint
Jun 8, 2023
27174c0
fix nits
Jun 9, 2023
87ed29e
bump go to 1.20.5
Jun 9, 2023
2a7d2c4
Merge branch 'develop' into pr-tvl-updates
Jun 9, 2023
729e5bf
Update x/interchainstaking/keeper/receipt.go
Jun 12, 2023
f69e7b9
Apply suggestions from code review
Jun 12, 2023
dcbb1fb
lint
Jun 12, 2023
ccf97e2
bump hermes to v1.5.0
Jun 12, 2023
974ea7f
update icq and relayer in test scripts
Jun 12, 2023
04df0fb
Merge remote-tracking branch 'origin/develop' into develop
muku314115 Jun 16, 2023
c7ad866
Merge remote-tracking branch 'origin/develop' into develop
muku314115 Jun 19, 2023
468fdfc
copying
muku314115 Jun 20, 2023
c07ca18
Merge branch 'develop' into mukund/delegatorintents
Jun 20, 2023
12092f6
Update x/interchainstaking/keeper/grpc_query.go
muku314115 Jun 21, 2023
4b6abfc
adding nil check
muku314115 Jun 21, 2023
b15e78e
Merge remote-tracking branch 'origin/mukund/delegatorintents' into mu…
muku314115 Jun 21, 2023
a5234f8
Merge branch 'develop' of https://github.com/ingenuity-build/quicksil…
muku314115 Jun 21, 2023
c311c50
proto format
muku314115 Jun 21, 2023
7b9d5ef
Merge branch 'develop' into mukund/delegatorintents
Jun 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions proto/quicksilver/interchainstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ service Query {
rpc DepositAccount(QueryDepositAccountForChainRequest) returns (QueryDepositAccountForChainResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/zones/{chain_id}/deposit_address";
}

// DelegatorIntent provides data on the intent of the delegator for the given
// zone.
rpc DelegatorIntent(QueryDelegatorIntentRequest) returns (QueryDelegatorIntentResponse) {
Expand All @@ -37,6 +38,13 @@ service Query {
"{delegator_address}";
}

// DelegatorIntents provides data on the intent of the delegator for all zones
rpc DelegatorIntents(QueryDelegatorIntentsRequest) returns (QueryDelegatorIntentsResponse) {
option (google.api.http).get =
"/quicksilver/interchainstaking/v1/delegator_intents/"
"{delegator_address}";
}

// Delegations provides data on the delegations for the given zone.
rpc Delegations(QueryDelegationsRequest) returns (QueryDelegationsResponse) {
option (google.api.http).get = "/quicksilver/interchainstaking/v1/zones/{chain_id}/delegations";
Expand Down Expand Up @@ -143,6 +151,19 @@ message QueryDelegatorIntentResponse {
DelegatorIntent intent = 1;
}

message QueryDelegatorIntentsRequest {
string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message DelegatorIntentsResponse {
string chain_id = 1;
DelegatorIntent intent = 2;
}

message QueryDelegatorIntentsResponse {
repeated DelegatorIntentsResponse intents = 1;
}

message QueryDelegationsRequest {
string chain_id = 1 [(gogoproto.moretags) = "yaml:\"chain_id\""];
cosmos.base.query.v1beta1.PageRequest pagination = 2;
Expand Down
21 changes: 21 additions & 0 deletions x/interchainstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ func (k *Keeper) DelegatorIntent(c context.Context, req *types.QueryDelegatorInt
return &types.QueryDelegatorIntentResponse{Intent: &intent}, nil
}

// DelegatorIntents returns information about the delegation intent of the given delegator for all zones.
func (k *Keeper) DelegatorIntents(c context.Context, req *types.QueryDelegatorIntentsRequest) (*types.QueryDelegatorIntentsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c)

intents := []*types.DelegatorIntentsResponse{}

k.IterateZones(ctx, func(_ int64, zone *types.Zone) bool {
intent, _ := k.GetDelegatorIntent(ctx, zone, req.DelegatorAddress, false)
if intent.Intents != nil {
intents = append(intents, &types.DelegatorIntentsResponse{ChainId: zone.ChainId, Intent: &intent})
}
return false
})

return &types.QueryDelegatorIntentsResponse{Intents: intents}, nil
}

func (k *Keeper) Delegations(c context.Context, req *types.QueryDelegationsRequest) (*types.QueryDelegationsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down
144 changes: 138 additions & 6 deletions x/interchainstaking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/ingenuity-build/quicksilver/x/interchainstaking/types"
)

var delegatorAddress = "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure"

func (suite *KeeperTestSuite) TestKeeper_Zones() {
icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper
ctx := suite.chainA.GetContext()
Expand Down Expand Up @@ -313,6 +315,136 @@ func (suite *KeeperTestSuite) TestKeeper_DelegatorIntent() {
}
}

func (suite *KeeperTestSuite) TestKeeper_DelegatorIntents() {
icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper
ctx := suite.chainA.GetContext()

tests := []struct {
name string
malleate func()
req *types.QueryDelegatorIntentsRequest
wantErr bool
verify func(delegation []*types.DelegatorIntentsResponse)
}{
{
name: "DelegatorIntent_Nil_Request",
malleate: func() {},
req: nil,
wantErr: true,
verify: func([]*types.DelegatorIntentsResponse) {
},
},
{
"DelegatorIntent_No_Delegator_Intents",
func() {
},
&types.QueryDelegatorIntentsRequest{
DelegatorAddress: testAddress,
},
false,
func(intents []*types.DelegatorIntentsResponse) {
for _, intent := range intents {
suite.Require().Equal(intent.ChainId, suite.chainB.ChainID)
suite.Require().Equal(len(intent.Intent.Intents), 0)
}
},
},
{
"DelegatorIntent_Valid_Intents across multiple zones",
func() {
zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID)
suite.Require().True(found)
// give funds
suite.giveFunds(ctx, zone.LocalDenom, 5000000, testAddress)
// set intents
intents := []types.DelegatorIntent{
{
Delegator: testAddress,
Intents: types.ValidatorIntents{
&types.ValidatorIntent{
ValoperAddress: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress,
Weight: sdk.OneDec(),
},
},
},
}
for _, intent := range intents {
icsKeeper.SetDelegatorIntent(ctx, &zone, intent, false)
}

// cosmos zone
zone = types.Zone{
ConnectionId: "connection-77001",
ChainId: "cosmoshub-4",
AccountPrefix: "cosmos",
LocalDenom: "uqatom",
BaseDenom: "uatom",
MultiSend: false,
LiquidityModule: false,
Is_118: true,
}
(&icsKeeper).SetZone(ctx, &zone)
// give funds
suite.giveFunds(ctx, zone.LocalDenom, 5000000, testAddress)
// set intents
intents = []types.DelegatorIntent{
{
Delegator: testAddress,
Intents: types.ValidatorIntents{
&types.ValidatorIntent{
ValoperAddress: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress,
Weight: sdk.OneDec(),
},
},
},
}
for _, intent := range intents {
icsKeeper.SetDelegatorIntent(ctx, &zone, intent, false)
}
},
&types.QueryDelegatorIntentsRequest{
DelegatorAddress: testAddress,
},
false,
func(intents []*types.DelegatorIntentsResponse) {
suite.Require().Equal(len(intents), 2)
suite.Require().Equal(intents[0].ChainId, "cosmoshub-4")
suite.Require().Equal(intents[1].ChainId, suite.chainB.ChainID)
for _, intent := range intents {
suite.Require().Equal(intent.Intent.Delegator, testAddress)
suite.Require().Equal(len(intent.Intent.Intents), 1)
}
},
},
}

// run tests:
suite.setupTestZones()

for _, tt := range tests {
suite.Run(tt.name, func() {
tt.malleate()
resp, err := icsKeeper.DelegatorIntents(
ctx,
tt.req,
)
if tt.wantErr {
suite.T().Logf("Error:\n%v\n", err)
suite.Require().Error(err)
return
}
suite.Require().NoError(err)
suite.Require().NotNil(resp)
tt.verify(resp.Intents)

vstr, err := json.MarshalIndent(resp, "", "\t")
suite.Require().NoError(err)

suite.T().Logf("Response:\n%s\n", vstr)
})
}
}

func (suite *KeeperTestSuite) TestKeeper_Delegations() {
icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper
ctx := suite.chainA.GetContext()
Expand Down Expand Up @@ -525,7 +657,7 @@ func (suite *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() {
func() {},
&types.QueryWithdrawalRecordsRequest{
ChainId: suite.chainB.ChainID,
DelegatorAddress: "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure",
DelegatorAddress: delegatorAddress,
},
false,
0,
Expand All @@ -551,7 +683,7 @@ func (suite *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() {
icsKeeper.AddWithdrawalRecord(
ctx,
zone.ChainId,
"quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure",
delegatorAddress,
distribution,
testAddress,
sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(15000000))),
Expand All @@ -563,7 +695,7 @@ func (suite *KeeperTestSuite) TestKeeper_ZoneWithdrawalRecords() {
},
&types.QueryWithdrawalRecordsRequest{
ChainId: suite.chainB.ChainID,
DelegatorAddress: "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure",
DelegatorAddress: delegatorAddress,
},
false,
1,
Expand Down Expand Up @@ -655,7 +787,7 @@ func (suite *KeeperTestSuite) TestKeeper_UserWithdrawalRecords() {
icsKeeper.AddWithdrawalRecord(
ctx,
zone.ChainId,
"quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure",
delegatorAddress,
distribution,
testAddress,
sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(15000000))),
Expand All @@ -666,7 +798,7 @@ func (suite *KeeperTestSuite) TestKeeper_UserWithdrawalRecords() {
)
},
&types.QueryUserWithdrawalRecordsRequest{
UserAddress: "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure",
UserAddress: delegatorAddress,
},
false,
1,
Expand Down Expand Up @@ -747,7 +879,7 @@ func (suite *KeeperTestSuite) TestKeeper_WithdrawalRecords() {
icsKeeper.AddWithdrawalRecord(
ctx,
zone.ChainId,
"quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure",
delegatorAddress,
distribution,
testAddress,
sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(15000000))),
Expand Down
Loading