From b60845c81812be8307960eb994f7128012db7a86 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Sat, 1 Apr 2017 17:31:44 -0400 Subject: [PATCH] BCHOME default dir change int int int int --- app/app.go | 12 ++++++------ app/genesis_test.go | 27 ++++++++++++++++++++++++++- cmd/commands/init.go | 16 ++++++++-------- cmd/commands/utils.go | 6 +++++- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/app/app.go b/app/app.go index f8cc5b739e..fe17736697 100644 --- a/app/app.go +++ b/app/app.go @@ -5,17 +5,17 @@ import ( "strings" abci "github.com/tendermint/abci/types" - sm "github.com/tendermint/basecoin/state" - "github.com/tendermint/basecoin/types" . "github.com/tendermint/go-common" "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" + + sm "github.com/tendermint/basecoin/state" + "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/version" ) const ( - version = "0.1" - maxTxSize = 10240 - + maxTxSize = 10240 PluginNameBase = "base" ) @@ -44,7 +44,7 @@ func (app *Basecoin) GetState() *sm.State { // ABCI::Info func (app *Basecoin) Info() abci.ResponseInfo { - return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version)} + return abci.ResponseInfo{Data: Fmt("Basecoin v%v", version.Version)} } func (app *Basecoin) RegisterPlugin(plugin types.Plugin) { diff --git a/app/genesis_test.go b/app/genesis_test.go index 90f61e152c..74ca22e61b 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -2,20 +2,24 @@ package app import ( "encoding/hex" + "encoding/json" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + cmn "github.com/tendermint/go-common" "github.com/tendermint/go-crypto" eyescli "github.com/tendermint/merkleeyes/client" ) +const genesisFilepath = "./testdata/genesis.json" + func TestLoadGenesis(t *testing.T) { assert, require := assert.New(t), require.New(t) eyesCli := eyescli.NewLocalClient("", 0) app := NewBasecoin(eyesCli) - err := app.LoadGenesis("./testdata/genesis.json") + err := app.LoadGenesis(genesisFilepath) require.Nil(err, "%+v", err) // check the chain id @@ -41,3 +45,24 @@ func TestLoadGenesis(t *testing.T) { assert.EqualValues(pkbyte, epk[:]) } } + +func TestParseGenesisList(t *testing.T) { + assert, require := assert.New(t), require.New(t) + + bytes, err := cmn.ReadFile(genesisFilepath) + require.Nil(err, "loading genesis file %+v", err) + + // the basecoin genesis go-data :) + genDoc := new(FullGenesisDoc) + err = json.Unmarshal(bytes, genDoc) + require.Nil(err, "unmarshaling genesis file %+v", err) + + pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions) + require.Nil(err, "%+v", err) + genDoc.AppOptions.pluginOptions = pluginOpts + + assert.Equal(genDoc.AppOptions.pluginOptions[0].Key, "plugin1/key1") + assert.Equal(genDoc.AppOptions.pluginOptions[1].Key, "plugin1/key2") + assert.Equal(genDoc.AppOptions.pluginOptions[0].Value, "value1") + assert.Equal(genDoc.AppOptions.pluginOptions[1].Value, "value2") +} diff --git a/cmd/commands/init.go b/cmd/commands/init.go index e938ccb2c5..05a76ef8a1 100644 --- a/cmd/commands/init.go +++ b/cmd/commands/init.go @@ -32,22 +32,22 @@ func initCmd(cmd *cobra.Command, args []string) { key2File := path.Join(rootDir, "key2.json") if _, err := os.Stat(privValFile); os.IsNotExist(err) { - err := ioutil.WriteFile(genesisFile, []byte(genesisJSON), 0644) + err := ioutil.WriteFile(genesisFile, []byte(GenesisJSON), 0644) if err != nil { cmn.Exit(fmt.Sprintf("%+v\n", err)) } - err = ioutil.WriteFile(privValFile, []byte(privValJSON), 0400) + err = ioutil.WriteFile(privValFile, []byte(PrivValJSON), 0400) if err != nil { cmn.Exit(fmt.Sprintf("%+v\n", err)) } - err = ioutil.WriteFile(key1File, []byte(key1JSON), 0400) + err = ioutil.WriteFile(key1File, []byte(Key1JSON), 0400) if err != nil { cmn.Exit(fmt.Sprintf("%+v\n", err)) } - err = ioutil.WriteFile(key2File, []byte(key2JSON), 0400) + err = ioutil.WriteFile(key2File, []byte(Key2JSON), 0400) if err != nil { cmn.Exit(fmt.Sprintf("%+v\n", err)) } @@ -58,7 +58,7 @@ func initCmd(cmd *cobra.Command, args []string) { } } -const privValJSON = `{ +var PrivValJSON = `{ "address": "7A956FADD20D3A5B2375042B2959F8AB172A058F", "last_height": 0, "last_round": 0, @@ -75,7 +75,7 @@ const privValJSON = `{ ] }` -const genesisJSON = `{ +var GenesisJSON = `{ "app_hash": "", "chain_id": "test_chain_id", "genesis_time": "0001-01-01T00:00:00.000Z", @@ -105,7 +105,7 @@ const genesisJSON = `{ } }` -const key1JSON = `{ +var Key1JSON = `{ "address": "1B1BE55F969F54064628A63B9559E7C21C925165", "priv_key": { "type": "ed25519", @@ -117,7 +117,7 @@ const key1JSON = `{ } }` -const key2JSON = `{ +var Key2JSON = `{ "address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090", "priv_key": { "type": "ed25519", diff --git a/cmd/commands/utils.go b/cmd/commands/utils.go index f49bfe162d..7f21be9515 100644 --- a/cmd/commands/utils.go +++ b/cmd/commands/utils.go @@ -19,12 +19,16 @@ import ( tmtypes "github.com/tendermint/tendermint/types" ) +//This variable can be overwritten by plugin applications +// if they require a different working directory +var DefaultHome = "basecoin" + func BasecoinRoot(rootDir string) string { if rootDir == "" { rootDir = os.Getenv("BCHOME") } if rootDir == "" { - rootDir = os.Getenv("HOME") + "/.basecoin" + rootDir = os.Getenv("HOME") + "/." + DefaultHome } return rootDir }