-
Notifications
You must be signed in to change notification settings - Fork 625
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: adding interchain accounts grpc query tests #368
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/27-interchain-accounts/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestQueryInterchainAccountAddress() { | ||
var ( | ||
req *types.QueryInterchainAccountAddressRequest | ||
expAddr string | ||
) | ||
|
||
testCases := []struct { | ||
msg string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"empty request", | ||
func() { | ||
req = &types.QueryInterchainAccountAddressRequest{} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid counterparty portID", | ||
func() { | ||
req = &types.QueryInterchainAccountAddressRequest{ | ||
CounterpartyPortId: "", | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"interchain account address not found", | ||
func() { | ||
req = &types.QueryInterchainAccountAddressRequest{ | ||
CounterpartyPortId: "ics-27", | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"success", | ||
func() { | ||
expAddr = authtypes.NewBaseAccountWithAddress(types.GenerateAddress("ics-27")).GetAddress().String() | ||
req = &types.QueryInterchainAccountAddressRequest{ | ||
CounterpartyPortId: "ics-27", | ||
} | ||
|
||
suite.chainA.GetSimApp().ICAKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), "ics-27", expAddr) | ||
}, | ||
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.InterchainAccountAddress(ctx, req) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
suite.Require().NotNil(res) | ||
suite.Require().Equal(expAddr, res.GetInterchainAccountAddress()) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package keeper_test | |
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/stretchr/testify/suite" | ||
|
||
|
@@ -20,13 +21,19 @@ type KeeperTestSuite struct { | |
chainA *ibctesting.TestChain | ||
chainB *ibctesting.TestChain | ||
chainC *ibctesting.TestChain | ||
|
||
queryClient types.QueryClient | ||
} | ||
|
||
func (suite *KeeperTestSuite) SetupTest() { | ||
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 3) | ||
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) | ||
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) | ||
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2)) | ||
|
||
queryHelper := baseapp.NewQueryServerTestHelper(suite.chainA.GetContext(), suite.chainA.GetSimApp().InterfaceRegistry()) | ||
types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().ICAKeeper) | ||
suite.queryClient = types.NewQueryClient(queryHelper) | ||
Comment on lines
+34
to
+36
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. This looks like the legacy grpc testing, you should be able to use the query server without adding a field, see #143 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. Ah, nice! I had just referenced what had been done in Will include with other changes in a follow up PR. 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. I took a look at this. For The other option which removes the
What do you think? 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. Let's do the second option you outlined since the QueryServer is just the keeper anyways 👍 |
||
} | ||
|
||
func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { | ||
|
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.
This testcase is essentially redundant but also causes no harm as
req
is the same as below in "invalid counterparty portID" due to protobuf defaulting to empty string.Using
req = nil
here causes apanic: invalid memory address or nil pointer dereference
as protobuf attempts to marshal the nil request.Can be removed if anyone feels it should. Thoughts?
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 think it's fine to leave in.
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.
Might be good to update invalid counterparty portID to be empty with spaces (
" "
) and addstrings.TrimSpace
to the grpc.go code?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.
Agree with this, I think it's a good call. Can handle this in a PR tomorrow