Fix TestTxProofs
This commit is contained in:
parent
1e6d9bcac6
commit
9092b4d7f1
|
@ -165,6 +165,7 @@ func (app *Basecoin) InitChain(req abci.RequestInitChain) {
|
||||||
|
|
||||||
// BeginBlock - ABCI
|
// BeginBlock - ABCI
|
||||||
func (app *Basecoin) BeginBlock(req abci.RequestBeginBlock) {
|
func (app *Basecoin) BeginBlock(req abci.RequestBeginBlock) {
|
||||||
|
fmt.Println("BeginBlock")
|
||||||
app.height++
|
app.height++
|
||||||
// for _, plugin := range app.plugins.GetList() {
|
// for _, plugin := range app.plugins.GetList() {
|
||||||
// plugin.BeginBlock(app.state, hash, header)
|
// plugin.BeginBlock(app.state, hash, header)
|
||||||
|
|
|
@ -123,6 +123,7 @@ func (s *Store) Commit() abci.Result {
|
||||||
if s.State.Size() == 0 {
|
if s.State.Size() == 0 {
|
||||||
return abci.NewResultOK(nil, "Empty hash for empty tree")
|
return abci.NewResultOK(nil, "Empty hash for empty tree")
|
||||||
}
|
}
|
||||||
|
fmt.Printf("ABCI Commit: %d / %X\n", height, hash)
|
||||||
return abci.NewResultOK(hash, "")
|
return abci.NewResultOK(hash, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/tendermint/go-wire/data"
|
"github.com/tendermint/go-wire/data"
|
||||||
|
@ -39,7 +41,9 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) (
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,6 +74,10 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) (
|
||||||
return
|
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.
|
// Validate the proof against the certified header to ensure data integrity.
|
||||||
err = aproof.Verify(resp.Key, nil, check.Header.AppHash)
|
err = aproof.Verify(resp.Key, nil, check.Header.AppHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -103,13 +104,14 @@ func TestTxProofs(t *testing.T) {
|
||||||
cl := client.NewLocal(node)
|
cl := client.NewLocal(node)
|
||||||
client.WaitForHeight(cl, 1, nil)
|
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))
|
btx := types.Tx(wire.BinaryBytes(tx))
|
||||||
br, err := cl.BroadcastTxCommit(btx)
|
br, err := cl.BroadcastTxCommit(btx)
|
||||||
require.NoError(err, "%+v", err)
|
require.NoError(err, "%+v", err)
|
||||||
require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx)
|
require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx)
|
||||||
require.EqualValues(0, br.DeliverTx.Code)
|
require.EqualValues(0, br.DeliverTx.Code)
|
||||||
|
fmt.Printf("tx height: %d\n", br.Height)
|
||||||
|
|
||||||
source := certclient.New(cl)
|
source := certclient.New(cl)
|
||||||
seed, err := source.GetByHeight(br.Height - 2)
|
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.
|
// First let's make sure a bogus transaction hash returns a valid non-existence proof.
|
||||||
key := types.Tx([]byte("bogus")).Hash()
|
key := types.Tx([]byte("bogus")).Hash()
|
||||||
bs, _, proof, err := GetWithProof(key, cl, cert)
|
res, err := cl.Tx(key, true)
|
||||||
assert.Nil(bs, "value should be nil")
|
require.NotNil(err)
|
||||||
require.True(lc.IsNoDataErr(err), "error should signal 'no data'")
|
require.Contains(err.Error(), "not found")
|
||||||
require.NotNil(proof, "proof shouldn't be nil")
|
|
||||||
err = proof.Verify(key, nil, proof.Root())
|
|
||||||
require.NoError(err, "%+v", err)
|
|
||||||
|
|
||||||
// Now let's check with the real tx hash.
|
// Now let's check with the real tx hash.
|
||||||
key = btx.Hash()
|
key = btx.Hash()
|
||||||
res, err := cl.Tx(key, true)
|
res, err = cl.Tx(key, true)
|
||||||
require.NoError(err, "%+v", err)
|
require.NoError(err, "%+v", err)
|
||||||
require.NotNil(res)
|
require.NotNil(res)
|
||||||
err = res.Proof.Validate(key)
|
err = res.Proof.Validate(key)
|
||||||
assert.NoError(err, "%+v", err)
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue