Merge pull request #1603: Adding option functions to NewBaseApp
* adding option functions to baseapp constructor * Added simple test and changed godoc * remove unrelated changelog updates
This commit is contained in:
parent
efa003db9a
commit
338c7b5e4c
|
@ -21,6 +21,7 @@ BREAKING CHANGES
|
||||||
* [auth] Removed MsgChangePubKey
|
* [auth] Removed MsgChangePubKey
|
||||||
* [auth] Removed SetPubKey from account mapper
|
* [auth] Removed SetPubKey from account mapper
|
||||||
* [auth] AltBytes renamed to Memo, now a string, max 100 characters, costs a bit of gas
|
* [auth] AltBytes renamed to Memo, now a string, max 100 characters, costs a bit of gas
|
||||||
|
* [baseapp] NewBaseApp now takes option functions as parameters
|
||||||
* [types] `GetMsg()` -> `GetMsgs()` as txs wrap many messages
|
* [types] `GetMsg()` -> `GetMsgs()` as txs wrap many messages
|
||||||
* [types] Removed GetMemo from Tx (it is still on StdTx)
|
* [types] Removed GetMemo from Tx (it is still on StdTx)
|
||||||
* [types] renamed rational.Evaluate to rational.Round{Int64, Int}
|
* [types] renamed rational.Evaluate to rational.Round{Int64, Int}
|
||||||
|
|
|
@ -73,7 +73,8 @@ var _ abci.Application = (*BaseApp)(nil)
|
||||||
|
|
||||||
// Create and name new BaseApp
|
// Create and name new BaseApp
|
||||||
// NOTE: The db is used to store the version number for now.
|
// NOTE: The db is used to store the version number for now.
|
||||||
func NewBaseApp(name string, cdc *wire.Codec, logger log.Logger, db dbm.DB) *BaseApp {
|
// Accepts variable number of option functions, which act on the BaseApp to set configuration choices
|
||||||
|
func NewBaseApp(name string, cdc *wire.Codec, logger log.Logger, db dbm.DB, options ...func(*BaseApp)) *BaseApp {
|
||||||
app := &BaseApp{
|
app := &BaseApp{
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -86,6 +87,9 @@ func NewBaseApp(name string, cdc *wire.Codec, logger log.Logger, db dbm.DB) *Bas
|
||||||
}
|
}
|
||||||
// Register the undefined & root codespaces, which should not be used by any modules
|
// Register the undefined & root codespaces, which should not be used by any modules
|
||||||
app.codespacer.RegisterOrPanic(sdk.CodespaceRoot)
|
app.codespacer.RegisterOrPanic(sdk.CodespaceRoot)
|
||||||
|
for _, option := range options {
|
||||||
|
option(app)
|
||||||
|
}
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,21 @@ func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, exp
|
||||||
require.Equal(t, expectedID, lastID)
|
require.Equal(t, expectedID, lastID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOptionFunction(t *testing.T) {
|
||||||
|
logger := defaultLogger()
|
||||||
|
db := dbm.NewMemDB()
|
||||||
|
codec := wire.NewCodec()
|
||||||
|
registerTestCodec(codec)
|
||||||
|
bap := NewBaseApp("starting name", codec, logger, db, testChangeNameHelper("new name"))
|
||||||
|
require.Equal(t, bap.name, "new name", "BaseApp should have had name changed via option function")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testChangeNameHelper(name string) func(*BaseApp) {
|
||||||
|
return func(bap *BaseApp) {
|
||||||
|
bap.name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test that the app hash is static
|
// Test that the app hash is static
|
||||||
// TODO: https://github.com/cosmos/cosmos-sdk/issues/520
|
// TODO: https://github.com/cosmos/cosmos-sdk/issues/520
|
||||||
/*func TestStaticAppHash(t *testing.T) {
|
/*func TestStaticAppHash(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue