Skip to content

Commit

Permalink
Deprecate REST endpoints (CosmWasm#1070)
Browse files Browse the repository at this point in the history
* Deprecate REST support

* Add deprecation and nolint annotations
  • Loading branch information
alpe authored and conorpp committed Feb 1, 2023
1 parent 385cf1f commit 416f73c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var (
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
append(
wasmclient.ProposalHandlers,
wasmclient.ProposalHandlers, //nolint:staticcheck
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.ProposalHandler,
Expand Down
1 change: 0 additions & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion x/wasm/client/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions x/wasm/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Deprecated: the rest package will be removed. You can use the GRPC gateway instead
package rest

import (
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions x/wasm/keeper/legacy_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
29 changes: 12 additions & 17 deletions x/wasm/keeper/recurse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)

type Recurse struct {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -176,7 +177,7 @@ func TestGasOnExternalQuery(t *testing.T) {
Depth: 4,
Work: 50,
},
expectPanic: true,
expOutOfGas: true,
},
}

Expand All @@ -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)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 416f73c

Please sign in to comment.