Skip to content

Commit

Permalink
x/msgfee: configuration is genesis is optional (#1083)
Browse files Browse the repository at this point in the history
When initializing `x/msgfee` extension from genesis, allow for no
configuration. Previously such setup would fail initialization. Now it
quietly ignores missing configuration.

fix #1082
  • Loading branch information
husio authored Dec 17, 2019
1 parent 82947ab commit 7a947c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## HEAD

- `x/msgfee` configuration in genesis is optional. Not providing it no longer
fails initialization.
- a new `orm.IterAll` iterator was implemented to allow iterating through all
entities of a given bucket.
- a `bnsd` data migration was added that rewrites all accounts from
Expand Down
3 changes: 2 additions & 1 deletion x/msgfee/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func (*Initializer) FromGenesis(opts weave.Options, params weave.GenesisParams,
}
}

if err := gconf.InitConfig(kv, opts, "msgfee", &Configuration{}); err != nil {
// We allow to initialize configuration but it is not required.
if err := gconf.InitConfig(kv, opts, "msgfee", &Configuration{}); err != nil && !errors.ErrNotFound.Is(err) {
return errors.Wrap(err, "init config")
}

Expand Down
15 changes: 15 additions & 0 deletions x/msgfee/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ func TestGenesisWithInvalidFee(t *testing.T) {
}

}

func TestGenesisConfigurationIsOptional(t *testing.T) {
const genesis = `{ "msgfee": [ ], "conf": {} }`
var opts weave.Options
if err := json.Unmarshal([]byte(genesis), &opts); err != nil {
t.Fatalf("cannot unmarshal genesis: %s", err)
}

db := store.MemStore()
migration.MustInitPkg(db, "msgfee")
var ini Initializer
if err := ini.FromGenesis(opts, weave.GenesisParams{}, db); err != nil {
t.Fatalf("cannot load genesis: %s", err)
}
}

0 comments on commit 7a947c6

Please sign in to comment.