From e242345d03cceecf5ea6f3c0952863f3c0b96f00 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 5 Jun 2017 15:11:46 +0300 Subject: [PATCH] fix panic when genesis file does not include app_options (Fixes #101) --- app/genesis.go | 5 +++++ app/genesis_test.go | 9 ++++++++- app/testdata/genesis3.json | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 app/testdata/genesis3.json diff --git a/app/genesis.go b/app/genesis.go index fa6a5ac3053..3901fa68985 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -37,6 +37,7 @@ func (app *Basecoin) LoadGenesis(path string) error { r := app.SetOption(kv.Key, kv.Value) app.logger.Info("Done setting Plugin key-value pair via SetOption", "result", r, "k", kv.Key, "v", kv.Value) } + return nil } @@ -71,6 +72,10 @@ func loadGenesis(filePath string) (*FullGenesisDoc, error) { return nil, errors.Wrap(err, "unmarshaling genesis file") } + if genDoc.AppOptions == nil { + genDoc.AppOptions = new(GenesisDoc) + } + pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions) if err != nil { return nil, err diff --git a/app/genesis_test.go b/app/genesis_test.go index b2a590bcf3d..dc398afd971 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/basecoin/types" - "github.com/tendermint/go-crypto" + crypto "github.com/tendermint/go-crypto" eyescli "github.com/tendermint/merkleeyes/client" cmn "github.com/tendermint/tmlibs/common" ) @@ -16,6 +16,13 @@ import ( const genesisFilepath = "./testdata/genesis.json" const genesisAcctFilepath = "./testdata/genesis2.json" +func TestLoadGenesisDoNotFailIfAppOptionsAreMissing(t *testing.T) { + eyesCli := eyescli.NewLocalClient("", 0) + app := NewBasecoin(eyesCli) + err := app.LoadGenesis("./testdata/genesis3.json") + require.Nil(t, err, "%+v", err) +} + func TestLoadGenesis(t *testing.T) { assert, require := assert.New(t), require.New(t) diff --git a/app/testdata/genesis3.json b/app/testdata/genesis3.json new file mode 100644 index 00000000000..b58b1d74025 --- /dev/null +++ b/app/testdata/genesis3.json @@ -0,0 +1,3 @@ +{ + "chain_id": "foo_bar_chain" +}