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
*sm.State
// cached validator changes from DeliverTx
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
@ -45,8 +49,9 @@ func NewBaseApp(dbName string, cacheSize int, logger log.Logger) (*BaseApp, erro
return nil, err
}
app := &BaseApp{
info: sm.NewChainState(),
State: state,
height: state.LatestHeight(),
info: sm.NewChainState(),
logger: logger,
}
return app, nil
@ -163,14 +168,10 @@ func (app *BaseApp) Commit() (res abci.Result) {
// InitChain - ABCI
func (app *BaseApp) InitChain(req abci.RequestInitChain) {
// for _, plugin := range app.plugins.GetList() {
// plugin.InitChain(app.state, validators)
// }
}
// BeginBlock - ABCI
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) {
app.height++
}
// EndBlock - ABCI
@ -182,6 +183,9 @@ func (app *BaseApp) EndBlock(height uint64) (res abci.ResponseEndBlock) {
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) {
for _, d := range diffs {
idx := pubKeyIndex(d, app.pending)
@ -203,8 +207,6 @@ func pubKeyIndex(val *abci.Validator, list []*abci.Validator) int {
return -1
}
//TODO move split key to tmlibs?
// Splits the string at the first '/'.
// if there are none, assign default module ("base").
func splitKey(key string) (string, string) {

View File

@ -75,7 +75,7 @@ func (app *Basecoin) DeliverTx(txBytes []byte) abci.Result {
ctx := stack.NewContext(
app.GetChainID(),
app.height,
app.height+1,
app.Logger().With("call", "delivertx"),
)
res, err := app.handler.DeliverTx(ctx, app.Append(), tx)
@ -96,7 +96,7 @@ func (app *Basecoin) CheckTx(txBytes []byte) abci.Result {
ctx := stack.NewContext(
app.GetChainID(),
app.height,
app.height+1,
app.Logger().With("call", "checktx"),
)
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.NewTracingLogger(logger)
// TODO: disk writing
var store *app.Store
var err error
dbDir, cache := "", 0
if persist {
tmpDir, _ := ioutil.TempDir("", "bc-app-benchmark")
store, err = app.NewStore(tmpDir, 500, logger)
} else {
store, err = app.NewStore("", 0, logger)
dbDir, _ = ioutil.TempDir("", "bc-app-benchmark")
cache = 500
}
app, err := app.NewBasecoin(
h,
dbDir,
cache,
logger.With("module", "app"),
)
if err != nil {
panic(err)
}
app := app.NewBasecoin(
h,
store,
logger.With("module", "app"),
)
res := app.InitState("base/chain_id", chainID)
if res != "Success" {
panic("cannot set chain")

View File

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

View File

@ -27,15 +27,14 @@ func TestCounterPlugin(t *testing.T) {
logger := log.TestingLogger()
// logger := log.NewTracingLogger(log.NewTMLogger(os.Stdout))
store, err := app.NewStore("", 0, logger.With("module", "store"))
require.Nil(err, "%+v", err)
h := NewHandler("gold")
bcApp := app.NewBasecoin(
bcApp, err := app.NewBasecoin(
h,
store,
"",
0,
logger.With("module", "app"),
)
require.Nil(err, "%+v", err)
bcApp.InitState("base/chain_id", chainID)
// 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 {
rootDir := viper.GetString(cli.HomeFlag)
store, err := app.NewStore(
// Create Basecoin app
basecoinApp, err := app.NewBasecoinTick(
Handler,
tick,
path.Join(rootDir, "data", "merkleeyes.db"),
EyesCacheSize,
logger.With("module", "store"),
)
logger.With("module", "app"))
if err != nil {
return err
}
// Create Basecoin app
basecoinApp := app.NewBasecoinTick(Handler, store, logger.With("module", "app"), tick)
return start(rootDir, store, basecoinApp)
return start(rootDir, basecoinApp)
}
}
func startCmd(cmd *cobra.Command, args []string) error {
rootDir := viper.GetString(cli.HomeFlag)
store, err := app.NewStore(
// Create Basecoin app
basecoinApp, err := app.NewBasecoin(
Handler,
path.Join(rootDir, "data", "merkleeyes.db"),
EyesCacheSize,
logger.With("module", "store"),
)
logger.With("module", "app"))
if err != nil {
return err
}
// Create Basecoin app
basecoinApp := app.NewBasecoin(Handler, store, logger.With("module", "app"))
return start(rootDir, store, basecoinApp)
return start(rootDir, 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.
// else, assume it's been loaded