Skip to content

Commit

Permalink
Superfluid Misc: Improve grpc_query (#1084)
Browse files Browse the repository at this point in the history
* Fix Query for empty connected intermediary account

* Improve superfluid grpc-query

(cherry picked from commit 052bc20)

# Conflicts:
#	x/superfluid/keeper/grpc_query_test.go
  • Loading branch information
mattverse authored and mergify-bot committed Mar 14, 2022
1 parent 5e7c937 commit 526ec93
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
13 changes: 12 additions & 1 deletion x/superfluid/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ func (k Keeper) ConnectedIntermediaryAccount(goCtx context.Context, req *types.C
address := k.GetLockIdIntermediaryAccountConnection(ctx, req.LockId)
acc := k.GetIntermediaryAccount(ctx, address)

if len(acc.Denom) == 0 && acc.GaugeId == uint64(0) && len(acc.ValAddr) == 0 {
return &types.ConnectedIntermediaryAccountResponse{
Account: &types.SuperfluidIntermediaryAccountInfo{
Denom: acc.Denom,
ValAddr: acc.ValAddr,
GaugeId: acc.GaugeId,
Address: "",
},
}, nil
}

return &types.ConnectedIntermediaryAccountResponse{
Account: &types.SuperfluidIntermediaryAccountInfo{
Denom: acc.Denom,
Expand Down Expand Up @@ -307,7 +318,7 @@ func (k Keeper) TotalSuperfluidDelegations(goCtx context.Context, req *types.Tot

delegation, found := k.sk.GetDelegation(ctx, intermediaryAccount.GetAccAddress(), valAddr)
if !found {
return nil, stakingtypes.ErrNoDelegation
continue
}

syntheticOsmoAmt := delegation.Shares.Quo(val.DelegatorShares).MulInt(val.Tokens).RoundInt()
Expand Down
24 changes: 24 additions & 0 deletions x/superfluid/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegations() {
}

// setup superfluid delegations
<<<<<<< HEAD
suite.SetupSuperfluidDelegations(delAddrs, valAddrs, superfluidDelegations)
=======
_, locks := suite.SetupSuperfluidDelegations(delAddrs, valAddrs, superfluidDelegations, denoms)
>>>>>>> 052bc20 (Superfluid Misc: Improve grpc_query (#1084))

// for each superfluid delegation, query the amount and make sure it is 1000000
for _, delegation := range superfluidDelegations {
Expand Down Expand Up @@ -111,6 +115,22 @@ func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegations() {
suite.Require().NoError(err)
suite.Require().Equal(sdk.NewInt(40000000), totalSuperfluidDelegationsRes.TotalDelegations)

<<<<<<< HEAD
=======
for _, lockID := range locks {
connectedIntermediaryAccountRes, err := suite.queryClient.ConnectedIntermediaryAccount(sdk.WrapSDKContext(suite.Ctx), &types.ConnectedIntermediaryAccountRequest{LockId: lockID.ID})
suite.Require().NoError(err)
suite.Require().NotEqual("", connectedIntermediaryAccountRes.Account.Denom)
suite.Require().NotEqual("", connectedIntermediaryAccountRes.Account.Address)
suite.Require().NotEqual(uint64(0), connectedIntermediaryAccountRes.Account.GaugeId)

}
connectedIntermediaryAccountRes, err := suite.queryClient.ConnectedIntermediaryAccount(sdk.WrapSDKContext(suite.Ctx), &types.ConnectedIntermediaryAccountRequest{LockId: 123})
suite.Require().NoError(err)
suite.Require().Equal("", connectedIntermediaryAccountRes.Account.Denom)
suite.Require().Equal("", connectedIntermediaryAccountRes.Account.ValAddr)
suite.Require().Equal(uint64(0), connectedIntermediaryAccountRes.Account.GaugeId)
>>>>>>> 052bc20 (Superfluid Misc: Improve grpc_query (#1084))
}

func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegationsDontIncludeUnbonding() {
Expand Down Expand Up @@ -177,4 +197,8 @@ func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegationsDontIncludeUnbon
})
suite.Require().NoError(err)
suite.Require().Len(delegationsRes.SuperfluidDelegationRecords, 1)

totalSuperfluidDelegationsRes, err := suite.queryClient.TotalSuperfluidDelegations(sdk.WrapSDKContext(suite.Ctx), &types.TotalSuperfluidDelegationsRequest{})
suite.Require().NoError(err)
suite.Require().Equal(totalSuperfluidDelegationsRes.TotalDelegations, sdk.NewInt(30000000))
}

0 comments on commit 526ec93

Please sign in to comment.