mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-04 23:27:02 +00:00
Everything compiles, test proof in dummy app
This commit is contained in:
+10
-1
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user