From f9c3fce5b43a17b2c7a420ea076553ae878559fa Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 10 Aug 2017 14:25:17 +0200 Subject: [PATCH] Write tx proof tests --- client/commands/query/query_test.go | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/client/commands/query/query_test.go b/client/commands/query/query_test.go index c16affb7c..25362a479 100644 --- a/client/commands/query/query_test.go +++ b/client/commands/query/query_test.go @@ -14,6 +14,7 @@ import ( nm "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/rpc/client" rpctest "github.com/tendermint/tendermint/rpc/test" + "github.com/tendermint/tendermint/types" "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin/app" @@ -85,3 +86,41 @@ func TestAppProofs(t *testing.T) { err = proofNotExists.Verify(k, proofNotExists.RootHash) assert.NotNil(err) } + +func TestTxProofs(t *testing.T) { + assert, require := assert.New(t), require.New(t) + + cl := client.NewLocal(node) + client.WaitForHeight(cl, 1, nil) + + tx := eyes.SetTx{Key: []byte("key-a"), Value: []byte("value-a")}.Wrap() + + btx := types.Tx(wire.BinaryBytes(tx)) + br, err := cl.BroadcastTxCommit(btx) + require.Nil(err, "%+v", err) + require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx) + require.EqualValues(0, br.DeliverTx.Code) + + source := certclient.New(cl) + seed, err := source.GetByHeight(br.Height - 2) + require.Nil(err, "%+v", err) + cert := certifiers.NewStatic("my-chain", seed.Validators) + + // First let's make sure a bogus transaction hash returns a valid non-existence proof. + key := types.Tx([]byte("bogus")).Hash() + bs, _, proofExists, proofNotExists, err := getWithProof(key, cl, cert) + assert.Nil(bs, "value should be nil") + require.True(lc.IsNoDataErr(err), "error should signal 'no data'") + assert.Nil(proofExists, "existence proof should be nil") + require.NotNil(proofNotExists, "non-existence proof shouldn't be nil") + err = proofNotExists.Verify(key, proofNotExists.RootHash) + require.Nil(err, "%+v", err) + + // Now let's check with the real tx hash. + key = btx.Hash() + res, err := cl.Tx(key, true) + require.Nil(err, "%+v", err) + require.NotNil(res) + err = res.Proof.Validate(key) + assert.Nil(err, "%+v", err) +}