Skip to content
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

Deprecate REST endpoints #1070

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 4 additions & 3 deletions x/wasm/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down