-
Notifications
You must be signed in to change notification settings - Fork 580
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
Remove usage of globals from 08-wasm #6103
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6dc7fa9
Move functionality from client state methods to light client module m…
DimitrisJim 8ec8bf6
Remove global VM, introspection to retrieve client identifier.
DimitrisJim c3ddc51
Move migrateContract from clientState to keeper method.
DimitrisJim 6e9d4a6
Move state management to keeper.
DimitrisJim 5cc45a4
Make InitializePinnedCodes a method on the keeper.
DimitrisJim 139c806
Remove pending todo in test for migrate contract.
DimitrisJim f3a7aae
Move vm entrypoint functions in keeper/ package.
DimitrisJim 6f5616a
feat: move vm entry points to keeper.
DimitrisJim 7373de0
chore: simplify signatures.
DimitrisJim 1692f8b
test: add amended tests for contact keeper.
DimitrisJim 5127126
refactor: move querier to keeper package.
DimitrisJim 57c2235
lint: you'll never fix me.
DimitrisJim 12c34cb
refactor: remove queryRouter global variable
DimitrisJim 151a546
refactor: remove global for query plugins.
DimitrisJim f679ccf
nit: rename to queryPlugins.
DimitrisJim e726ce9
refactor: remove QueryPluginsI interface.
DimitrisJim 480fcf8
refactor: make queryHandler a private type.
DimitrisJim d614a93
Make migrateContractCode a private function, clean up uneeded export …
DimitrisJim 8e6b567
refactor: Move vm entrypoints to keeper.
DimitrisJim 2aea36f
chore: address some testing todos. Move testing unmarshal failure cas…
DimitrisJim 23decca
chore: additional tiny nits.
DimitrisJim f23bc7c
chore: restructure definitions to make diff more readable.
DimitrisJim 2836073
d'oh: rm vm arg from instantiate.
DimitrisJim 76d8055
nit: Space out keeper fields. Remove TODO for method name.
DimitrisJim 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 was deleted.
Oops, something went wrong.
160 changes: 68 additions & 92 deletions
160
modules/light-clients/08-wasm/types/vm.go → ...clients/08-wasm/keeper/contract_keeper.go
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package types_test | ||
package keeper_test | ||
|
||
import ( | ||
"encoding/json" | ||
|
@@ -15,7 +15,7 @@ import ( | |
localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost" | ||
) | ||
|
||
func (suite *TypesTestSuite) TestWasmInstantiate() { | ||
func (suite *KeeperTestSuite) TestWasmInstantiate() { | ||
testCases := []struct { | ||
name string | ||
malleate func() | ||
|
@@ -165,17 +165,19 @@ func (suite *TypesTestSuite) TestWasmInstantiate() { | |
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupWasmWithMockVM() | ||
checksum := storeWasmCode(suite, wasmtesting.Code) | ||
|
||
DimitrisJim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tc.malleate() | ||
|
||
initMsg := types.InstantiateMessage{ | ||
ClientState: clienttypes.MustMarshalClientState(suite.chainA.App.AppCodec(), wasmtesting.MockTendermitClientState), | ||
ConsensusState: clienttypes.MustMarshalConsensusState(suite.chainA.App.AppCodec(), wasmtesting.MockTendermintClientConsensusState), | ||
Checksum: suite.checksum, | ||
Checksum: checksum, | ||
} | ||
|
||
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) | ||
err := types.WasmInstantiate(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, &types.ClientState{Checksum: suite.checksum}, initMsg) | ||
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper | ||
err := wasmClientKeeper.WasmInstantiate(suite.chainA.GetContext(), defaultWasmClientID, clientStore, &types.ClientState{Checksum: checksum}, initMsg) | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
|
@@ -187,7 +189,7 @@ func (suite *TypesTestSuite) TestWasmInstantiate() { | |
} | ||
} | ||
|
||
func (suite *TypesTestSuite) TestWasmMigrate() { | ||
func (suite *KeeperTestSuite) TestWasmMigrate() { | ||
testCases := []struct { | ||
name string | ||
malleate func() | ||
|
@@ -305,6 +307,7 @@ func (suite *TypesTestSuite) TestWasmMigrate() { | |
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupWasmWithMockVM() | ||
_ = storeWasmCode(suite, wasmtesting.Code) | ||
|
||
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. many of the type tests were written to assume a checksum exists in state, keeper tests don't. This should require some refactoring at some point. |
||
endpoint := wasmtesting.NewWasmEndpoint(suite.chainA) | ||
err := endpoint.CreateClient() | ||
|
@@ -313,7 +316,8 @@ func (suite *TypesTestSuite) TestWasmMigrate() { | |
tc.malleate() | ||
|
||
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), defaultWasmClientID) | ||
err = types.WasmMigrate(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, &types.ClientState{}, defaultWasmClientID, []byte("{}")) | ||
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper | ||
err = wasmClientKeeper.WasmMigrate(suite.chainA.GetContext(), clientStore, &types.ClientState{}, defaultWasmClientID, []byte("{}")) | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
|
@@ -325,7 +329,7 @@ func (suite *TypesTestSuite) TestWasmMigrate() { | |
} | ||
} | ||
|
||
func (suite *TypesTestSuite) TestWasmQuery() { | ||
func (suite *KeeperTestSuite) TestWasmQuery() { | ||
var payload types.QueryMsg | ||
|
||
testCases := []struct { | ||
|
@@ -368,21 +372,13 @@ func (suite *TypesTestSuite) TestWasmQuery() { | |
}, | ||
types.ErrWasmContractCallFailed, | ||
}, | ||
{ | ||
"failure: response fails to unmarshal", | ||
func() { | ||
DimitrisJim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
suite.mockVM.RegisterQueryCallback(types.StatusMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) { | ||
return &wasmvmtypes.QueryResult{Ok: []byte("invalid json")}, wasmtesting.DefaultGasUsed, nil | ||
}) | ||
}, | ||
types.ErrWasmInvalidResponseData, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupWasmWithMockVM() | ||
_ = storeWasmCode(suite, wasmtesting.Code) | ||
|
||
endpoint := wasmtesting.NewWasmEndpoint(suite.chainA) | ||
err := endpoint.CreateClient() | ||
|
@@ -398,7 +394,8 @@ func (suite *TypesTestSuite) TestWasmQuery() { | |
|
||
tc.malleate() | ||
|
||
res, err := types.WasmQuery[types.StatusResult](suite.chainA.GetContext(), clientStore, wasmClientState, payload) | ||
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper | ||
res, err := wasmClientKeeper.WasmQuery(suite.chainA.GetContext(), endpoint.ClientID, clientStore, wasmClientState, payload) | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
|
@@ -411,7 +408,7 @@ func (suite *TypesTestSuite) TestWasmQuery() { | |
} | ||
} | ||
|
||
func (suite *TypesTestSuite) TestWasmSudo() { | ||
func (suite *KeeperTestSuite) TestWasmSudo() { | ||
var payload types.SudoMsg | ||
|
||
testCases := []struct { | ||
|
@@ -487,15 +484,6 @@ func (suite *TypesTestSuite) TestWasmSudo() { | |
}, | ||
types.ErrWasmAttributesNotAllowed, | ||
}, | ||
{ | ||
"failure: response fails to unmarshal", | ||
func() { | ||
suite.mockVM.RegisterSudoCallback(types.UpdateStateMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, _ wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.ContractResult, uint64, error) { | ||
return &wasmvmtypes.ContractResult{Ok: &wasmvmtypes.Response{Data: []byte("invalid json")}}, wasmtesting.DefaultGasUsed, nil | ||
}) | ||
}, | ||
types.ErrWasmInvalidResponseData, | ||
}, | ||
{ | ||
"failure: invalid clientstate type", | ||
func() { | ||
|
@@ -561,6 +549,7 @@ func (suite *TypesTestSuite) TestWasmSudo() { | |
tc := tc | ||
suite.Run(tc.name, func() { | ||
suite.SetupWasmWithMockVM() | ||
_ = storeWasmCode(suite, wasmtesting.Code) | ||
|
||
endpoint := wasmtesting.NewWasmEndpoint(suite.chainA) | ||
err := endpoint.CreateClient() | ||
|
@@ -576,7 +565,8 @@ func (suite *TypesTestSuite) TestWasmSudo() { | |
|
||
tc.malleate() | ||
|
||
res, err := types.WasmSudo[types.UpdateStateResult](suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, wasmClientState, payload) | ||
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper | ||
res, err := wasmClientKeeper.WasmSudo(suite.chainA.GetContext(), endpoint.ClientID, clientStore, wasmClientState, payload) | ||
|
||
expPass := tc.expError == nil | ||
if expPass { | ||
|
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package keeper | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
// MigrateContractCode is a wrapper around k.migrateContractCode to allow the method to be directly called in tests. | ||
func (k Keeper) MigrateContractCode(ctx sdk.Context, clientID string, newChecksum, migrateMsg []byte) error { | ||
return k.migrateContractCode(ctx, clientID, newChecksum, migrateMsg) | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
This interface isn't needed anymore? what was it being used for previously?
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.
#5345 (comment)
The main problem previously was the
Set/Get
for query plugins being globally accessible throughtypes
. Currently these are moved (and exported) on Keeper which in cosmos-sdk context would require someone explicitly hold a ref to keeper to modify, hence, not as unexpected (was my thinking).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.
oh, think I could make them private though! I'll do a follow up here too.
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.
in general my plan was do refactor -> merge, move as much as possible into internal/make symbols private.