From 4049c5d24fb5be7d5904fb580ea7b7bea4a3fd95 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Tue, 24 Apr 2018 19:46:39 -0400 Subject: [PATCH] cwgoes comments, bug fix --- server/init.go | 21 +++++++++++++-------- server/test_helpers.go | 24 ------------------------ server/util_test.go | 2 -- 3 files changed, 13 insertions(+), 34 deletions(-) diff --git a/server/init.go b/server/init.go index 68eb7f738a..4420bdf017 100644 --- a/server/init.go +++ b/server/init.go @@ -25,10 +25,9 @@ import ( dbm "github.com/tendermint/tmlibs/db" ) -// TODO flag to retrieve genesis file / config file from a URL? // get cmd to initialize all files for tendermint and application func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { - flagOverwrite, flagPieceFile := "overwrite", "piece-file" + flagOverwrite, flagPieceFile, flagIP := "overwrite", "piece-file", "ip" cmd := &cobra.Command{ Use: "init", Short: "Initialize genesis config, priv-validator file, and p2p-node file", @@ -79,9 +78,12 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { // write the piece file is path specified if viper.GetBool(flagPieceFile) { //create the piece - ip, err := externalIP() - if err != nil { - return err + ip := viper.GetString(flagIP) + if len(ip) == 0 { + ip, err = externalIP() + if err != nil { + return err + } } piece := GenesisPiece{ ChainID: chainID, @@ -90,7 +92,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { AppState: appState, Validators: validators, } - bz, err := cdc.MarshalJSON(piece) + bz, err := wire.MarshalJSONIndent(cdc, piece) if err != nil { return err } @@ -107,6 +109,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { cmd.Flags().BoolP(flagPieceFile, "a", false, "create an append file (under [--home]/[nodeID]piece.json) for others to import") } cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the config file") + cmd.Flags().String(flagIP, "", "external facing IP to use if left blank IP will be retrieved from this machine") cmd.Flags().AddFlagSet(appInit.Flags) return cmd } @@ -158,6 +161,7 @@ func FromPiecesCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Comman // append a genesis-piece func appendPiece(ctx *Context, cdc *wire.Codec, appInit AppInit, nodeKeyFile, genFile string) filepath.WalkFunc { return func(pieceFile string, _ os.FileInfo, err error) error { + fmt.Printf("debug pieceFile: %v\n", pieceFile) if err != nil { return err } @@ -202,7 +206,7 @@ func appendPiece(ctx *Context, cdc *wire.Codec, appInit AppInit, nodeKeyFile, ge return err } if piece.ChainID != genChainID { - return fmt.Errorf("piece chain id's are mismatched, %s != %s", piece.ChainID, genMap["chain_id"]) + return fmt.Errorf("piece chain id's are mismatched, %s != %s", piece.ChainID, genChainID) } // combine the validator set @@ -237,7 +241,8 @@ func appendPiece(ctx *Context, cdc *wire.Codec, appInit AppInit, nodeKeyFile, ge if len(ctx.Config.P2P.PersistentPeers) == 0 { comma = "" } - ctx.Config.P2P.PersistentPeers += fmt.Sprintf("%s%s@%s", comma, piece.NodeID, piece.IP) + //newPeer := fmt.Sprintf("%s%s@%s:46656", comma, piece.NodeID, piece.IP) + ctx.Config.P2P.PersistentPeers += fmt.Sprintf("%s%s@%s:46656", comma, piece.NodeID, piece.IP) configFilePath := filepath.Join(viper.GetString("home"), "config", "config.toml") //TODO this is annoying should be easier to get cfg.WriteConfigFile(configFilePath, ctx.Config) diff --git a/server/test_helpers.go b/server/test_helpers.go index 55b6caf43b..382c778787 100644 --- a/server/test_helpers.go +++ b/server/test_helpers.go @@ -37,30 +37,6 @@ func setupViper(t *testing.T) func() { } } -// Begin the server pass up the channel to close -// NOTE pass up the channel so it can be closed at the end of the process -//func StartServer(t *testing.T, cdc *wire.Codec) chan error { -//defer setupViper(t)() - -//cfg, err := tcmd.ParseConfig() -//require.Nil(t, err) - -//// init server -//ctx := NewContext(cfg, log.NewNopLogger()) -//initCmd := InitCmd(ctx, cdc, mock.GenAppParams) -//err = initCmd.RunE(nil, nil) -//require.NoError(t, err) - -//// start server -//viper.Set(flagWithTendermint, true) -//startCmd := StartCmd(mock.NewApp, ctx) -//startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address -//startCmd.Flags().Set("rpc.laddr", FreeTCPAddr(t)) // set to a new free address -//timeout := time.Duration(3) * time.Second - -//return RunOrTimeout(startCmd, timeout, t) -//} - // Run or Timout RunE of command passed in func RunOrTimeout(cmd *cobra.Command, timeout time.Duration, t *testing.T) chan error { done := make(chan error) diff --git a/server/util_test.go b/server/util_test.go index a21fe38828..13f8ad5dbc 100644 --- a/server/util_test.go +++ b/server/util_test.go @@ -9,8 +9,6 @@ import ( "github.com/stretchr/testify/require" ) -//func AppendJSON(cdc *wire.Codec, baseJSON []byte, key string, value json.RawMessage) (appended []byte, err error) { - func TestAppendJSON(t *testing.T) { cdc := wire.NewCodec()