-
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
refactor: allow the mock module to be used multiple times as base ibc application in middleware stack #892
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
70e6a3a
refactor: allow the mock module to be used multiple times as base ibc…
colin-axner ba3d43d
add changelog entry
colin-axner 174057e
update testing docs
colin-axner a78bc3f
chore: add and use 'NewMockIBCApp'
colin-axner aeb3d61
Merge branch 'main' into colin/ibcmock-improvements
colin-axner f330f34
Update CHANGELOG.md
colin-axner 0b3d732
fix merge conflicts
colin-axner 5c38780
fix merge conflicts
colin-axner 662b5e7
Update CHANGELOG.md
colin-axner 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 |
---|---|---|
|
@@ -8,7 +8,6 @@ import ( | |
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" | ||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
"github.com/gorilla/mux" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
|
@@ -89,15 +88,14 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { | |
// AppModule represents the AppModule for the mock module. | ||
type AppModule struct { | ||
AppModuleBasic | ||
scopedKeeper capabilitykeeper.ScopedKeeper | ||
portKeeper PortKeeper | ||
ibcApps []*MockIBCApp | ||
portKeeper PortKeeper | ||
} | ||
|
||
// NewAppModule returns a mock AppModule instance. | ||
func NewAppModule(sk capabilitykeeper.ScopedKeeper, pk PortKeeper) AppModule { | ||
func NewAppModule(pk PortKeeper) AppModule { | ||
return AppModule{ | ||
scopedKeeper: sk, | ||
portKeeper: pk, | ||
portKeeper: pk, | ||
} | ||
} | ||
|
||
|
@@ -124,9 +122,13 @@ 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 { | ||
// bind mock port ID | ||
cap := am.portKeeper.BindPort(ctx, ModuleName) | ||
am.scopedKeeper.ClaimCapability(ctx, cap, host.PortPath(ModuleName)) | ||
for _, ibcApp := range am.ibcApps { | ||
if ibcApp.PortID != "" { | ||
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. some apps like ica auth modules don't bind/claim ports |
||
// bind mock portID | ||
cap := am.portKeeper.BindPort(ctx, ibcApp.PortID) | ||
ibcApp.ScopedKeeper.ClaimCapability(ctx, cap, host.PortPath(ModuleName)) | ||
} | ||
} | ||
|
||
return []abci.ValidatorUpdate{} | ||
} | ||
|
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
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.
So this is so that one
AppModule
can be shared between multipleMockIBCApps
?I find it slightly confusing how
IBCModule
contains a reference to itsMockIBCApp
but also a reference toAppModule
which contains references to all otherMockIBCApps
.Is there a way it could be structured so that you could call
NewAppModule
per mock application? I guess different args would need to be supplied if that was done and maybe complicate things further. Perhaps I'm overthinking things a bit, I'm just thinking out loud here really for what may be the easiest to follow option.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.
No this was the purpose of splitting out the IBC callbacks. SDK doesn't allow you to register the same AppModule twice. The alternative approaches:
NewAppModule
I felt the dev UX improvements were worth the under the hood magic (hence why those variables are private). I'm happy to change the API if we feel it is better for the ibc apps to be passed in at
NewAppModule
instantiationThere 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.
Ah yes, that slipped my mind from before! Got a little lost in the weeds thinking of alternatives. Makes sense along with the context from your other comment too, thanks a lot for the thorough explanation! I agree, since this is kind of hidden away anyway, its totally worth it for the testability of middleware..etc