Fix up commits, debug cli tests

This commit is contained in:
Ethan Frey
2017-10-19 14:38:29 +02:00
parent 9aff9f94dd
commit bae4e4acce
4 changed files with 28 additions and 16 deletions
+16 -1
View File
@@ -1,6 +1,7 @@
package dummy
import (
"fmt"
"strings"
"github.com/tendermint/abci/types"
@@ -33,6 +34,7 @@ func (app *DummyApplication) DeliverTx(tx []byte) types.Result {
} else {
app.state.Set(tx, tx)
}
fmt.Println("set data")
return types.OK
}
@@ -41,7 +43,20 @@ func (app *DummyApplication) CheckTx(tx []byte) types.Result {
}
func (app *DummyApplication) Commit() types.Result {
hash := app.state.Hash()
// Save a new version
var hash []byte
var err error
if app.state.Size() > 0 {
// just add one more to height (kind of arbitrarily stupid)
height := app.state.LatestVersion() + 1
hash, err = app.state.SaveVersion(height)
if err != nil {
// if this wasn't a dummy app, we'd do something smarter
panic(err)
}
}
return types.NewResultOK(hash, "")
}
+2 -6
View File
@@ -94,6 +94,7 @@ func (app *PersistentDummyApplication) Commit() types.Result {
// Save a new version
var appHash []byte
var err error
if app.app.state.Size() > 0 {
appHash, err = app.app.state.SaveVersion(app.height)
if err != nil {
@@ -103,12 +104,7 @@ func (app *PersistentDummyApplication) Commit() types.Result {
app.logger.Info("Saved state", "root", appHash)
}
lastBlock := LastBlockInfo{
Height: app.height,
AppHash: appHash, // this hash will be in the next block header
}
app.logger.Info("Saving block", "height", lastBlock.Height, "root", lastBlock.AppHash)
app.logger.Info("Commit block", "height", app.height, "root", appHash)
return types.NewResultOK(appHash, "")
}