-
Notifications
You must be signed in to change notification settings - Fork 586
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
deps: upgrade capability to sdk v0.50 and remove ibc-go dependency #4068
Conversation
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.
Added some context for review. More testcases could be cleaned up but I left as is to reduce diffs. The main one of concern was TestInitializeMemstore
which I've cleaned up
// InitGenesis must be called in order to set the intial index to 1. | ||
capability.InitGenesis(suite.ctx, *suite.keeper, *types.DefaultGenesis()) |
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.
InitGenesis
has to be called directly here in order to set the initial capability index to 1.
This used to be happening handled implicitly when testing with a simapp. This caught me off guard for a while as after removing simapp this test would fail below when trying to lookup the first capability after genesis is reinitialised.
The reasoning for this is that without setting the initial index to 1 - cap1
created on line 19 would be at index 0, and ExportGenesis
starts the loop index here at 1. So after exporting and then reinitialising the gen state we'd lose first capabiliity.
suite.keeper = keeper | ||
suite.cdc = cdc | ||
suite.module = capability.NewAppModule(cdc, *keeper, false) | ||
encodingCfg := moduletestutil.MakeTestEncodingConfig(capability.AppModuleBasic{}) |
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.
Pretty nice way to create a test encoding config 👍
func (suite *CapabilityTestSuite) NewTestContext() sdk.Context { | ||
db := dbm.NewMemDB() | ||
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) | ||
cms.MountStoreWithDB(suite.storeKey, storetypes.StoreTypeIAVL, db) | ||
cms.MountStoreWithDB(suite.memStoreKey, storetypes.StoreTypeMemory, db) | ||
cms.MountStoreWithDB(suite.mockMemStoreKey, storetypes.StoreTypeMemory, db) | ||
|
||
err := cms.LoadLatestVersion() | ||
suite.Require().NoError(err) | ||
|
||
return sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()) | ||
} |
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 has been adapted from here.
I'm unsure why the test helpers in the sdk do not support adding mem store keys, or even mounting multiple keys (I guess nobody has run into an issue with the current code yet).
I was going to make a PR to the sdk to add some extra support for this, but I felt it was cleaner and quicker to adapt it and maintain it here.
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.
Opened cosmos/cosmos-sdk#16998
} | ||
|
||
// The following test case mocks a specific bug discovered in https://github.com/cosmos/cosmos-sdk/issues/9800 | ||
// and ensures that the current code successfully fixes the issue. | ||
// This test emulates statesync by firstly populating persisted state by creating a new scoped keeper and capability. | ||
// In-memory storage is then discarded by creating a new capability keeper and app module using a mock memstore key. | ||
// BeginBlock is then called to populate the new in-memory store using the persisted state. | ||
func (suite *CapabilityTestSuite) TestInitializeMemStore() { |
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 spent a good bit of time trying to parse this testcase. So I've added a bunch of in-line comments as well as extra info to the godoc above. This was initially added by @AdityaSripal in cosmos/cosmos-sdk#9835 but has since seen a whole bunch of devs chopping into the code.
Hopefully its now clear what its doing and is easier to maintain.
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.
Thank you for this!
prevGas := ctx.GasMeter().GasConsumed() | ||
prevBlockGas := ctx.BlockGasMeter().GasConsumed() | ||
prevGas := ctx.BlockGasMeter().GasConsumed() |
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.
prevGas
here was incorrect, it was being set to the same value as prevBlockGas
Thank you so much for handling the upgrade of the capability module, @damiannolan. This PR will supersede #3978, right? So that one can be closed? |
Yep, indeed we can close #3978 |
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.
LGTM nice investigation ❤️
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.
Damn, excellent work! This is a pretty epic pr if I have ever seen one 🔥
} | ||
|
||
// The following test case mocks a specific bug discovered in https://github.com/cosmos/cosmos-sdk/issues/9800 | ||
// and ensures that the current code successfully fixes the issue. | ||
// This test emulates statesync by firstly populating persisted state by creating a new scoped keeper and capability. | ||
// In-memory storage is then discarded by creating a new capability keeper and app module using a mock memstore key. | ||
// BeginBlock is then called to populate the new in-memory store using the persisted state. | ||
func (suite *CapabilityTestSuite) TestInitializeMemStore() { |
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.
Thank you for this!
cc @faddat 👀 should be able to pick this up in #3883 using a edit: tagged @ |
…4068) * adding testing/simapp dir for testing purposes * upgrade to sdk v0.50.0-alpha.1 and rm dep on ibc-go simapp * refactor and improve capability tests to use test helpers in favour of simapp * rm simapp and go mod tidy * update godoc * assert the transfer capability does not exist until memstore is reinitialised (cherry picked from commit 49cdfc5) # Conflicts: # modules/capability/capability_test.go # modules/capability/genesis_test.go # modules/capability/go.mod # modules/capability/go.sum # modules/capability/module.go # modules/capability/simulation/decoder_test.go
…ackport #4068) (#4083) * deps: upgrade capability to sdk v0.50 and remove ibc-go dependency (#4068) * adding testing/simapp dir for testing purposes * upgrade to sdk v0.50.0-alpha.1 and rm dep on ibc-go simapp * refactor and improve capability tests to use test helpers in favour of simapp * rm simapp and go mod tidy * update godoc * assert the transfer capability does not exist until memstore is reinitialised (cherry picked from commit 49cdfc5) # Conflicts: # modules/capability/capability_test.go # modules/capability/genesis_test.go # modules/capability/go.mod # modules/capability/go.sum # modules/capability/module.go # modules/capability/simulation/decoder_test.go * addressing merge conflicts * pin goleveldb using replace * updating to go 1.20 in capability workflows * just use the workflow from main.. please work --------- Co-authored-by: Damian Nolan <damiannolan@gmail.com>
Description
This PR upgrades the capability module to sdk v0.50 eden release.
It removes the dependency on ibc-go
testing/simapp
and refactors the tests of interest to not depend on a simulation app.Instead it uses a test a context and in-memory db in order to accomplish the same level of testing provided by simapp.
Note, I have tried to clean up and add inline code comments to
capability_test.go
to make it easier to understand.closes: #4055
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.
docs/
) or specification (x/<module>/spec/
).godoc
comments.Files changed
in the Github PR explorer.Codecov Report
in the comment section below once CI passes.