diff --git a/app/genesis_test.go b/app/genesis_test.go index 4707d8c4ee..a519bc9982 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -26,7 +26,7 @@ func TestLoadGenesisDoNotFailIfAppOptionsAreMissing(t *testing.T) { require.Nil(t, err, "%+v", err) app := NewBaseApp(store, DefaultHandler("mycoin"), nil) - err = genesis.LoadGenesis(app, "./testdata/genesis3.json") + err = genesis.Load(app, "./testdata/genesis3.json") require.Nil(t, err, "%+v", err) } @@ -38,7 +38,7 @@ func TestLoadGenesisFailsWithUnknownOptions(t *testing.T) { require.Nil(err, "%+v", err) app := NewBaseApp(store, DefaultHandler("mycoin"), nil) - err = genesis.LoadGenesis(app, genesisFilepath) + err = genesis.Load(app, genesisFilepath) require.NotNil(err, "%+v", err) } @@ -51,7 +51,7 @@ func TestLoadGenesisAccountAddress(t *testing.T) { require.Nil(err, "%+v", err) app := NewBaseApp(store, DefaultHandler("mycoin"), nil) - err = genesis.LoadGenesis(app, genesisAcctFilepath) + err = genesis.Load(app, genesisAcctFilepath) require.Nil(err, "%+v", err) // check the chain id @@ -96,6 +96,6 @@ func TestLoadGenesisAccountInconsistentAddress(t *testing.T) { store, err := MockStoreApp("genesis", logger) require.Nil(err, "%+v", err) app := NewBaseApp(store, DefaultHandler("mycoin"), nil) - err = genesis.LoadGenesis(app, genesisBadAcctFilepath) + err = genesis.Load(app, genesisBadAcctFilepath) require.NotNil(err) } diff --git a/genesis/parse.go b/genesis/parse.go index f0eefd2138..6a183464c5 100644 --- a/genesis/parse.go +++ b/genesis/parse.go @@ -24,10 +24,10 @@ type InitStater interface { InitState(module, key, value string) (string, error) } -// LoadGenesis parses the genesis file and sets the initial +// Load parses the genesis file and sets the initial // state based on that -func LoadGenesis(app InitStater, filePath string) error { - opts, err := GetGenesisOptions(filePath) +func Load(app InitStater, filePath string) error { + opts, err := GetOptions(filePath) if err != nil { return err } @@ -43,10 +43,10 @@ func LoadGenesis(app InitStater, filePath string) error { return nil } -// GetGenesisOptions parses the genesis file in a format +// GetOptions parses the genesis file in a format // that can easily be handed into InitStaters -func GetGenesisOptions(path string) ([]Option, error) { - genDoc, err := loadGenesis(path) +func GetOptions(path string) ([]Option, error) { + genDoc, err := load(path) if err != nil { return nil, err } @@ -79,38 +79,38 @@ type keyValue struct { Value string `json:"value"` } -// FullGenesisDoc - includes tendermint (in the json, we ignore here) -type FullGenesisDoc struct { - ChainID string `json:"chain_id"` - AppOptions *GenesisDoc `json:"app_options"` +// FullDoc - includes tendermint (in the json, we ignore here) +type FullDoc struct { + ChainID string `json:"chain_id"` + AppOptions *Doc `json:"app_options"` } -// GenesisDoc - All genesis values -type GenesisDoc struct { +// Doc - All genesis values +type Doc struct { Accounts []json.RawMessage `json:"accounts"` PluginOptions []json.RawMessage `json:"plugin_options"` pluginOptions []keyValue // unmarshaled rawmessages } -func loadGenesis(filePath string) (*FullGenesisDoc, error) { +func load(filePath string) (*FullDoc, error) { bytes, err := cmn.ReadFile(filePath) if err != nil { return nil, errors.Wrap(err, "loading genesis file") } // the basecoin genesis go-wire/data :) - genDoc := new(FullGenesisDoc) + genDoc := new(FullDoc) err = json.Unmarshal(bytes, genDoc) if err != nil { return nil, errors.Wrap(err, "unmarshaling genesis file") } if genDoc.AppOptions == nil { - genDoc.AppOptions = new(GenesisDoc) + genDoc.AppOptions = new(Doc) } - pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions) + pluginOpts, err := parseList(genDoc.AppOptions.PluginOptions) if err != nil { return nil, err } @@ -118,7 +118,7 @@ func loadGenesis(filePath string) (*FullGenesisDoc, error) { return genDoc, nil } -func parseGenesisList(kvzIn []json.RawMessage) (kvz []keyValue, err error) { +func parseList(kvzIn []json.RawMessage) (kvz []keyValue, err error) { if len(kvzIn)%2 != 0 { return nil, errors.New("genesis cannot have an odd number of items. Format = [key1, value1, key2, value2, ...]") } diff --git a/genesis/parse_test.go b/genesis/parse_test.go index 5c81d794cc..822e2630ac 100644 --- a/genesis/parse_test.go +++ b/genesis/parse_test.go @@ -13,18 +13,18 @@ import ( const genesisFilepath = "./testdata/genesis.json" -func TestParseGenesisList(t *testing.T) { +func TestParseList(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-wire/data :) - genDoc := new(FullGenesisDoc) + genDoc := new(FullDoc) err = json.Unmarshal(bytes, genDoc) require.Nil(err, "unmarshaling genesis file %+v", err) - pluginOpts, err := parseGenesisList(genDoc.AppOptions.PluginOptions) + pluginOpts, err := parseList(genDoc.AppOptions.PluginOptions) require.Nil(err, "%+v", err) genDoc.AppOptions.pluginOptions = pluginOpts @@ -34,10 +34,10 @@ func TestParseGenesisList(t *testing.T) { assert.Equal(genDoc.AppOptions.pluginOptions[1].Value, "value2") } -func TestGetGenesisOptions(t *testing.T) { +func TestGetOptions(t *testing.T) { assert, require := assert.New(t), require.New(t) - opts, err := GetGenesisOptions(genesisFilepath) + opts, err := GetOptions(genesisFilepath) require.Nil(err, "loading genesis file %+v", err) require.Equal(4, len(opts)) diff --git a/server/commands/start.go b/server/commands/start.go index a7f41a329b..5580ce3036 100644 --- a/server/commands/start.go +++ b/server/commands/start.go @@ -120,7 +120,7 @@ func start(rootDir string, basecoinApp *app.BaseApp) error { // If genesis file exists, set key-value options genesisFile := path.Join(rootDir, "genesis.json") if _, err := os.Stat(genesisFile); err == nil { - err = genesis.LoadGenesis(basecoinApp, genesisFile) + err = genesis.Load(basecoinApp, genesisFile) if err != nil { return errors.Errorf("Error in LoadGenesis: %v\n", err) }