From a4e3eacab4d4bfa0f2339fddd4c73dfce27e9d12 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Fri, 8 Feb 2019 13:04:54 -0800 Subject: [PATCH] add a bunch of tests, add DONTCOVER text tag - Also fix flaky test (closes: #3559). Don't test values returned by queries since there's no way to query a specific height via REST. --- .circleci/config.yml | 8 +++ client/context/query.go | 3 +- client/keys/mnemonic.go | 3 +- client/lcd/lcd_test.go | 16 ++---- cmd/gaia/app/sim_test.go | 5 +- cmd/gaia/init/collect.go | 2 + cmd/gaia/init/gentx.go | 2 + cmd/gaia/init/init_test.go | 1 - cmd/gaia/init/testnet.go | 2 + cmd/gaia/init/utils_test.go | 49 +++++++++++++++++++ crypto/keys/lazy_keybase.go | 5 +- crypto/ledger_secp256k1.go | 3 +- server/constructors_test.go | 33 +++++++++++++ server/export.go | 17 ++++--- server/init_test.go | 27 +++++++++- server/tm_cmds.go | 2 + store/list/list_test.go | 3 +- store/transient/store.go | 3 +- tests/util.go | 30 +++++------- x/distribution/client/cli/tx.go | 6 +-- x/distribution/client/common/common_test.go | 3 +- x/distribution/client/rest/query.go | 3 +- x/distribution/client/rest/rest.go | 3 +- x/gov/client/cli/parse.go | 42 ++++++++++++++++ .../client/cli/{tx_test.go => parse_test.go} | 0 x/gov/client/cli/query.go | 2 + x/gov/client/cli/tx.go | 36 +------------- 27 files changed, 219 insertions(+), 90 deletions(-) create mode 100644 cmd/gaia/init/utils_test.go create mode 100644 server/constructors_test.go create mode 100644 x/gov/client/cli/parse.go rename x/gov/client/cli/{tx_test.go => parse_test.go} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index bbbe7dd9d4d4..9efb455e119f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -232,6 +232,14 @@ jobs: for prof in $(ls /tmp/workspace/profiles/); do tail -n +2 /tmp/workspace/profiles/"$prof" >> coverage.txt done + - run: + name: filter out DONTCOVER + command: | + excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER' | xargs realpath --relative-to=$GOPATH/src)" + for filename in ${excludelist}; do + echo "Excluding ${filename} ..." + sed -i "\%${filename}:%d" coverage.txt + done - run: name: upload command: bash <(curl -s https://codecov.io/bash) -f coverage.txt diff --git a/client/context/query.go b/client/context/query.go index 17df39e74e25..a2fc7ff781ec 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -10,7 +10,6 @@ import ( "strings" - "github.com/cosmos/cosmos-sdk/store/rootmulti" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/merkle" cmn "github.com/tendermint/tendermint/libs/common" @@ -18,6 +17,8 @@ import ( 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/rootmulti" ) // GetNode returns an RPC client. If the context's client is not defined, an diff --git a/client/keys/mnemonic.go b/client/keys/mnemonic.go index 64641e1c480b..b9d434d2bf96 100644 --- a/client/keys/mnemonic.go +++ b/client/keys/mnemonic.go @@ -5,8 +5,9 @@ import ( "fmt" bip39 "github.com/bartekn/go-bip39" - "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" ) const ( diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 7648d86a3012..c13be7acb8f7 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -527,7 +527,8 @@ func TestBonding(t *testing.T) { require.NoError(t, err) addr, _ := CreateAddr(t, name1, pw, kb) - cleanup, valPubKeys, operAddrs, port := InitializeTestLCD(t, 2, []sdk.AccAddress{addr}, true) + cleanup, valPubKeys, operAddrs, port := InitializeTestLCD(t, 2, []sdk.AccAddress{addr}, false) + tests.WaitForHeight(1, port) defer cleanup() require.Equal(t, 2, len(valPubKeys)) @@ -1025,7 +1026,7 @@ func TestDistributionFlow(t *testing.T) { kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, "")) require.NoError(t, err) addr, seed := CreateAddr(t, name1, pw, kb) - cleanup, _, valAddrs, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}, false) + cleanup, _, valAddrs, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}, true) defer cleanup() valAddr := valAddrs[0] @@ -1035,15 +1036,12 @@ func TestDistributionFlow(t *testing.T) { res, body := Request(t, port, "GET", fmt.Sprintf("/distribution/outstanding_rewards"), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) require.NoError(t, cdc.UnmarshalJSON([]byte(body), &rewards)) - require.Equal(t, sdk.DecCoins(nil), rewards) var valDistInfo distrrest.ValidatorDistInfo res, body = Request(t, port, "GET", "/distribution/validators/"+valAddr.String(), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) require.NoError(t, cdc.UnmarshalJSON([]byte(body), &valDistInfo)) require.Equal(t, valDistInfo.OperatorAddress.String(), sdk.AccAddress(valAddr).String()) - require.Equal(t, valDistInfo.ValidatorCommission, sdk.DecCoins(nil)) - require.Equal(t, valDistInfo.SelfBondRewards, sdk.DecCoins(nil)) // Delegate some coins delTokens := staking.TokensFromTendermintPower(60) @@ -1057,43 +1055,35 @@ func TestDistributionFlow(t *testing.T) { require.Equal(t, uint32(0), resultTx.Code) // Query outstanding rewards changed - oustandingRewards := mustParseDecCoins("9.80stake") res, body = Request(t, port, "GET", fmt.Sprintf("/distribution/outstanding_rewards"), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) require.NoError(t, cdc.UnmarshalJSON([]byte(body), &rewards)) - require.Equal(t, oustandingRewards, rewards) // Query validator distribution info res, body = Request(t, port, "GET", "/distribution/validators/"+valAddr.String(), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - valRewards := mustParseDecCoins("6.125stake") require.NoError(t, cdc.UnmarshalJSON([]byte(body), &valDistInfo)) - require.Equal(t, valRewards, valDistInfo.SelfBondRewards) // Query validator's rewards res, body = Request(t, port, "GET", fmt.Sprintf("/distribution/validators/%s/rewards", valAddr), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) require.NoError(t, cdc.UnmarshalJSON([]byte(body), &rewards)) - require.Equal(t, valRewards, rewards) // Query self-delegation res, body = Request(t, port, "GET", fmt.Sprintf("/distribution/delegators/%s/rewards/%s", operAddr, valAddr), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) require.NoError(t, cdc.UnmarshalJSON([]byte(body), &rewards)) - require.Equal(t, valRewards, rewards) // Query delegation res, body = Request(t, port, "GET", fmt.Sprintf("/distribution/delegators/%s/rewards/%s", addr, valAddr), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) require.NoError(t, cdc.UnmarshalJSON([]byte(body), &rewards)) - require.Equal(t, mustParseDecCoins("3.675stake"), rewards) // Query delegator's rewards total res, body = Request(t, port, "GET", fmt.Sprintf("/distribution/delegators/%s/rewards", operAddr), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) require.NoError(t, cdc.UnmarshalJSON([]byte(body), &rewards)) - require.Equal(t, valRewards, rewards) // Query delegator's withdrawal address var withdrawAddr string diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index 6e0c1f3292e6..90b1785b1dd3 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -417,10 +417,7 @@ func TestGaiaImportExport(t *testing.T) { fmt.Printf("Exporting genesis...\n") appState, _, err := app.ExportAppStateAndValidators(false, []string{}) - if err != nil { - panic(err) - } - + require.NoError(t, err) fmt.Printf("Importing genesis...\n") newDir, _ := ioutil.TempDir("", "goleveldb-gaia-sim-2") diff --git a/cmd/gaia/init/collect.go b/cmd/gaia/init/collect.go index d0842df2cbe0..858639486861 100644 --- a/cmd/gaia/init/collect.go +++ b/cmd/gaia/init/collect.go @@ -1,5 +1,7 @@ package init +// DONTCOVER + import ( "encoding/json" "path/filepath" diff --git a/cmd/gaia/init/gentx.go b/cmd/gaia/init/gentx.go index 5c35818cd9be..ef3ee7106d04 100644 --- a/cmd/gaia/init/gentx.go +++ b/cmd/gaia/init/gentx.go @@ -1,5 +1,7 @@ package init +// DONTCOVER + import ( "bytes" "fmt" diff --git a/cmd/gaia/init/init_test.go b/cmd/gaia/init/init_test.go index 8dac1695286b..39975bb2963c 100644 --- a/cmd/gaia/init/init_test.go +++ b/cmd/gaia/init/init_test.go @@ -79,7 +79,6 @@ func TestEmptyState(t *testing.T) { w.Close() os.Stdout = old out := <-outC - require.Contains(t, out, "WARNING: State is not initialized") require.Contains(t, out, "genesis_time") require.Contains(t, out, "chain_id") require.Contains(t, out, "consensus_params") diff --git a/cmd/gaia/init/testnet.go b/cmd/gaia/init/testnet.go index 24cfd2b1dbc5..346e6a4b342e 100644 --- a/cmd/gaia/init/testnet.go +++ b/cmd/gaia/init/testnet.go @@ -1,5 +1,7 @@ package init +// DONTCOVER + import ( "encoding/json" "fmt" diff --git a/cmd/gaia/init/utils_test.go b/cmd/gaia/init/utils_test.go new file mode 100644 index 000000000000..3a5a136903b2 --- /dev/null +++ b/cmd/gaia/init/utils_test.go @@ -0,0 +1,49 @@ +package init + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + "testing" + "time" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/tests" + + "github.com/stretchr/testify/require" +) + +func TestExportGenesisFileWithTime(t *testing.T) { + t.Parallel() + dir, cleanup := tests.NewTestCaseDir(t) + defer cleanup() + + fname := filepath.Join(dir, "genesis.json") + require.NoError(t, ExportGenesisFileWithTime(fname, "test", nil, json.RawMessage(""), time.Now())) +} + +func TestLoadGenesisDoc(t *testing.T) { + t.Parallel() + dir, cleanup := tests.NewTestCaseDir(t) + defer cleanup() + + fname := filepath.Join(dir, "genesis.json") + require.NoError(t, ExportGenesisFileWithTime(fname, "test", nil, json.RawMessage(""), time.Now())) + + _, err := LoadGenesisDoc(codec.Cdc, fname) + require.NoError(t, err) + + // Non-existing file + _, err = LoadGenesisDoc(codec.Cdc, "non-existing-file") + require.Error(t, err) + + malformedFilename := filepath.Join(dir, "malformed") + malformedFile, err := os.Create(malformedFilename) + require.NoError(t, err) + fmt.Fprint(malformedFile, "invalidjson") + malformedFile.Close() + // Non-existing file + _, err = LoadGenesisDoc(codec.Cdc, malformedFilename) + require.Error(t, err) +} diff --git a/crypto/keys/lazy_keybase.go b/crypto/keys/lazy_keybase.go index d63e6c06c8e3..c26083972201 100644 --- a/crypto/keys/lazy_keybase.go +++ b/crypto/keys/lazy_keybase.go @@ -1,10 +1,11 @@ package keys import ( - "github.com/cosmos/cosmos-sdk/crypto/keys/hd" - "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/crypto" dbm "github.com/tendermint/tendermint/libs/db" + + "github.com/cosmos/cosmos-sdk/crypto/keys/hd" + "github.com/cosmos/cosmos-sdk/types" ) var _ Keybase = lazyKeybase{} diff --git a/crypto/ledger_secp256k1.go b/crypto/ledger_secp256k1.go index 0a7b9707b08d..c19c82fd8aa6 100644 --- a/crypto/ledger_secp256k1.go +++ b/crypto/ledger_secp256k1.go @@ -5,11 +5,12 @@ import ( "os" "github.com/btcsuite/btcd/btcec" - "github.com/cosmos/cosmos-sdk/crypto/keys/hd" "github.com/pkg/errors" tmbtcec "github.com/tendermint/btcd/btcec" tmcrypto "github.com/tendermint/tendermint/crypto" tmsecp256k1 "github.com/tendermint/tendermint/crypto/secp256k1" + + "github.com/cosmos/cosmos-sdk/crypto/keys/hd" ) var ( diff --git a/server/constructors_test.go b/server/constructors_test.go new file mode 100644 index 000000000000..e1da004a63f9 --- /dev/null +++ b/server/constructors_test.go @@ -0,0 +1,33 @@ +package server + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/tests" +) + +func Test_openDB(t *testing.T) { + t.Parallel() + dir, cleanup := tests.NewTestCaseDir(t) + defer cleanup() + _, err := openDB(dir) + require.NoError(t, err) +} + +func Test_openTraceWriter(t *testing.T) { + t.Parallel() + dir, cleanup := tests.NewTestCaseDir(t) + defer cleanup() + fname := filepath.Join(dir, "logfile") + w, err := openTraceWriter(fname) + require.NoError(t, err) + require.NotNil(t, w) + + // test no-op + w, err = openTraceWriter("") + require.NoError(t, err) + require.Nil(t, w) +} diff --git a/server/export.go b/server/export.go index ba222ac5814f..5256aa76ca92 100644 --- a/server/export.go +++ b/server/export.go @@ -1,7 +1,10 @@ package server +// DONTCOVER + import ( "fmt" + "os" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -9,6 +12,7 @@ import ( "io/ioutil" "path" + "github.com/tendermint/tendermint/libs/cli" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" @@ -26,17 +30,18 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C Use: "export", Short: "Export state to JSON", RunE: func(cmd *cobra.Command, args []string) error { - home := viper.GetString("home") + config := ctx.Config + config.SetRoot(viper.GetString(cli.HomeFlag)) + traceWriterFile := viper.GetString(flagTraceStore) - emptyState, err := isEmptyState(home) + emptyState, err := isEmptyState(config.RootDir) if err != nil { return err } if emptyState || appExporter == nil { - fmt.Println("WARNING: State is not initialized. Returning genesis file.") - genesisFile := path.Join(home, "config", "genesis.json") - genesis, err := ioutil.ReadFile(genesisFile) + fmt.Fprintln(os.Stderr, "WARNING: State is not initialized. Returning genesis file.") + genesis, err := ioutil.ReadFile(config.GenesisFile()) if err != nil { return err } @@ -44,7 +49,7 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C return nil } - db, err := openDB(home) + db, err := openDB(config.RootDir) if err != nil { return err } diff --git a/server/init_test.go b/server/init_test.go index 632042050104..38b88777900a 100644 --- a/server/init_test.go +++ b/server/init_test.go @@ -5,12 +5,14 @@ import ( "os" "testing" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/server" - "github.com/stretchr/testify/require" ) func TestGenerateCoinKey(t *testing.T) { + t.Parallel() addr, mnemonic, err := server.GenerateCoinKey() require.NoError(t, err) @@ -21,6 +23,7 @@ func TestGenerateCoinKey(t *testing.T) { } func TestGenerateSaveCoinKey(t *testing.T) { + t.Parallel() dir, cleanup := tempdir(t) defer cleanup() // clean after itself // Remove the dir to that GenerateSaveCoinKey creates it automatically @@ -42,6 +45,28 @@ func TestGenerateSaveCoinKey(t *testing.T) { require.Equal(t, addr, info.GetAddress()) } +func TestGenerateSaveCoinKeyOverwriteFlag(t *testing.T) { + t.Parallel() + dir, cleanup := tempdir(t) + defer cleanup() // clean after itself + // Remove the dir to that GenerateSaveCoinKey creates it automatically + os.RemoveAll(dir) + + keyname := "justakey" + addr1, _, err := server.GenerateSaveCoinKey(dir, keyname, "012345678", false) + require.NoError(t, err) + + // Test overwrite with overwrite=false + _, _, err = server.GenerateSaveCoinKey(dir, keyname, "012345678", false) + require.Error(t, err) + + // Test overwrite with overwrite=true + addr2, _, err := server.GenerateSaveCoinKey(dir, keyname, "012345678", true) + require.NoError(t, err) + + require.NotEqual(t, addr1, addr2) +} + func tempdir(t *testing.T) (string, func()) { dir, err := ioutil.TempDir("", t.Name()+"_") require.NoError(t, err) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 93a9caa6b23f..92d51d69e16b 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -1,5 +1,7 @@ package server +// DONTCOVER + import ( "fmt" diff --git a/store/list/list_test.go b/store/list/list_test.go index 970c836bc3eb..34548a79e509 100644 --- a/store/list/list_test.go +++ b/store/list/list_test.go @@ -9,10 +9,11 @@ import ( abci "github.com/tendermint/tendermint/abci/types" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/rootmulti" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" ) type TestStruct struct { diff --git a/store/transient/store.go b/store/transient/store.go index 0a7e945e3e58..de514ec2f3fe 100644 --- a/store/transient/store.go +++ b/store/transient/store.go @@ -1,9 +1,10 @@ package transient import ( - "github.com/cosmos/cosmos-sdk/store/types" dbm "github.com/tendermint/tendermint/libs/db" + "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/store/dbadapter" ) diff --git a/tests/util.go b/tests/util.go index be365bfa979e..d8ddd424e603 100644 --- a/tests/util.go +++ b/tests/util.go @@ -5,8 +5,11 @@ import ( "io/ioutil" "net/http" "os" + "testing" "time" + "github.com/stretchr/testify/require" + "strings" amino "github.com/tendermint/go-amino" @@ -197,26 +200,17 @@ func ExtractPortFromAddress(listenAddress string) string { return stringList[2] } +// NewTestCaseDir creates a new temporary directory for a test case. +// Returns the directory path and a cleanup function. +// nolint: errcheck +func NewTestCaseDir(t *testing.T) (string, func()) { + dir, err := ioutil.TempDir("", t.Name()+"_") + require.NoError(t, err) + return dir, func() { os.RemoveAll(dir) } +} + var cdc = amino.NewCodec() func init() { ctypes.RegisterAmino(cdc) } - -// GetTempDir creates a temporary directory and returns a clean up function -// to be deferred -func GetTempDir(prefix string) (string, func(), error) { - rootDir, err := ioutil.TempDir("", prefix) - if err != nil { - return "", nil, err - } - - cleanUp := func() { - err := os.RemoveAll(rootDir) - if err != nil { - panic(err) - } - } - - return rootDir, cleanUp, nil -} diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 3f7278280860..8bf143ce953f 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -22,7 +22,7 @@ import ( var ( flagOnlyFromValidator = "only-from-validator" flagIsValidator = "is-validator" - flagComission = "comission" + flagComission = "commission" ) // GetTxCmd returns the transaction commands for this module @@ -48,7 +48,7 @@ func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command { Long: strings.TrimSpace(`witdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator: $ gaiacli tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey -$ gaiacli tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey --comission +$ gaiacli tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey --commission `), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -108,7 +108,7 @@ func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "set-withdraw-addr [withdraw-addr]", Short: "change the default withdraw address for rewards associated with an address", - Long: strings.TrimSpace(`Set the withdraw address for rewards assoicated with a delegator address: + Long: strings.TrimSpace(`Set the withdraw address for rewards associated with a delegator address: $ gaiacli tx set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from mykey `), diff --git a/x/distribution/client/common/common_test.go b/x/distribution/client/common/common_test.go index 622326232a05..ff9cbfd75642 100644 --- a/x/distribution/client/common/common_test.go +++ b/x/distribution/client/common/common_test.go @@ -3,9 +3,10 @@ package common import ( "testing" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - "github.com/stretchr/testify/require" ) func TestQueryDelegationRewardsAddrValidation(t *testing.T) { diff --git a/x/distribution/client/rest/query.go b/x/distribution/client/rest/query.go index 6f7730407dde..2c70e34fc680 100644 --- a/x/distribution/client/rest/query.go +++ b/x/distribution/client/rest/query.go @@ -8,11 +8,12 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution/client/common" "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/rest" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/gorilla/mux" ) func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index 769e7360e8da..6596ccdf3e1d 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -1,9 +1,10 @@ package rest import ( + "github.com/gorilla/mux" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - "github.com/gorilla/mux" ) // RegisterRoutes register distribution REST routes. diff --git a/x/gov/client/cli/parse.go b/x/gov/client/cli/parse.go new file mode 100644 index 000000000000..884837c91bc5 --- /dev/null +++ b/x/gov/client/cli/parse.go @@ -0,0 +1,42 @@ +package cli + +import ( + "encoding/json" + "fmt" + "io/ioutil" + + "github.com/spf13/viper" + + govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" +) + +func parseSubmitProposalFlags() (*proposal, error) { + proposal := &proposal{} + proposalFile := viper.GetString(flagProposal) + + if proposalFile == "" { + proposal.Title = viper.GetString(flagTitle) + proposal.Description = viper.GetString(flagDescription) + proposal.Type = govClientUtils.NormalizeProposalType(viper.GetString(flagProposalType)) + proposal.Deposit = viper.GetString(flagDeposit) + return proposal, nil + } + + for _, flag := range proposalFlags { + if viper.GetString(flag) != "" { + return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag) + } + } + + contents, err := ioutil.ReadFile(proposalFile) + if err != nil { + return nil, err + } + + err = json.Unmarshal(contents, proposal) + if err != nil { + return nil, err + } + + return proposal, nil +} diff --git a/x/gov/client/cli/tx_test.go b/x/gov/client/cli/parse_test.go similarity index 100% rename from x/gov/client/cli/tx_test.go rename to x/gov/client/cli/parse_test.go diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 7d7952f4d8c4..4d2b8ddde2dd 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -511,3 +511,5 @@ $ gaiacli query gov proposer 1 }, } } + +// DONTCOVER diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 9199491a91c8..836c799b0d03 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -11,12 +11,9 @@ import ( authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" "github.com/cosmos/cosmos-sdk/x/gov" - "encoding/json" - "io/ioutil" "strings" "github.com/spf13/cobra" - "github.com/spf13/viper" govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" ) @@ -126,37 +123,6 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome return cmd } -func parseSubmitProposalFlags() (*proposal, error) { - proposal := &proposal{} - proposalFile := viper.GetString(flagProposal) - - if proposalFile == "" { - proposal.Title = viper.GetString(flagTitle) - proposal.Description = viper.GetString(flagDescription) - proposal.Type = govClientUtils.NormalizeProposalType(viper.GetString(flagProposalType)) - proposal.Deposit = viper.GetString(flagDeposit) - return proposal, nil - } - - for _, flag := range proposalFlags { - if viper.GetString(flag) != "" { - return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag) - } - } - - contents, err := ioutil.ReadFile(proposalFile) - if err != nil { - return nil, err - } - - err = json.Unmarshal(contents, proposal) - if err != nil { - return nil, err - } - - return proposal, nil -} - // GetCmdDeposit implements depositing tokens for an active proposal. func GetCmdDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ @@ -265,3 +231,5 @@ $ gaiacli tx gov vote 1 yes --from mykey }, } } + +// DONTCOVER