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
  • Loading branch information
mattverse authored Mar 14, 2022
1 parent a454116 commit 052bc20
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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
20 changes: 19 additions & 1 deletion x/superfluid/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegations() {
}

// setup superfluid delegations
suite.SetupSuperfluidDelegations(delAddrs, valAddrs, superfluidDelegations, denoms)
_, locks := suite.SetupSuperfluidDelegations(delAddrs, valAddrs, superfluidDelegations, denoms)

// for each superfluid delegation, query the amount and make sure it is 1000000
for _, delegation := range superfluidDelegations {
Expand Down Expand Up @@ -108,6 +108,20 @@ func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegations() {
totalSuperfluidDelegationsRes, err := suite.queryClient.TotalSuperfluidDelegations(sdk.WrapSDKContext(suite.Ctx), &types.TotalSuperfluidDelegationsRequest{})
suite.Require().NoError(err)
suite.Require().Equal(sdk.NewInt(40000000), totalSuperfluidDelegationsRes.TotalDelegations)

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)
}

func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegationsDontIncludeUnbonding() {
Expand Down Expand Up @@ -171,4 +185,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 052bc20

Please sign in to comment.