diff --git a/CHANGELOG.md b/CHANGELOG.md index 2012ec84a1..d0c77c03bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ BREAKING CHANGES: - removed `example-plugin`, put `counter` inside `docs/guide` ENHANCEMENTS: +- `basecoin init` support `--chain-id` - intergrates tendermint 0.10.0 (not the rc-2, but the real thing) - commands return error code (1) on failure for easier script testing - add `reset_all` to basecli, and never delete keys on `init` diff --git a/cmd/basecoin/commands/init.go b/cmd/basecoin/commands/init.go index 3fb627138e..e9f20247ac 100644 --- a/cmd/basecoin/commands/init.go +++ b/cmd/basecoin/commands/init.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "path" "github.com/spf13/cobra" ) @@ -17,6 +18,18 @@ var ( } ) +//flags +var ( + chainIDFlag string +) + +func init() { + flags := []Flag2Register{ + {&chainIDFlag, "chain-id", "test_chain_id", "Chain ID"}, + } + RegisterFlags(InitCmd, flags) +} + // returns 1 iff it set a file, otherwise 0 (so we can add them) func setupFile(path, data string, perm os.FileMode) (int, error) { _, err := os.Stat(path) @@ -47,7 +60,7 @@ func initCmd(cmd *cobra.Command, args []string) error { privValFile := cfg.PrivValidatorFile() keyFile := path.Join(cfg.RootDir, "key.json") - mod1, err := setupFile(genesisFile, GetGenesisJSON(userAddr), 0644) + mod1, err := setupFile(genesisFile, GetGenesisJSON(chainIDFlag, userAddr), 0644) if err != nil { return err } @@ -55,7 +68,7 @@ func initCmd(cmd *cobra.Command, args []string) error { if err != nil { return err } - mod3, err := setupFile(key1File, KeyJSON, 0400) + mod3, err := setupFile(keyFile, KeyJSON, 0400) if err != nil { return err } @@ -89,10 +102,10 @@ var PrivValJSON = `{ // GetGenesisJSON returns a new tendermint genesis with Basecoin app_options // that grant a large amount of "mycoin" to a single address // TODO: A better UX for generating genesis files -func GetGenesisJSON(addr string) string { +func GetGenesisJSON(chainID, addr string) string { return fmt.Sprintf(`{ "app_hash": "", - "chain_id": "test_chain_id", + "chain_id": "%s", "genesis_time": "0001-01-01T00:00:00.000Z", "validators": [ { @@ -115,7 +128,7 @@ func GetGenesisJSON(addr string) string { ] }] } -}`, addr) +}`, chainID, addr) } // TODO: remove this once not needed for relay diff --git a/docs/guide/counter/cmd/counter/main.go b/docs/guide/counter/cmd/counter/main.go index 0da66c12f6..c877a51eda 100644 --- a/docs/guide/counter/cmd/counter/main.go +++ b/docs/guide/counter/cmd/counter/main.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tmlibs/cli" - "github.com/tendermint/basecoin/cmd/commands" + "github.com/tendermint/basecoin/cmd/basecoin/commands" "github.com/tendermint/basecoin/docs/guide/counter/plugins/counter" "github.com/tendermint/basecoin/types" ) diff --git a/tests/cli/common.sh b/tests/cli/common.sh index 017da897a4..0b507e5969 100644 --- a/tests/cli/common.sh +++ b/tests/cli/common.sh @@ -24,13 +24,7 @@ initServer() { assertNotNull "no chain" $2 CHAIN=$2 SERVER_LOG=$1/${SERVER_EXE}.log - ${SERVER_EXE} init --home=$SERVE_DIR >>$SERVER_LOG - - #change the genesis to the first account - GENKEY=$(${CLIENT_EXE} keys get ${RICH} -o json | jq .pubkey.data) - GENJSON=$(cat $SERVE_DIR/genesis.json) - echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY \ - | jq ".chain_id=\"$2\"" > $SERVE_DIR/genesis.json + ${SERVER_EXE} init --chain-id $CHAIN $(${CLIENT_EXE} keys get ${RICH} | awk '{print $2}') --home=$SERVE_DIR >>$SERVER_LOG # optionally set the port if [ -n "$3" ]; then