BCHOME default dir change
int int int int
This commit is contained in:
parent
02b4fd5f17
commit
b60845c818
12
app/app.go
12
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) {
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user