Skip to content

Commit

Permalink
feat: update protos, grpc queries (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
charleenfei authored Nov 10, 2021
1 parent 67bd594 commit 405f193
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 2,159 deletions.
102 changes: 31 additions & 71 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@
- [GenesisState](#ibc.applications.fee.v1.GenesisState)

- [ibc/applications/fee/v1/query.proto](#ibc/applications/fee/v1/query.proto)
- [QueryAckFeeRequest](#ibc.applications.fee.v1.QueryAckFeeRequest)
- [QueryAckFeeResponse](#ibc.applications.fee.v1.QueryAckFeeResponse)
- [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest)
- [QueryIncentivizedPacketResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketResponse)
- [QueryIncentivizedPacketsRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketsRequest)
- [QueryIncentivizedPacketsResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketsResponse)
- [QueryReceiveFeeRequest](#ibc.applications.fee.v1.QueryReceiveFeeRequest)
- [QueryReceiveFeeResponse](#ibc.applications.fee.v1.QueryReceiveFeeResponse)
- [QueryTimeoutFeeRequest](#ibc.applications.fee.v1.QueryTimeoutFeeRequest)
- [QueryTimeoutFeeResponse](#ibc.applications.fee.v1.QueryTimeoutFeeResponse)

- [Query](#ibc.applications.fee.v1.Query)

Expand Down Expand Up @@ -698,38 +692,6 @@ GenesisState defines the fee middleware genesis state



<a name="ibc.applications.fee.v1.QueryAckFeeRequest"></a>

### QueryAckFeeRequest
QueryAckFeeRequest is the request type for querying the acknowledgement fee


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | PacketID |
| `relayer_address` | [string](#string) | | Caller should provide the intended relayer address in case the fee is dependent on specific relayer(s). |
| `query_height` | [uint64](#uint64) | | Height to query at |






<a name="ibc.applications.fee.v1.QueryAckFeeResponse"></a>

### QueryAckFeeResponse
QueryAckFeeResponse is the response type for the AckFee RPC


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |






<a name="ibc.applications.fee.v1.QueryIncentivizedPacketRequest"></a>

### QueryIncentivizedPacketRequest
Expand Down Expand Up @@ -791,75 +753,73 @@ QueryIncentivizedPacketsResponse is the response type for the incentivized packe



<!-- end messages -->

<a name="ibc.applications.fee.v1.QueryReceiveFeeRequest"></a>

### QueryReceiveFeeRequest
QueryReceiveFeeRequest is the request type for querying the receive fee


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | PacketID |
| `relayer_address` | [string](#string) | | Caller should provide the intended relayer address in case the fee is dependent on specific relayer(s). |
| `query_height` | [uint64](#uint64) | | Height to query at |


<!-- end enums -->

<!-- end HasExtensions -->


<a name="ibc.applications.fee.v1.Query"></a>

<a name="ibc.applications.fee.v1.QueryReceiveFeeResponse"></a>
### Query
Query provides defines the gRPC querier service.

### QueryReceiveFeeResponse
QueryReceiveFeeResponse is the response type for the ReceiveFee RPC
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `IncentivizedPackets` | [QueryIncentivizedPacketsRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketsRequest) | [QueryIncentivizedPacketsResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketsResponse) | Gets all incentivized packets | GET|/ibc/apps/fee/v1/incentivized_packets|
| `IncentivizedPacket` | [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest) | [QueryIncentivizedPacketResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketResponse) | Gets the fees expected for submitting the ReceivePacket, AcknowledgementPacket, and TimeoutPacket messages for the given packet | GET|/ibc/apps/fee/v1/incentivized_packet/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|

<!-- end services -->

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |


<a name="ibc/applications/fee/v1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## ibc/applications/fee/v1/tx.proto



<a name="ibc.applications.fee.v1.QueryTimeoutFeeRequest"></a>
<a name="ibc.applications.fee.v1.MsgPayPacketFee"></a>

### QueryTimeoutFeeRequest
QueryTimeoutFeeRequest is the request type for querying the timeout fee
### MsgPayPacketFee
MsgPayPacketFee defines the request type EscrowPacketFee RPC
This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be
paid for


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | PacketID |
| `relayer_address` | [string](#string) | | Caller should provide the intended relayer address in case the fee is dependent on specific relayer(s). |
| `query_height` | [uint64](#uint64) | | Height to query at |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `source_port_id` | [string](#string) | | source channel port identifier |
| `source_channel_id` | [string](#string) | | source channel unique identifier |
| `signer` | [string](#string) | | account address to refund fee if necessary |
| `relayers` | [string](#string) | repeated | |






<a name="ibc.applications.fee.v1.QueryTimeoutFeeResponse"></a>
<a name="ibc.applications.fee.v1.MsgPayPacketFeeAsync"></a>

### QueryTimeoutFeeResponse
QueryTimeoutFeeResponse is the response type for the timeout RPC
### MsgPayPacketFeeAsync
MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC
This Msg can be used to pay for a packet at a specified sequence (instead of the next sequence send)


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `identified_packet_fee` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | packet to pay fee for |
| `signer` | [string](#string) | | account address to refund fee if necessary |





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->
<a name="ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse"></a>


<a name="ibc.applications.fee.v1.Query"></a>
Expand Down
64 changes: 62 additions & 2 deletions modules/apps/29-fee/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
package keeper

// TODO
import (
"context"

//var _ types.QueryServer = Keeper{}
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"

"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
)

var _ types.QueryServer = Keeper{}

// IncentivizedPackets implements the IncentivizedPackets gRPC method
func (k Keeper) IncentivizedPackets(c context.Context, req *types.QueryIncentivizedPacketsRequest) (*types.QueryIncentivizedPacketsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c).WithBlockHeight(int64(req.QueryHeight))

var packets []*types.IdentifiedPacketFee
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.FeeInEscrowPrefix))
_, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {
result := k.MustUnmarshalFee(value)
packets = append(packets, &result)
return nil
})

if err != nil {
return nil, status.Error(
codes.NotFound, err.Error(),
)
}

return &types.QueryIncentivizedPacketsResponse{
IncentivizedPackets: packets,
}, nil
}

// IncentivizedPacket implements the IncentivizedPacket gRPC method
func (k Keeper) IncentivizedPacket(c context.Context, req *types.QueryIncentivizedPacketRequest) (*types.QueryIncentivizedPacketResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(c).WithBlockHeight(int64(req.QueryHeight))

fee, exists := k.GetFeeInEscrow(ctx, req.PacketId)
if !exists {
return nil, status.Error(
codes.NotFound,
sdkerrors.Wrap(types.ErrFeeNotFound, req.PacketId.String()).Error(),
)
}

return &types.QueryIncentivizedPacketResponse{
IncentivizedPacket: &fee,
}, nil
}
151 changes: 151 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package keeper_test

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"

"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
ibctesting "github.com/cosmos/ibc-go/testing"
)

func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() {

var (
req *types.QueryIncentivizedPacketRequest
)

// setup
validPacketId := types.NewPacketId(ibctesting.FirstChannelID, 1)
invalidPacketId := types.NewPacketId(ibctesting.FirstChannelID, 2)
identifiedPacketFee := types.NewIdentifiedPacketFee(
validPacketId,
types.Fee{
AckFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))),
ReceiveFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))),
TimeoutFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))),
},
[]string(nil),
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success",
func() {
req = &types.QueryIncentivizedPacketRequest{
PacketId: validPacketId,
QueryHeight: 0,
}
},
true,
},
{
"packetId not found",
func() {
req = &types.QueryIncentivizedPacketRequest{
PacketId: invalidPacketId,
QueryHeight: 0,
}
},
false,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

refundAcc := suite.chainA.SenderAccount.GetAddress()

tc.malleate()
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee)
res, err := suite.queryClient.IncentivizedPacket(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(identifiedPacketFee, res.IncentivizedPacket)
} else {
suite.Require().Error(err)
}
})
}
}

func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() {
var (
req *types.QueryIncentivizedPacketsRequest
expPackets []*types.IdentifiedPacketFee
)

fee := types.Fee{
AckFee: sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}},
ReceiveFee: sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}},
TimeoutFee: sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}},
}

testCases := []struct {
msg string
malleate func()
expPass bool
}{
{
"empty pagination",
func() {
req = &types.QueryIncentivizedPacketsRequest{}
},
true,
},
{
"success",
func() {
refundAcc := suite.chainA.SenderAccount.GetAddress()

fee1 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 1), fee, []string(nil))
fee2 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 2), fee, []string(nil))
fee3 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 3), fee, []string(nil))

expPackets = []*types.IdentifiedPacketFee{}
expPackets = append(expPackets, fee1, fee2, fee3)

for _, p := range expPackets {
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, p)
}

req = &types.QueryIncentivizedPacketsRequest{
Pagination: &query.PageRequest{
Limit: 5,
CountTotal: false,
},
QueryHeight: 0,
}
},
true,
},
}

for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset
tc.malleate()
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())

res, err := suite.queryClient.IncentivizedPackets(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
fmt.Println(expPackets)
suite.Require().Equal(expPackets, res.IncentivizedPackets)
} else {
suite.Require().Error(err)
}
})
}
}
Loading

0 comments on commit 405f193

Please sign in to comment.