json testing, addressed init option PR comments
This commit is contained in:
parent
748a1e97e4
commit
4ac089f084
3
Makefile
3
Makefile
|
@ -3,7 +3,7 @@ GOTOOLS = github.com/mitchellh/gox \
|
||||||
github.com/rigelrozanski/shelldown/cmd/shelldown
|
github.com/rigelrozanski/shelldown/cmd/shelldown
|
||||||
TUTORIALS=$(shell find docs/guide -name "*md" -type f)
|
TUTORIALS=$(shell find docs/guide -name "*md" -type f)
|
||||||
|
|
||||||
EXAMPLES := counter eyes basecoin
|
EXAMPLES := counter eyes basecoin
|
||||||
INSTALL_EXAMPLES := $(addprefix install_,${EXAMPLES})
|
INSTALL_EXAMPLES := $(addprefix install_,${EXAMPLES})
|
||||||
TEST_EXAMPLES := $(addprefix testex_,${EXAMPLES})
|
TEST_EXAMPLES := $(addprefix testex_,${EXAMPLES})
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ test_unit:
|
||||||
@go test `glide novendor`
|
@go test `glide novendor`
|
||||||
|
|
||||||
test_cli: $(TEST_EXAMPLES)
|
test_cli: $(TEST_EXAMPLES)
|
||||||
|
./tests/cli/init-server.sh
|
||||||
# sudo apt-get install jq
|
# sudo apt-get install jq
|
||||||
# wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2"
|
# wget "https://raw.githubusercontent.com/kward/shunit2/master/source/2.1/src/shunit2"
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
InitCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID")
|
InitCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID")
|
||||||
InitCmd.Flags().StringSlice(FlagOption, []string{}, "Genesis option in the format <app>/<option>/<value>")
|
InitCmd.Flags().StringSliceP(FlagOption, "p", []string{}, "Genesis option in the format <app>/<option>/<value>")
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns 1 iff it set a file, otherwise 0 (so we can add them)
|
// returns 1 iff it set a file, otherwise 0 (so we can add them)
|
||||||
|
@ -67,12 +67,13 @@ func initCmd(cmd *cobra.Command, args []string) error {
|
||||||
return errors.New("Address must be 20-bytes in hex")
|
return errors.New("Address must be 20-bytes in hex")
|
||||||
}
|
}
|
||||||
|
|
||||||
var options []string
|
|
||||||
var optionsStr string
|
var optionsStr string
|
||||||
sep := ",\n "
|
|
||||||
optionsRaw := viper.GetStringSlice(FlagOption)
|
optionsRaw := viper.GetStringSlice(FlagOption)
|
||||||
if len(optionsRaw) > 0 {
|
if len(optionsRaw) > 0 {
|
||||||
optionsStr = sep
|
|
||||||
|
var options []string
|
||||||
|
sep := ",\n "
|
||||||
|
|
||||||
for i := 0; i < len(optionsRaw); i++ {
|
for i := 0; i < len(optionsRaw); i++ {
|
||||||
s := strings.SplitN(optionsRaw[i], "/", 3)
|
s := strings.SplitN(optionsRaw[i], "/", 3)
|
||||||
if len(s) != 3 {
|
if len(s) != 3 {
|
||||||
|
@ -87,8 +88,8 @@ func initCmd(cmd *cobra.Command, args []string) error {
|
||||||
option := `"` + s[0] + `/` + s[1] + `", ` + s[2]
|
option := `"` + s[0] + `/` + s[1] + `", ` + s[2]
|
||||||
options = append(options, option)
|
options = append(options, option)
|
||||||
}
|
}
|
||||||
|
optionsStr = sep + strings.Join(options[:], sep)
|
||||||
}
|
}
|
||||||
optionsStr += strings.Join(options[:], sep)
|
|
||||||
|
|
||||||
genesis := GetGenesisJSON(viper.GetString(FlagChainID), userAddr, optionsStr)
|
genesis := GetGenesisJSON(viper.GetString(FlagChainID), userAddr, optionsStr)
|
||||||
return CreateGenesisValidatorFiles(cfg, genesis, cmd.Root().Name())
|
return CreateGenesisValidatorFiles(cfg, genesis, cmd.Root().Name())
|
||||||
|
|
|
@ -35,6 +35,7 @@ func preRunSetup(cmd *cobra.Command, args []string) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetUpRoot - initialize the root command
|
||||||
func SetUpRoot(cmd *cobra.Command) {
|
func SetUpRoot(cmd *cobra.Command) {
|
||||||
cmd.PersistentPreRunE = preRunSetup
|
cmd.PersistentPreRunE = preRunSetup
|
||||||
cmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level")
|
cmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level")
|
||||||
|
|
|
@ -8,24 +8,36 @@ test01initOption() {
|
||||||
rm -rf "$BASE"
|
rm -rf "$BASE"
|
||||||
mkdir -p "$BASE"
|
mkdir -p "$BASE"
|
||||||
|
|
||||||
SERVER="${BASE}/server"
|
SERVE_DIR="${BASE}/server"
|
||||||
GENESIS_FILE=${SERVER}/genesis.json
|
GENESIS_FILE=${SERVE_DIR}/genesis.json
|
||||||
HEX="deadbeef1234deadbeef1234deadbeef1234aaaa"
|
HEX="deadbeef1234deadbeef1234deadbeef1234aaaa"
|
||||||
|
|
||||||
${SERVER_EXE} init ${HEX} --home="$SERVER" --option=app1/key1/val1 --option=app2/key2/val2 >/dev/null
|
${SERVER_EXE} init ${HEX} --home="$SERVE_DIR" -p=app1/key1/val1 -p='"app2/key2/{""name"": ""joe"", ""age"": ""100""}"' >/dev/null
|
||||||
if ! assertTrue "line=${LINENO}" $?; then return 1; fi
|
if ! assertTrue "line=${LINENO}" $?; then return 1; fi
|
||||||
|
|
||||||
OPTION1KEY=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[2]')
|
OPTION1KEY=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[2]')
|
||||||
OPTION1VAL=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[3]')
|
OPTION1VAL=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[3]')
|
||||||
OPTION2KEY=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[4]')
|
OPTION2KEY=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[4]')
|
||||||
OPTION2VAL=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[5]')
|
OPTION2VAL=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[5]')
|
||||||
|
OPTION2VALEXPECTED=$(echo '{"name": "joe", "age": "100"}' | jq '.')
|
||||||
|
|
||||||
assertEquals "line=${LINENO}" '"app1/key1"' $OPTION1KEY
|
assertEquals "line=${LINENO}" '"app1/key1"' $OPTION1KEY
|
||||||
assertEquals "line=${LINENO}" '"val1"' $OPTION1VAL
|
assertEquals "line=${LINENO}" '"val1"' $OPTION1VAL
|
||||||
assertEquals "line=${LINENO}" '"app2/key2"' $OPTION2KEY
|
assertEquals "line=${LINENO}" '"app2/key2"' $OPTION2KEY
|
||||||
assertEquals "line=${LINENO}" '"val2"' $OPTION2VAL
|
assertEquals "line=${LINENO}" "$OPTION2VALEXPECTED" "$OPTION2VAL"
|
||||||
|
}
|
||||||
|
|
||||||
|
test02runServer() {
|
||||||
|
# Attempt to begin the server with the custom genesis
|
||||||
|
SERVER_LOG=$BASE/${SERVER_EXE}.log
|
||||||
|
startServer $SERVE_DIR $SERVER_LOG
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeTearDown() {
|
||||||
|
quickTearDown
|
||||||
}
|
}
|
||||||
|
|
||||||
# load and run these tests with shunit2!
|
# load and run these tests with shunit2!
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
CLI_DIR=$GOPATH/src/github.com/cosmos/cosmos-sdk/tests/cli
|
||||||
. $DIR/shunit2
|
. $CLI_DIR/common.sh
|
||||||
|
. $CLI_DIR/shunit2
|
||||||
|
|
Loading…
Reference in New Issue