Everything compiles, test proof in dummy app

This commit is contained in:
Ethan Frey
2017-01-17 15:44:41 +01:00
parent 7cd39dafea
commit cfc3f24751
8 changed files with 63 additions and 22 deletions
+10 -1
View File
@@ -2,6 +2,7 @@ package dummy
import (
"encoding/hex"
"fmt"
"strings"
"github.com/tendermint/abci/types"
@@ -54,7 +55,15 @@ func (app *DummyApplication) Query(query []byte) types.Result {
}
func (app *DummyApplication) Proof(key []byte, blockHeight int64) types.Result {
return types.NewResultOK(nil, Fmt("TODO: support proof!"))
if blockHeight != 0 {
return types.ErrUnknownRequest
}
proof, exists := app.state.Proof(key)
if !exists {
fmt.Println("Didn't find nothing")
return types.NewResultOK(nil, "")
}
return types.NewResultOK(proof, "Found the key")
}
type QueryResult struct {
+22
View File
@@ -8,6 +8,7 @@ import (
. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
merkle "github.com/tendermint/go-merkle"
"github.com/tendermint/go-wire"
"github.com/tendermint/abci/types"
)
@@ -34,6 +35,27 @@ func testDummy(t *testing.T, dummy types.Application, tx []byte, key, value stri
t.Fatalf("Got %s, expected %s", q.Value, value)
}
rp := dummy.Proof([]byte(key), 0)
if rp.IsErr() {
t.Fatal(rp)
}
p, err := merkle.LoadProof(rp.Data)
if err != nil {
t.Fatal(err)
}
if !p.Valid() {
t.Fatal("Invalid proof")
}
if !bytes.Equal([]byte(key), p.Key()) {
t.Fatalf("Invalid key: %s", p.Key())
}
if !bytes.Equal([]byte(value), p.Value()) {
t.Fatalf("Invalid key: %s", p.Value())
}
}
func TestDummyKV(t *testing.T) {
+1 -1
View File
@@ -94,7 +94,7 @@ func (app *PersistentDummyApplication) Query(query []byte) types.Result {
}
func (app *PersistentDummyApplication) Proof(key []byte, blockHeight int64) types.Result {
return types.NewResultOK(nil, Fmt("TODO: support proof!"))
return app.app.Proof(key, blockHeight)
}
// Save the validators in the merkle tree