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

R4R: Move generate_only and simulate to POST body in REST txs #3060

Merged
merged 5 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BREAKING CHANGES

* Gaia REST API (`gaiacli advanced rest-server`)
* [\#3056](https://github.com/cosmos/cosmos-sdk/pull/3056) `generate_only` and `simulate` have moved from query arguments to POST requests body.

* Gaia CLI (`gaiacli`)
* [cli] [\#2595](https://github.com/cosmos/cosmos-sdk/issues/2595) Remove `keys new` in favor of `keys add` incorporating existing functionality with addition of key recovery functionality.
Expand Down
3 changes: 2 additions & 1 deletion baseapp/helpers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package baseapp

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/abci/server"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"

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

// nolint - Mostly for testing
Expand Down
3 changes: 2 additions & 1 deletion baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ package baseapp
import (
"fmt"

dbm "github.com/tendermint/tendermint/libs/db"

"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
dbm "github.com/tendermint/tendermint/libs/db"
)

// File for storing in-package BaseApp optional functions,
Expand Down
3 changes: 2 additions & 1 deletion baseapp/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"

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

// Test that we can only query from the latest committed state.
Expand Down
3 changes: 2 additions & 1 deletion client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"path"
"strconv"

"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/cmd/gaia/app"

"github.com/pelletier/go-toml"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
7 changes: 4 additions & 3 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (

"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client/keys"
cskeys "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
tmlite "github.com/tendermint/tendermint/lite"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
rpcclient "github.com/tendermint/tendermint/rpc/client"

"github.com/cosmos/cosmos-sdk/client/keys"
cskeys "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/types"
)

const ctxAccStoreName = "acc"
Expand Down
3 changes: 2 additions & 1 deletion client/context/errors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package context

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"

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

// ErrInvalidAccount returns a standardized error reflecting that a given
Expand Down
3 changes: 2 additions & 1 deletion client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (

"strings"

"github.com/cosmos/cosmos-sdk/store"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
tmliteErr "github.com/tendermint/tendermint/lite/errors"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
rpcclient "github.com/tendermint/tendermint/rpc/client"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/store"
)

// GetNode returns an RPC client. If the context's client is not defined, an
Expand Down
3 changes: 2 additions & 1 deletion client/keys.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package client

import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
dbm "github.com/tendermint/tendermint/libs/db"

"github.com/cosmos/cosmos-sdk/crypto/keys"
)

// GetKeyBase initializes a keybase based on the given db.
Expand Down
3 changes: 2 additions & 1 deletion client/keys/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

"github.com/spf13/viper"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client"
keys "github.com/cosmos/cosmos-sdk/crypto/keys"
keyerror "github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
"github.com/gorilla/mux"

"github.com/spf13/cobra"
)
Expand Down
3 changes: 2 additions & 1 deletion client/keys/mnemonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"crypto/sha256"
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"

bip39 "github.com/bartekn/go-bip39"
)

Expand Down
3 changes: 2 additions & 1 deletion client/keys/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package keys

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/gorilla/mux"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
)

// Commands registers a sub-tree of commands to interact with
Expand Down
8 changes: 5 additions & 3 deletions client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/crypto/keys"

"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
Expand Down
6 changes: 4 additions & 2 deletions client/keys/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"fmt"
"net/http"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client"
keys "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
)

func updateKeyCommand() *cobra.Command {
Expand Down
9 changes: 5 additions & 4 deletions client/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"net/http"
"path/filepath"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/viper"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/tendermint/tendermint/libs/cli"
dbm "github.com/tendermint/tendermint/libs/db"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// KeyDBName is the directory under root where we store the keys
Expand Down
6 changes: 4 additions & 2 deletions client/keys/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package keys

import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/crypto/keys"
)

func TestGetKeyBaseLocks(t *testing.T) {
Expand Down
28 changes: 16 additions & 12 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,29 +279,29 @@ func TestCoinSend(t *testing.T) {
require.Equal(t, int64(1), mycoins.Amount.Int64())

// test failure with too little gas
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "100", 0, "")
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "100", 0, false, false)
require.Equal(t, http.StatusInternalServerError, res.StatusCode, body)

// test failure with negative gas
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "-200", 0, "")
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "-200", 0, false, false)
require.Equal(t, http.StatusBadRequest, res.StatusCode, body)

// test failure with 0 gas
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "0", 0, "")
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "0", 0, false, false)
require.Equal(t, http.StatusInternalServerError, res.StatusCode, body)

