Skip to content

Commit

Permalink
Merge PR cosmos#4351: remove x/ dependency on cmd/gaia
Browse files Browse the repository at this point in the history
* remove x/ dependency on cmd/gaia

This is an alternative patch to what is proposed in cosmos#4348

* Add pending entry

* Ditto for CollectGenTxsCmd

* Update pending

* Update tests

* Update pending
  • Loading branch information
alessio authored and rigelrozanski committed May 17, 2019
1 parent 5b7690e commit ca4363f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
1 change: 1 addition & 0 deletions .pending/breaking/sdk/4351-AddGenesisAccou
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4351 InitCmd, AddGenesisAccountCmd, and CollectGenTxsCmd take node's and client's default home directories as arguments.
6 changes: 3 additions & 3 deletions cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

rootCmd.AddCommand(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics))
rootCmd.AddCommand(genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}))
rootCmd.AddCommand(genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome))
rootCmd.AddCommand(genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, app.DefaultNodeHome))
rootCmd.AddCommand(genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics))
rootCmd.AddCommand(genaccscli.AddGenesisAccountCmd(ctx, cdc))
rootCmd.AddCommand(genaccscli.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome))
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
rootCmd.AddCommand(testnetCmd(ctx, cdc, app.ModuleBasics, genaccounts.AppModuleBasic{}))
rootCmd.AddCommand(replayCmd())
Expand Down
8 changes: 4 additions & 4 deletions x/auth/genaccounts/client/cli/genesis_accts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -24,7 +23,8 @@ const (
)

// AddGenesisAccountCmd returns add-genesis-account cobra Command.
func AddGenesisAccountCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
func AddGenesisAccountCmd(ctx *server.Context, cdc *codec.Codec,
defaultNodeHome, defaultClientHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
Short: "Add genesis account to genesis.json",
Expand Down Expand Up @@ -95,8 +95,8 @@ func AddGenesisAccountCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command
},
}

cmd.Flags().String(cli.HomeFlag, app.DefaultNodeHome, "node's home directory")
cmd.Flags().String(flagClientHome, app.DefaultCLIHome, "client's home directory")
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().String(flagClientHome, defaultClientHome, "client's home directory")
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
cmd.Flags().Uint64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
Expand Down
5 changes: 2 additions & 3 deletions x/genutil/client/cli/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
Expand All @@ -20,7 +19,7 @@ const flagGenTxDir = "gentx-dir"

// CollectGenTxsCmd - return the cobra command to collect genesis transactions
func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec,
genAccIterator genutil.GenesisAccountsIterator) *cobra.Command {
genAccIterator genutil.GenesisAccountsIterator, defaultNodeHome string) *cobra.Command {

cmd := &cobra.Command{
Use: "collect-gentxs",
Expand Down Expand Up @@ -59,7 +58,7 @@ func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec,
},
}

