From 6c5302e4531b24bdc8ecf144112e267d4e39e9bd Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Tue, 1 Nov 2022 16:17:02 +0100 Subject: [PATCH 1/2] Deprecate REST support --- x/wasm/alias.go | 1 - x/wasm/client/rest/rest.go | 2 ++ x/wasm/keeper/legacy_querier.go | 1 + x/wasm/keeper/recurse_test.go | 29 ++++++++++++----------------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/x/wasm/alias.go b/x/wasm/alias.go index a64de37bdd..e47a657c97 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -59,7 +59,6 @@ var ( EncodeStakingMsg = keeper.EncodeStakingMsg EncodeWasmMsg = keeper.EncodeWasmMsg NewKeeper = keeper.NewKeeper - NewLegacyQuerier = keeper.NewLegacyQuerier DefaultQueryPlugins = keeper.DefaultQueryPlugins BankQuerier = keeper.BankQuerier NoCustomQuerier = keeper.NoCustomQuerier diff --git a/x/wasm/client/rest/rest.go b/x/wasm/client/rest/rest.go index 2e697a6b50..95339d3aa0 100644 --- a/x/wasm/client/rest/rest.go +++ b/x/wasm/client/rest/rest.go @@ -1,3 +1,4 @@ +// Deprecated: the rest package will be removed. You can use the GRPC gateway instead package rest import ( @@ -6,6 +7,7 @@ import ( ) // RegisterRoutes registers staking-related REST handlers to a router +// Deprecated: the rest package will be removed. You can use the GRPC gateway instead func RegisterRoutes(cliCtx client.Context, r *mux.Router) { registerQueryRoutes(cliCtx, r) registerTxRoutes(cliCtx, r) diff --git a/x/wasm/keeper/legacy_querier.go b/x/wasm/keeper/legacy_querier.go index a4dd3055aa..8ff72e1f81 100644 --- a/x/wasm/keeper/legacy_querier.go +++ b/x/wasm/keeper/legacy_querier.go @@ -28,6 +28,7 @@ const ( ) // NewLegacyQuerier creates a new querier +// Deprecated: the rest support will be removed. You can use the GRPC gateway instead func NewLegacyQuerier(keeper types.ViewKeeper, gasLimit sdk.Gas) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { var ( diff --git a/x/wasm/keeper/recurse_test.go b/x/wasm/keeper/recurse_test.go index 5a16da7878..0c0831aa49 100644 --- a/x/wasm/keeper/recurse_test.go +++ b/x/wasm/keeper/recurse_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "testing" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/CosmWasm/wasmd/x/wasm/types" wasmvmtypes "github.com/CosmWasm/wasmvm/types" @@ -11,7 +13,6 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - abci "github.com/tendermint/tendermint/abci/types" ) type Recurse struct { @@ -146,7 +147,7 @@ func TestGasOnExternalQuery(t *testing.T) { cases := map[string]struct { gasLimit uint64 msg Recurse - expectPanic bool + expOutOfGas bool }{ "no recursion, plenty gas": { gasLimit: 400_000, @@ -167,7 +168,7 @@ func TestGasOnExternalQuery(t *testing.T) { msg: Recurse{ Work: 50, }, - expectPanic: true, + expOutOfGas: true, }, "recursion 4, external gas limit": { // this uses 244708 gas but give less @@ -176,7 +177,7 @@ func TestGasOnExternalQuery(t *testing.T) { Depth: 4, Work: 50, }, - expectPanic: true, + expOutOfGas: true, }, } @@ -188,20 +189,14 @@ func TestGasOnExternalQuery(t *testing.T) { recurse.Contract = contractAddr msg := buildRecurseQuery(t, recurse) - // do the query - path := []string{QueryGetContractState, contractAddr.String(), QueryMethodContractStateSmart} - req := abci.RequestQuery{Data: msg} - if tc.expectPanic { - require.Panics(t, func() { - // this should run out of gas - _, err := NewLegacyQuerier(keeper, tc.gasLimit)(ctx, path, req) - t.Logf("%v", err) - }) - } else { - // otherwise, make sure we get a good success - _, err := NewLegacyQuerier(keeper, tc.gasLimit)(ctx, path, req) - require.NoError(t, err) + querier := NewGrpcQuerier(keeper.cdc, keeper.storeKey, keeper, tc.gasLimit) + req := &types.QuerySmartContractStateRequest{Address: contractAddr.String(), QueryData: msg} + _, gotErr := querier.SmartContractState(sdk.WrapSDKContext(ctx), req) + if tc.expOutOfGas { + require.Error(t, gotErr, sdkerrors.ErrOutOfGas) + return } + require.NoError(t, gotErr) }) } } From de6df178ac8b4904fb087ee5f9ef6bef17ecf124 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 9 Nov 2022 08:33:04 +0100 Subject: [PATCH 2/2] Add deprecation and nolint annotations --- app/app.go | 2 +- x/wasm/client/proposal_handler.go | 3 ++- x/wasm/module.go | 2 +- x/wasm/simulation/proposals.go | 7 ++++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index 5d62f67e1e..c81550fd22 100644 --- a/app/app.go +++ b/app/app.go @@ -185,7 +185,7 @@ var ( distr.AppModuleBasic{}, gov.NewAppModuleBasic( append( - wasmclient.ProposalHandlers, + wasmclient.ProposalHandlers, //nolint:staticcheck paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, diff --git a/x/wasm/client/proposal_handler.go b/x/wasm/client/proposal_handler.go index 6d4735180e..9d90d48df8 100644 --- a/x/wasm/client/proposal_handler.go +++ b/x/wasm/client/proposal_handler.go @@ -4,10 +4,11 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/CosmWasm/wasmd/x/wasm/client/cli" - "github.com/CosmWasm/wasmd/x/wasm/client/rest" + "github.com/CosmWasm/wasmd/x/wasm/client/rest" //nolint:staticcheck ) // ProposalHandlers define the wasm cli proposal types and rest handler. +// Deprecated: the rest package will be removed. You can use the GRPC gateway instead var ProposalHandlers = []govclient.ProposalHandler{ govclient.NewProposalHandler(cli.ProposalStoreCodeCmd, rest.StoreCodeProposalHandler), govclient.NewProposalHandler(cli.ProposalInstantiateContractCmd, rest.InstantiateProposalHandler), diff --git a/x/wasm/module.go b/x/wasm/module.go index 8473d7f34e..ea79b23768 100644 --- a/x/wasm/module.go +++ b/x/wasm/module.go @@ -24,7 +24,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/CosmWasm/wasmd/x/wasm/client/cli" - "github.com/CosmWasm/wasmd/x/wasm/client/rest" + "github.com/CosmWasm/wasmd/x/wasm/client/rest" //nolint:staticcheck "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/simulation" "github.com/CosmWasm/wasmd/x/wasm/types" diff --git a/x/wasm/simulation/proposals.go b/x/wasm/simulation/proposals.go index 8e73f04f64..1ee9584811 100644 --- a/x/wasm/simulation/proposals.go +++ b/x/wasm/simulation/proposals.go @@ -3,12 +3,13 @@ package simulation import ( "math/rand" - "github.com/CosmWasm/wasmd/app/params" - "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" - "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/CosmWasm/wasmd/app/params" + "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" + "github.com/CosmWasm/wasmd/x/wasm/types" ) const (