Skip to content

Commit

Permalink
fix: correctly claim capability for mock module, handle genesis expor…
Browse files Browse the repository at this point in the history
…ts (#921) (#922)

## Description

This contains two fixes:
- the capability being claimed by the scoped keeper was incorrect (mock.ModuleName -> port ID)
- the mock module wasn't accounting for non empty genesis state in capabilities (after genesis export, capability will create the bound ports so rebinding doesn't need to happen)

closes: #XXXX

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing)
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [ ] Re-reviewed `Files changed` in the Github PR explorer
- [ ] Review `Codecov Report` in the comment section below once CI passes

(cherry picked from commit afa2d90)

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
mergify[bot] and colin-axner authored Feb 15, 2022
1 parent 96ca59b commit f418799
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions testing/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var _ porttypes.IBCModule = IBCModule{}
// PortKeeper defines the expected IBC port keeper
type PortKeeper interface {
BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
IsBound(ctx sdk.Context, portID string) bool
}

// AppModuleBasic is the mock AppModuleBasic.
Expand Down Expand Up @@ -123,10 +124,10 @@ func (am AppModule) RegisterServices(module.Configurator) {}
// InitGenesis implements the AppModule interface.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
for _, ibcApp := range am.ibcApps {
if ibcApp.PortID != "" {
if ibcApp.PortID != "" && !am.portKeeper.IsBound(ctx, ibcApp.PortID) {
// bind mock portID
cap := am.portKeeper.BindPort(ctx, ibcApp.PortID)
ibcApp.ScopedKeeper.ClaimCapability(ctx, cap, host.PortPath(ModuleName))
ibcApp.ScopedKeeper.ClaimCapability(ctx, cap, host.PortPath(ibcApp.PortID))
}
}

Expand Down

0 comments on commit f418799

Please sign in to comment.