Skip to content

Commit

Permalink
fix panic when genesis file does not include app_options (Fixes #101)
Browse files Browse the repository at this point in the history
  • Loading branch information
melekes committed Jun 5, 2017
1 parent 2655bf8 commit e242345
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ 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"
)

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)

Expand Down
3 changes: 3 additions & 0 deletions app/testdata/genesis3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"chain_id": "foo_bar_chain"
}

0 comments on commit e242345

Please sign in to comment.