Fixed all tests

This commit is contained in:
Ethan Frey 2017-10-16 16:56:20 +02:00
parent 9d1205f8c7
commit c1d36eeb21
6 changed files with 41 additions and 45 deletions

View File

@ -33,9 +33,13 @@ type BaseApp struct {
info *sm.ChainState info *sm.ChainState
*sm.State *sm.State
// cached validator changes from DeliverTx
pending []*abci.Validator pending []*abci.Validator
height uint64
logger log.Logger // height is last committed block, DeliverTx is the next one
height uint64
logger log.Logger
} }
// NewBaseApp creates a data store to handle queries // NewBaseApp creates a data store to handle queries
@ -45,8 +49,9 @@ func NewBaseApp(dbName string, cacheSize int, logger log.Logger) (*BaseApp, erro
return nil, err return nil, err
} }
app := &BaseApp{ app := &BaseApp{
info: sm.NewChainState(),
State: state, State: state,
height: state.LatestHeight(),
info: sm.NewChainState(),
logger: logger, logger: logger,
} }
return app, nil return app, nil
@ -163,14 +168,10 @@ func (app *BaseApp) Commit() (res abci.Result) {
// InitChain - ABCI // InitChain - ABCI
func (app *BaseApp) InitChain(req abci.RequestInitChain) { func (app *BaseApp) InitChain(req abci.RequestInitChain) {
// for _, plugin := range app.plugins.GetList() {
// plugin.InitChain(app.state, validators)
// }
} }
// BeginBlock - ABCI // BeginBlock - ABCI
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) { func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) {
app.height++
} }
// EndBlock - ABCI // EndBlock - ABCI
@ -182,6 +183,9 @@ func (app *BaseApp) EndBlock(height uint64) (res abci.ResponseEndBlock) {
return return
} }
// AddValChange is meant to be called by apps on DeliverTx
// results, this is added to the cache for the endblock
// changeset
func (app *BaseApp) AddValChange(diffs []*abci.Validator) { func (app *BaseApp) AddValChange(diffs []*abci.Validator) {
for _, d := range diffs { for _, d := range diffs {
idx := pubKeyIndex(d, app.pending) idx := pubKeyIndex(d, app.pending)
@ -203,8 +207,6 @@ func pubKeyIndex(val *abci.Validator, list []*abci.Validator) int {
return -1 return -1
} }
//TODO move split key to tmlibs?
// Splits the string at the first '/'. // Splits the string at the first '/'.
// if there are none, assign default module ("base"). // if there are none, assign default module ("base").
func splitKey(key string) (string, string) { func splitKey(key string) (string, string) {

View File

@ -75,7 +75,7 @@ func (app *Basecoin) DeliverTx(txBytes []byte) abci.Result {
ctx := stack.NewContext( ctx := stack.NewContext(
app.GetChainID(), app.GetChainID(),
app.height, app.height+1,
app.Logger().With("call", "delivertx"), app.Logger().With("call", "delivertx"),
) )
res, err := app.handler.DeliverTx(ctx, app.Append(), tx) res, err := app.handler.DeliverTx(ctx, app.Append(), tx)
@ -96,7 +96,7 @@ func (app *Basecoin) CheckTx(txBytes []byte) abci.Result {
ctx := stack.NewContext( ctx := stack.NewContext(
app.GetChainID(), app.GetChainID(),
app.height, app.height+1,
app.Logger().With("call", "checktx"), app.Logger().With("call", "checktx"),
) )
res, err := app.handler.CheckTx(ctx, app.Check(), tx) res, err := app.handler.CheckTx(ctx, app.Check(), tx)

View File

@ -53,25 +53,22 @@ func NewBenchApp(h sdk.Handler, chainID string, n int,
// logger := log.NewFilter(log.NewTMLogger(os.Stdout), log.AllowError()) // logger := log.NewFilter(log.NewTMLogger(os.Stdout), log.AllowError())
// logger = log.NewTracingLogger(logger) // logger = log.NewTracingLogger(logger)
// TODO: disk writing dbDir, cache := "", 0
var store *app.Store
var err error
if persist { if persist {
tmpDir, _ := ioutil.TempDir("", "bc-app-benchmark") dbDir, _ = ioutil.TempDir("", "bc-app-benchmark")
store, err = app.NewStore(tmpDir, 500, logger) cache = 500
} else {
store, err = app.NewStore("", 0, logger)
} }
app, err := app.NewBasecoin(
h,
dbDir,
cache,
logger.With("module", "app"),
)
if err != nil { if err != nil {
panic(err) panic(err)
} }
app := app.NewBasecoin(
h,
store,
logger.With("module", "app"),
)
res := app.InitState("base/chain_id", chainID) res := app.InitState("base/chain_id", chainID)
if res != "Success" { if res != "Success" {
panic("cannot set chain") panic("cannot set chain")

View File

@ -26,11 +26,11 @@ var node *nm.Node
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
logger := log.TestingLogger() logger := log.TestingLogger()
store, err := app.NewStore("", 0, logger) app, err := app.NewBasecoin(eyes.NewHandler(), "", 0, logger)
if err != nil { if err != nil {
panic(err) panic(err)
} }
app := app.NewBasecoin(eyes.NewHandler(), store, logger)
node = rpctest.StartTendermint(app) node = rpctest.StartTendermint(app)
code := m.Run() code := m.Run()

View File

@ -27,15 +27,14 @@ func TestCounterPlugin(t *testing.T) {
logger := log.TestingLogger() logger := log.TestingLogger()
// logger := log.NewTracingLogger(log.NewTMLogger(os.Stdout)) // logger := log.NewTracingLogger(log.NewTMLogger(os.Stdout))
store, err := app.NewStore("", 0, logger.With("module", "store"))
require.Nil(err, "%+v", err)
h := NewHandler("gold") h := NewHandler("gold")
bcApp := app.NewBasecoin( bcApp, err := app.NewBasecoin(
h, h,
store, "",
0,
logger.With("module", "app"), logger.With("module", "app"),
) )
require.Nil(err, "%+v", err)
bcApp.InitState("base/chain_id", chainID) bcApp.InitState("base/chain_id", chainID)
// Account initialization // Account initialization

View File

@ -74,38 +74,36 @@ func tickStartCmd(tick app.Ticker) func(cmd *cobra.Command, args []string) error
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {
rootDir := viper.GetString(cli.HomeFlag) rootDir := viper.GetString(cli.HomeFlag)
store, err := app.NewStore( // Create Basecoin app
basecoinApp, err := app.NewBasecoinTick(
Handler,
tick,
path.Join(rootDir, "data", "merkleeyes.db"), path.Join(rootDir, "data", "merkleeyes.db"),
EyesCacheSize, EyesCacheSize,
logger.With("module", "store"), logger.With("module", "app"))
)
if err != nil { if err != nil {
return err return err
} }
return start(rootDir, basecoinApp)
// Create Basecoin app
basecoinApp := app.NewBasecoinTick(Handler, store, logger.With("module", "app"), tick)
return start(rootDir, store, basecoinApp)
} }
} }
func startCmd(cmd *cobra.Command, args []string) error { func startCmd(cmd *cobra.Command, args []string) error {
rootDir := viper.GetString(cli.HomeFlag) rootDir := viper.GetString(cli.HomeFlag)
store, err := app.NewStore( // Create Basecoin app
basecoinApp, err := app.NewBasecoin(
Handler,
path.Join(rootDir, "data", "merkleeyes.db"), path.Join(rootDir, "data", "merkleeyes.db"),
EyesCacheSize, EyesCacheSize,
logger.With("module", "store"), logger.With("module", "app"))
)
if err != nil { if err != nil {
return err return err
} }
// Create Basecoin app return start(rootDir, basecoinApp)
basecoinApp := app.NewBasecoin(Handler, store, logger.With("module", "app"))
return start(rootDir, store, basecoinApp)
} }
func start(rootDir string, store *app.Store, basecoinApp *app.Basecoin) error { func start(rootDir string, basecoinApp *app.Basecoin) error {
// if chain_id has not been set yet, load the genesis. // if chain_id has not been set yet, load the genesis.
// else, assume it's been loaded // else, assume it's been loaded