cmd.Flags().String(cli.HomeFlag, app.DefaultNodeHome, "node's home directory")
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().String(flagGenTxDir, "",
"override default \"gentx\" directory from which collect and execute "+
"genesis transactions; default [--home]/config/gentx/")
Expand Down
6 changes: 3 additions & 3 deletions x/genutil/client/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -58,7 +57,8 @@ func displayInfo(cdc *codec.Codec, info printInfo) error {

// InitCmd returns a command that initializes all files needed for Tendermint
// and the respective application.
func InitCmd(ctx *server.Context, cdc *codec.Codec, mbm sdk.ModuleBasicManager) *cobra.Command { // nolint: golint
func InitCmd(ctx *server.Context, cdc *codec.Codec, mbm sdk.ModuleBasicManager,
defaultNodeHome string) *cobra.Command { // nolint: golint
cmd := &cobra.Command{
Use: "init [moniker]",
Short: "Initialize private validator, p2p, genesis, and application configuration files",
Expand Down Expand Up @@ -115,7 +115,7 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, mbm sdk.ModuleBasicManager)
},
}

cmd.Flags().String(cli.HomeFlag, app.DefaultNodeHome, "node's home directory")
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().String(client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")

Expand Down
53 changes: 27 additions & 26 deletions x/genutil/client/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cli
import (
"bytes"
"io"
"io/ioutil"
"os"
"testing"
"time"
Expand All @@ -16,9 +15,10 @@ import (
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/mock"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
)
Expand All @@ -28,42 +28,41 @@ var testMbm = sdk.NewModuleBasicManager(genutil.AppModuleBasic{})
func TestInitCmd(t *testing.T) {
defer server.SetupViper(t)()
defer setupClientHome(t)()
home, cleanup := tests.NewTestCaseDir(t)
defer cleanup()

logger := log.NewNopLogger()
cfg, err := tcmd.ParseConfig()
require.Nil(t, err)

ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
cmd := InitCmd(ctx, cdc, testMbm)
cdc := makeCodec()
cmd := InitCmd(ctx, cdc, testMbm, home)

require.NoError(t, cmd.RunE(nil, []string{"gaianode-test"}))
}

func setupClientHome(t *testing.T) func() {
clientDir, err := ioutil.TempDir("", "mock-sdk-cmd")
require.Nil(t, err)
clientDir, cleanup := tests.NewTestCaseDir(t)
viper.Set(flagClientHome, clientDir)
return func() {
if err := os.RemoveAll(clientDir); err != nil {
// TODO: Handle with #870
panic(err)
}
}
return cleanup
}

func TestEmptyState(t *testing.T) {
defer server.SetupViper(t)()
defer setupClientHome(t)()

home, cleanup := tests.NewTestCaseDir(t)
defer cleanup()

logger := log.NewNopLogger()
cfg, err := tcmd.ParseConfig()
require.Nil(t, err)

ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
cdc := makeCodec()

cmd := InitCmd(ctx, cdc, testMbm)
cmd := InitCmd(ctx, cdc, testMbm, home)
require.NoError(t, cmd.RunE(nil, []string{"gaianode-test"}))

old := os.Stdout
Expand Down Expand Up @@ -93,20 +92,17 @@ func TestEmptyState(t *testing.T) {
}

func TestStartStandAlone(t *testing.T) {
home, err := ioutil.TempDir("", "mock-sdk-cmd")
require.Nil(t, err)
defer func() {
os.RemoveAll(home)
}()
home, cleanup := tests.NewTestCaseDir(t)
defer cleanup()
viper.Set(cli.HomeFlag, home)
defer setupClientHome(t)()

logger := log.NewNopLogger()
cfg, err := tcmd.ParseConfig()
require.Nil(t, err)
ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
initCmd := InitCmd(ctx, cdc, testMbm)
cdc := makeCodec()
initCmd := InitCmd(ctx, cdc, testMbm, home)
require.NoError(t, initCmd.RunE(nil, []string{"gaianode-test"}))

app, err := mock.NewApp(home, logger)
Expand All @@ -126,11 +122,8 @@ func TestStartStandAlone(t *testing.T) {
}

func TestInitNodeValidatorFiles(t *testing.T) {
home, err := ioutil.TempDir("", "mock-sdk-cmd")
require.Nil(t, err)
defer func() {
os.RemoveAll(home)
}()
home, cleanup := tests.NewTestCaseDir(t)
defer cleanup()
viper.Set(cli.HomeFlag, home)
viper.Set(client.FlagName, "moniker")
cfg, err := tcmd.ParseConfig()
Expand All @@ -140,3 +133,11 @@ func TestInitNodeValidatorFiles(t *testing.T) {
require.NotEqual(t, "", nodeID)
require.NotEqual(t, 0, len(valPubKey.Bytes()))
}

// custom tx codec
func makeCodec() *codec.Codec {
var cdc = codec.New()
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
return cdc
}

0 comments on commit ca4363f

Please sign in to comment.