Skip to content

Commit

Permalink
start working on tests, prove GetCapability bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed Apr 1, 2020
1 parent 56a4c9c commit b282f99
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 34 deletions.
7 changes: 7 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ type SimApp struct {
EvidenceKeeper evidence.Keeper
TransferKeeper transfer.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capability.ScopedKeeper
ScopedTransferKeeper capability.ScopedKeeper

// the module manager
mm *module.Manager

Expand Down Expand Up @@ -342,6 +346,9 @@ func NewSimApp(
ctx := app.BaseApp.NewContext(true, abci.Header{})
app.CapabilityKeeper.InitializeAndSeal(ctx)

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper

return app
}

Expand Down
5 changes: 5 additions & 0 deletions x/capability/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (suite *KeeperTestSuite) TestNewCapability() {
got, ok := sk.GetCapability(suite.ctx, "transfer")
suite.Require().True(ok)
suite.Require().Equal(cap, got)
suite.Require().True(cap == got, "pointers not equal")

got, ok = sk.GetCapability(suite.ctx, "invalid")
suite.Require().False(ok)
Expand All @@ -107,7 +108,11 @@ func (suite *KeeperTestSuite) TestAuthenticateCapability() {
suite.Require().NoError(err)
suite.Require().NotNil(cap2)

got, ok := sk1.GetCapability(suite.ctx, "transfer")
suite.Require().True(ok)

suite.Require().True(sk1.AuthenticateCapability(suite.ctx, cap1, "transfer"))
suite.Require().True(sk1.AuthenticateCapability(suite.ctx, got, "transfer"))
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, cap1, "invalid"))
suite.Require().False(sk1.AuthenticateCapability(suite.ctx, cap2, "transfer"))

Expand Down
4 changes: 4 additions & 0 deletions x/ibc/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/capability"
Expand Down Expand Up @@ -59,6 +61,7 @@ func (k Keeper) ChanOpenInit(
)
}

fmt.Println(portID)
if !k.portKeeper.Authenticate(ctx, portCap, portID) {
return nil, sdkerrors.Wrap(porttypes.ErrInvalidPort, "caller does not own port capability")
}
Expand All @@ -67,6 +70,7 @@ func (k Keeper) ChanOpenInit(
k.SetChannel(ctx, portID, channelID, channel)

capKey, err := k.scopedKeeper.NewCapability(ctx, ibctypes.ChannelCapabilityPath(portID, channelID))
fmt.Println("In chan init", capKey.String())
if err != nil {
return nil, sdkerrors.Wrap(types.ErrInvalidChannelCapability, err.Error())
}
Expand Down
Loading

0 comments on commit b282f99

Please sign in to comment.