// test failure with wrong adjustment
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "simulate", 0.1, "")
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "simulate", 0.1, false, false)
require.Equal(t, http.StatusInternalServerError, res.StatusCode, body)

// run simulation and test success with estimated gas
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "", 0, "?simulate=true")
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, "", 0, true, false)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var responseBody struct {
GasEstimate int64 `json:"gas_estimate"`
}
require.Nil(t, json.Unmarshal([]byte(body), &responseBody))
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, fmt.Sprintf("%v", responseBody.GasEstimate), 0, "")
res, body, _ = doSendWithGas(t, port, seed, name, password, addr, fmt.Sprintf("%v", responseBody.GasEstimate), 0, false, false)
require.Equal(t, http.StatusOK, res.StatusCode, body)
}

Expand Down Expand Up @@ -342,7 +342,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) {
acc := getAccount(t, port, addr)

// generate TX
res, body, _ := doSendWithGas(t, port, seed, name, password, addr, "simulate", 0, "?generate_only=true")
res, body, _ := doSendWithGas(t, port, seed, name, password, addr, "simulate", 0, false, true)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var msg auth.StdTx
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &msg))
Expand Down Expand Up @@ -897,7 +897,9 @@ func getAccount(t *testing.T, port string, addr sdk.AccAddress) auth.Account {
return acc
}

func doSendWithGas(t *testing.T, port, seed, name, password string, addr sdk.AccAddress, gas string, gasAdjustment float64, queryStr string) (res *http.Response, body string, receiveAddr sdk.AccAddress) {
func doSendWithGas(t *testing.T, port, seed, name, password string, addr sdk.AccAddress, gas string,
gasAdjustment float64, simulate, generateOnly bool) (
res *http.Response, body string, receiveAddr sdk.AccAddress) {

// create receive address
kb := client.MockKeyBase()
Expand Down Expand Up @@ -935,11 +937,13 @@ func doSendWithGas(t *testing.T, port, seed, name, password string, addr sdk.Acc
"password": "%s",
"chain_id": "%s",
"account_number":"%d",
"sequence":"%d"
"sequence": "%d",
"simulate": %v,
"generate_only": %v
}
}`, coinbz, gasStr, gasAdjustmentStr, name, password, chainID, accnum, sequence))
}`, coinbz, gasStr, gasAdjustmentStr, name, password, chainID, accnum, sequence, simulate, generateOnly))

res, body = Request(t, port, "POST", fmt.Sprintf("/bank/accounts/%s/transfers%v", receiveAddr, queryStr), jsonStr)
res, body = Request(t, port, "POST", fmt.Sprintf("/bank/accounts/%s/transfers", receiveAddr), jsonStr)
return
}

Expand All @@ -958,7 +962,7 @@ func doRecoverKey(t *testing.T, port, recoverName, recoverPassword, seed string)
}

func doSend(t *testing.T, port, seed, name, password string, addr sdk.AccAddress) (receiveAddr sdk.AccAddress, resultTx ctypes.ResultBroadcastTxCommit) {
res, body, receiveAddr := doSendWithGas(t, port, seed, name, password, addr, "", 0, "")
res, body, receiveAddr := doSendWithGas(t, port, seed, name, password, addr, "", 0, false, false)
require.Equal(t, http.StatusOK, res.StatusCode, body)

err := cdc.UnmarshalJSON([]byte(body), &resultTx)
Expand Down
13 changes: 7 additions & 6 deletions client/lcd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import (
"net/http"
"os"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec"
keybase "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/server"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/log"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec"
keybase "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/server"

// Import statik for light client stuff
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik"
)
Expand Down
6 changes: 4 additions & 2 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
"strings"
"testing"

stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
"github.com/tendermint/tendermint/crypto/secp256k1"

stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/rpc"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"

txbuilder "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
abci "github.com/tendermint/tendermint/abci/types"
tmcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
Expand All @@ -48,6 +48,8 @@ import (
tmrpc "github.com/tendermint/tendermint/rpc/lib/server"
tmtypes "github.com/tendermint/tendermint/types"

txbuilder "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"

authRest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
bankRest "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
govRest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
Expand Down
3 changes: 2 additions & 1 deletion client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"

"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/spf13/viper"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"

"github.com/cosmos/cosmos-sdk/client/utils"
)

//BlockCommand returns the verified block data for a given heights
Expand Down
3 changes: 2 additions & 1 deletion client/rpc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/spf13/viper"
)

const (
Expand Down
Loading