From 9092b4d7f10a89072d65a3247df955f9089dc3f4 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 10 Oct 2017 14:27:38 +0200 Subject: [PATCH] Fix TestTxProofs --- app/app.go | 1 + app/store.go | 1 + client/query.go | 10 +++++++++- client/query_test.go | 20 ++++++++++++-------- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/app.go b/app/app.go index eebc816e8..89f5ed6df 100644 --- a/app/app.go +++ b/app/app.go @@ -165,6 +165,7 @@ func (app *Basecoin) InitChain(req abci.RequestInitChain) { // BeginBlock - ABCI func (app *Basecoin) BeginBlock(req abci.RequestBeginBlock) { + fmt.Println("BeginBlock") app.height++ // for _, plugin := range app.plugins.GetList() { // plugin.BeginBlock(app.state, hash, header) diff --git a/app/store.go b/app/store.go index c70adf9b0..0f9a2c4f5 100644 --- a/app/store.go +++ b/app/store.go @@ -123,6 +123,7 @@ func (s *Store) Commit() abci.Result { if s.State.Size() == 0 { return abci.NewResultOK(nil, "Empty hash for empty tree") } + fmt.Printf("ABCI Commit: %d / %X\n", height, hash) return abci.NewResultOK(hash, "") } diff --git a/client/query.go b/client/query.go index bdc3e98c5..a25d80407 100644 --- a/client/query.go +++ b/client/query.go @@ -1,6 +1,8 @@ package client import ( + "fmt" + "github.com/pkg/errors" "github.com/tendermint/go-wire/data" @@ -39,7 +41,9 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) ( return } - check, err := GetCertifiedCheckpoint(int(resp.Height), node, cert) + var check lc.Checkpoint + // check, err = GetCertifiedCheckpoint(int(resp.Height), node, cert) + check, err = GetCertifiedCheckpoint(int(resp.Height+9), node, cert) if err != nil { return } @@ -70,6 +74,10 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) ( return } + fmt.Printf("apphash: %x\n", check.Header.AppHash) + fmt.Printf("proof hash: %x\n", aproof.Root()) + fmt.Printf("response height: %d\n", resp.Height) + // Validate the proof against the certified header to ensure data integrity. err = aproof.Verify(resp.Key, nil, check.Header.AppHash) if err != nil { diff --git a/client/query_test.go b/client/query_test.go index aaac2bea3..5d6a5bf5c 100644 --- a/client/query_test.go +++ b/client/query_test.go @@ -1,6 +1,7 @@ package client import ( + "fmt" "os" "testing" @@ -103,13 +104,14 @@ func TestTxProofs(t *testing.T) { cl := client.NewLocal(node) client.WaitForHeight(cl, 1, nil) - tx := eyes.SetTx{Key: []byte("key-a"), Value: []byte("value-a")}.Wrap() + tx := eyes.NewSetTx([]byte("key-a"), []byte("value-a")) btx := types.Tx(wire.BinaryBytes(tx)) br, err := cl.BroadcastTxCommit(btx) require.NoError(err, "%+v", err) require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx) require.EqualValues(0, br.DeliverTx.Code) + fmt.Printf("tx height: %d\n", br.Height) source := certclient.New(cl) seed, err := source.GetByHeight(br.Height - 2) @@ -118,18 +120,20 @@ func TestTxProofs(t *testing.T) { // First let's make sure a bogus transaction hash returns a valid non-existence proof. key := types.Tx([]byte("bogus")).Hash() - bs, _, proof, err := GetWithProof(key, cl, cert) - assert.Nil(bs, "value should be nil") - require.True(lc.IsNoDataErr(err), "error should signal 'no data'") - require.NotNil(proof, "proof shouldn't be nil") - err = proof.Verify(key, nil, proof.Root()) - require.NoError(err, "%+v", err) + res, err := cl.Tx(key, true) + require.NotNil(err) + require.Contains(err.Error(), "not found") // Now let's check with the real tx hash. key = btx.Hash() - res, err := cl.Tx(key, true) + res, err = cl.Tx(key, true) require.NoError(err, "%+v", err) require.NotNil(res) err = res.Proof.Validate(key) assert.NoError(err, "%+v", err) + + check, err := GetCertifiedCheckpoint(int(br.Height), cl, cert) + require.Nil(err, "%+v", err) + require.Equal(res.Proof.RootHash, check.Header.DataHash) + }