Skip to content

Commit

Permalink
Merge pull request #102 from tendermint/bugfix/101-genesis-without-ap…
Browse files Browse the repository at this point in the history
…p-options

fix panic when genesis file does not include app_options (Fixes #101)
  • Loading branch information
ebuchman authored Jun 5, 2017
2 parents 2655bf8 + e242345 commit 7624c66
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 7624c66

Please sign in to comment.