-
Notifications
You must be signed in to change notification settings - Fork 624
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
chore: update grpc queries to handle multiple fees #967
Merged
damiannolan
merged 11 commits into
ics29-fee-middleware
from
damian/953-update-existing-queries
Feb 24, 2022
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
23940d4
adding new proto types and codegen
damiannolan 615200b
refactoring ics29 fees for more efficient storage
damiannolan c5178be
updating tests
damiannolan b658b0f
updating protos and existing queries
damiannolan d853b94
updating grpc queries and refactoring tests
damiannolan dda4039
format error correct in favour of proto string() method
damiannolan ea718bc
Merge branch 'ics29-fee-middleware' into damian/953-update-existing-q…
damiannolan b6c7fdf
Merge branch 'ics29-fee-middleware' into damian/953-update-existing-q…
damiannolan e1d02aa
Merge branch 'ics29-fee-middleware' into damian/953-update-existing-q…
damiannolan b4ac164
Merge branch 'ics29-fee-middleware' into damian/953-update-existing-q…
damiannolan 2418546
leveraging ParseKeyFeesInEscrow to obtain packet id in query
damiannolan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/query" | ||
|
||
|
@@ -11,25 +9,10 @@ import ( | |
ibctesting "github.com/cosmos/ibc-go/v3/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() { | ||
|
||
func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { | ||
var ( | ||
req *types.QueryIncentivizedPacketRequest | ||
) | ||
|
||
// setup | ||
suite.coordinator.Setup(suite.path) // setup channel | ||
validPacketId := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1) | ||
invalidPacketId := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 2) | ||
identifiedPacketFee := types.NewIdentifiedPacketFee( | ||
validPacketId, | ||
types.Fee{ | ||
AckFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), | ||
RecvFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), | ||
TimeoutFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), | ||
}, | ||
"", // leave empty here and then populate on each testcase since suite resets | ||
[]string(nil), | ||
req *types.QueryIncentivizedPacketsRequest | ||
expectedPackets []types.IdentifiedPacketFees | ||
) | ||
|
||
testCases := []struct { | ||
|
@@ -40,117 +23,116 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() { | |
{ | ||
"success", | ||
func() { | ||
req = &types.QueryIncentivizedPacketRequest{ | ||
PacketId: validPacketId, | ||
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) | ||
|
||
fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) | ||
packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) | ||
|
||
for i := 0; i < 3; i++ { | ||
// escrow packet fees for three different packets | ||
packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, uint64(i+1)) | ||
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) | ||
|
||
expectedPackets = append(expectedPackets, types.NewIdentifiedPacketFees(packetID, []types.PacketFee{packetFee})) | ||
} | ||
|
||
req = &types.QueryIncentivizedPacketsRequest{ | ||
Pagination: &query.PageRequest{ | ||
Limit: 5, | ||
CountTotal: false, | ||
}, | ||
QueryHeight: 0, | ||
} | ||
}, | ||
true, | ||
}, | ||
{ | ||
"packetId not found", | ||
"empty pagination", | ||
func() { | ||
req = &types.QueryIncentivizedPacketRequest{ | ||
PacketId: invalidPacketId, | ||
QueryHeight: 0, | ||
} | ||
expectedPackets = nil | ||
req = &types.QueryIncentivizedPacketsRequest{} | ||
}, | ||
false, | ||
true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() // reset | ||
|
||
refundAcc := suite.chainA.SenderAccount.GetAddress() | ||
// populate RefundAddress field | ||
identifiedPacketFee.RefundAddress = refundAcc.String() | ||
|
||
tc.malleate() | ||
|
||
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), validPacketId.PortId, validPacketId.ChannelId) | ||
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeInEscrow(suite.chainA.GetContext(), identifiedPacketFee) | ||
tc.malleate() // malleate mutates test data | ||
|
||
ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) | ||
res, err := suite.queryClient.IncentivizedPacket(ctx, req) | ||
res, err := suite.queryClient.IncentivizedPackets(ctx, req) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
suite.Require().NotNil(res) | ||
suite.Require().Equal(&identifiedPacketFee, res.IncentivizedPacket) | ||
suite.Require().Equal(expectedPackets, res.IncentivizedPackets) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() { | ||
func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() { | ||
var ( | ||
req *types.QueryIncentivizedPacketsRequest | ||
expPackets []*types.IdentifiedPacketFee | ||
req *types.QueryIncentivizedPacketRequest | ||
) | ||
|
||
fee := types.Fee{ | ||
AckFee: sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}}, | ||
RecvFee: 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 | ||
name string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"empty pagination", | ||
func() { | ||
req = &types.QueryIncentivizedPacketsRequest{} | ||
}, | ||
"success", | ||
func() {}, | ||
true, | ||
}, | ||
{ | ||
"success", | ||
"fees not found for packet id", | ||
func() { | ||
refundAcc := suite.chainA.SenderAccount.GetAddress() | ||
|
||
fee1 := types.NewIdentifiedPacketFee(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1), fee, refundAcc.String(), []string(nil)) | ||
fee2 := types.NewIdentifiedPacketFee(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 2), fee, refundAcc.String(), []string(nil)) | ||
fee3 := types.NewIdentifiedPacketFee(channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 3), fee, refundAcc.String(), []string(nil)) | ||
|
||
expPackets = []*types.IdentifiedPacketFee{} | ||
expPackets = append(expPackets, &fee1, &fee2, &fee3) | ||
|
||
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) | ||
for _, packetFee := range expPackets { | ||
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeInEscrow(suite.chainA.GetContext(), *packetFee) | ||
} | ||
|
||
req = &types.QueryIncentivizedPacketsRequest{ | ||
Pagination: &query.PageRequest{ | ||
Limit: 5, | ||
CountTotal: false, | ||
}, | ||
req = &types.QueryIncentivizedPacketRequest{ | ||
PacketId: channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100), | ||
QueryHeight: 0, | ||
} | ||
}, | ||
true, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() // reset | ||
tc.malleate() | ||
ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) | ||
|
||
res, err := suite.queryClient.IncentivizedPackets(ctx, req) | ||
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID) | ||
|
||
packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1) | ||
fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee) | ||
packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil)) | ||
|
||
for i := 0; i < 3; i++ { | ||
// escrow three packet fees for the same packet | ||
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee) | ||
suite.Require().NoError(err) | ||
} | ||
|
||
req = &types.QueryIncentivizedPacketRequest{ | ||
PacketId: packetID, | ||
QueryHeight: 0, | ||
Comment on lines
+110
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha I just thought to do the same on #983 |
||
} | ||
|
||
tc.malleate() // malleate mutates test data | ||
|
||
ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) | ||
res, err := suite.queryClient.IncentivizedPacket(ctx, req) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
suite.Require().NotNil(res) | ||
suite.Require().Equal(expPackets, res.IncentivizedPackets) | ||
suite.Require().Equal(types.NewIdentifiedPacketFees(packetID, []types.PacketFee{packetFee, packetFee, packetFee}), res.IncentivizedPacket) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? From my investigation, pagination doesn't include the prefix iterated on in the return value. I guess there's a trailing "/" leading the key, which is subtle
So I think the key is something like "/transfer/channel-0/5"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kinda wondering if we should just reconstruct the full key and then use the parse functions in keys.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, correct, so a paginated query doesn't include the prefix, but because of the leading
"/"
when we split using the slash separator the first element is an empty string. So with your example,keySplit
ends up as a 4 element slice:[]string{"", "transfer", "channel-0", "5"}
.I do think since you've added the parse function we should try to leverage it here. It should be something like below, right?
edit: Done ✅