diff --git a/CHANGELOG.md b/CHANGELOG.md index 98eef848d..2f6c756c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## UNRELEASED +FEATURES + +* Context now has access to the application-configured logger + BREAKING CHANGES * types/rational now extends big.Rat @@ -27,7 +31,6 @@ FEATURES: * Create genesis transactions with `gaiad init gen-tx` * New genesis account keys are automatically added to the client keybase (introduce `--client-home` flag) * Initialize with genesis txs using `--gen-txs` flag -* Context now has access to the application-configured logger BREAKING CHANGES diff --git a/examples/democoin/x/cool/keeper_test.go b/examples/democoin/x/cool/keeper_test.go index 9aca3cc2a..d497dee69 100644 --- a/examples/democoin/x/cool/keeper_test.go +++ b/examples/democoin/x/cool/keeper_test.go @@ -30,7 +30,7 @@ func TestCoolKeeper(t *testing.T) { auth.RegisterBaseAccount(cdc) am := auth.NewAccountMapper(cdc, capKey, &auth.BaseAccount{}) - ctx := sdk.NewContext(ms, abci.Header{}, false, nil) + ctx := sdk.NewContext(ms, abci.Header{}, false, nil, nil) ck := bank.NewKeeper(am) keeper := NewKeeper(capKey, ck, DefaultCodespace) diff --git a/types/context_test.go b/types/context_test.go index d813516f0..ec5faab44 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" @@ -13,6 +14,33 @@ import ( abci "github.com/tendermint/abci/types" ) +type MockLogger struct { + logs *[]string +} + +func NewMockLogger() MockLogger { + logs := make([]string, 0) + return MockLogger{ + &logs, + } +} + +func (l MockLogger) Debug(msg string, kvs ...interface{}) { + *l.logs = append(*l.logs, msg) +} + +func (l MockLogger) Info(msg string, kvs ...interface{}) { + *l.logs = append(*l.logs, msg) +} + +func (l MockLogger) Error(msg string, kvs ...interface{}) { + *l.logs = append(*l.logs, msg) +} + +func (l MockLogger) With(kvs ...interface{}) log.Logger { + panic("not implemented") +} + func TestContextGetOpShouldNeverPanic(t *testing.T) { var ms types.MultiStore ctx := types.NewContext(ms, abci.Header{}, false, nil, log.NewNopLogger()) @@ -64,7 +92,10 @@ func TestCacheContext(t *testing.T) { func TestLogContext(t *testing.T) { key := types.NewKVStoreKey(t.Name()) ctx := defaultContext(key) + logger := NewMockLogger() + ctx = ctx.WithLogger(logger) ctx.Logger().Debug("debug") ctx.Logger().Info("info") ctx.Logger().Error("error") + require.Equal(t, *logger.logs, []string{"debug", "info", "error"}) }