Skip to content

Commit

Permalink
Merge branch 'main' into upgrade_linter
Browse files Browse the repository at this point in the history
  • Loading branch information
bznein authored Apr 16, 2024
2 parents e04c77b + 8af554c commit 4a9abfc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ lint-fix:
@echo "--> Running linter"
@./scripts/go-lint-all.sh --fix

#? format: Run gofumpt and mispell
#? format: Run gofumpt and misspell
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs gofumpt -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs misspell -w
Expand Down
7 changes: 7 additions & 0 deletions modules/light-clients/08-wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (k Keeper) newQueryHandler(ctx sdk.Context, callerID string) *queryHandler
return newQueryHandler(ctx, k.GetQueryPlugins(), callerID)
}

// storeWasmCode stores the contract to the VM, pins the checksum in the VM's in memory cache and stores the checksum
// in the 08-wasm store. The checksum identifying it is returned if successful. The following checks are made to the
// contract code before storing:
// - Size bounds are checked. Contract length must not be 0 or exceed a specific size (maxWasmSize).
// - The contract must not have already been stored in store.
func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wasmvm.WasmCode, gasLimit uint64) (wasmvm.Checksum, uint64, error)) ([]byte, error) {
var err error
if types.IsGzip(code) {
Expand Down Expand Up @@ -134,6 +139,8 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wa
return checksum, nil
}

// migrateContractCode migrates the contract for a given light client to one denoted by the given new checksum. The checksum we
// are migrating to must first be stored using storeWasmCode and must not match the checksum currently stored for this light client.
func (k Keeper) migrateContractCode(ctx sdk.Context, clientID string, newChecksum, migrateMsg []byte) error {
wasmClientState, err := k.GetWasmClientState(ctx, clientID)
if err != nil {
Expand Down
28 changes: 14 additions & 14 deletions modules/light-clients/08-wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ func mockCustomQuerier() func(sdk.Context, json.RawMessage) ([]byte, error) {
func (suite *KeeperTestSuite) TestCustomQuery() {
testCases := []struct {
name string
malleate func(k *keeper.Keeper)
malleate func()
expError error
}{
{
"success: custom query",
func(k *keeper.Keeper) {
func() {
querierPlugin := keeper.QueryPlugins{
Custom: mockCustomQuerier(),
}

k.SetQueryPlugins(querierPlugin)
GetSimApp(suite.chainA).WasmClientKeeper.SetQueryPlugins(querierPlugin)
suite.mockVM.RegisterQueryCallback(types.StatusMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) {
echo := CustomQuery{
Echo: &QueryEcho{
Expand Down Expand Up @@ -87,7 +87,7 @@ func (suite *KeeperTestSuite) TestCustomQuery() {
},
{
"failure: default query",
func(k *keeper.Keeper) {
func() {
suite.mockVM.RegisterQueryCallback(types.StatusMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) {
resp, err := querier.Query(wasmvmtypes.QueryRequest{Custom: json.RawMessage("{}")}, math.MaxUint64)
suite.Require().ErrorIs(err, wasmvmtypes.UnsupportedRequest{Kind: "Custom queries are not allowed"})
Expand All @@ -109,9 +109,9 @@ func (suite *KeeperTestSuite) TestCustomQuery() {
err := endpoint.CreateClient()
suite.Require().NoError(err)

wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper
tc.malleate()

tc.malleate(&wasmClientKeeper)
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper

clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID)
clientState, ok := endpoint.GetClientState().(*types.ClientState)
Expand Down Expand Up @@ -148,17 +148,17 @@ func (suite *KeeperTestSuite) TestStargateQuery() {

testCases := []struct {
name string
malleate func(k *keeper.Keeper)
malleate func()
expError error
}{
{
"success: custom query",
func(k *keeper.Keeper) {
func() {
querierPlugin := keeper.QueryPlugins{
Stargate: keeper.AcceptListStargateQuerier([]string{typeURL}, GetSimApp(suite.chainA).GRPCQueryRouter()),
}

k.SetQueryPlugins(querierPlugin)
GetSimApp(suite.chainA).WasmClientKeeper.SetQueryPlugins(querierPlugin)

suite.mockVM.RegisterQueryCallback(types.TimestampAtHeightMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, store wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) {
queryRequest := types.QueryChecksumsRequest{}
Expand Down Expand Up @@ -200,12 +200,12 @@ func (suite *KeeperTestSuite) TestStargateQuery() {
// This exercises the full flow through the grpc handler and into the light client for verification, handling encoding and routing.
// Furthermore we write a test key and assert that the state changes made by this handler were discarded by the cachedCtx at the grpc handler.
"success: verify membership query",
func(k *keeper.Keeper) {
func() {
querierPlugin := keeper.QueryPlugins{
Stargate: keeper.AcceptListStargateQuerier([]string{""}, GetSimApp(suite.chainA).GRPCQueryRouter()),
}

k.SetQueryPlugins(querierPlugin)
GetSimApp(suite.chainA).WasmClientKeeper.SetQueryPlugins(querierPlugin)

store := suite.chainA.GetContext().KVStore(GetSimApp(suite.chainA).GetKey(exported.StoreKey))
store.Set(proofKey, value)
Expand Down Expand Up @@ -277,7 +277,7 @@ func (suite *KeeperTestSuite) TestStargateQuery() {
},
{
"failure: default querier",
func(k *keeper.Keeper) {
func() {
suite.mockVM.RegisterQueryCallback(types.TimestampAtHeightMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, store wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) {
queryRequest := types.QueryChecksumsRequest{}
bz, err := queryRequest.Marshal()
Expand Down Expand Up @@ -311,9 +311,9 @@ func (suite *KeeperTestSuite) TestStargateQuery() {
err := endpoint.CreateClient()
suite.Require().NoError(err)

wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper
tc.malleate()

tc.malleate(&wasmClientKeeper)
wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper

payload := types.QueryMsg{
TimestampAtHeight: &types.TimestampAtHeightMsg{
Expand Down

0 comments on commit 4a9abfc

Please sign in to comment.