Browse Source

Improve tx tests for both prove true/false

pull/412/head
Ethan Frey 8 years ago
committed by Ethan Buchman
parent
commit
4ee9acb8a7
1 changed files with 29 additions and 22 deletions
  1. +29
    -22
      rpc/test/client_test.go

+ 29
- 22
rpc/test/client_test.go View File

@ -182,29 +182,35 @@ func testTx(t *testing.T, client rpc.HTTPClient) {
height int height int
index int index int
hash []byte hash []byte
prove bool
}{ }{
// only on proper height, index match // only on proper height, index match
{true, res.Height, 0, nil},
{false, res.Height, 1, nil},
{false, res.Height, -7, nil},
{false, -10, -100, nil},
{false, res.Height + 1, 0, nil},
{true, res.Height, 0, nil, false},
{true, res.Height, 0, nil, true},
{false, res.Height, 1, nil, false},
{false, res.Height, -7, nil, true},
{false, -10, -100, nil, false},
{false, res.Height + 1, 0, nil, true},
// on proper hash match // on proper hash match
{true, 0, 0, tx.Hash()},
{false, res.Height, 0, tx.Hash()}, // TODO: or shall we allow this????
{true, 0, 0, tx.Hash(), false},
{true, 0, 0, tx.Hash(), true},
{false, res.Height, 0, tx.Hash(), false}, // TODO: or shall we allow this????
{false, res.Height, 0, tx.Hash(), true}, // TODO: or shall we allow this????
// with extra data is an error // with extra data is an error
{false, 10, 0, tx.Hash()},
{false, 0, 2, tx.Hash()},
{false, 0, 0, []byte("jkh8y0fw")},
{false, 0, 0, nil},
{false, 10, 0, tx.Hash(), false},
{false, 0, 2, tx.Hash(), true},
{false, 0, 0, []byte("jkh8y0fw"), false},
{false, 0, 0, nil, true},
// missing height and hash fails // missing height and hash fails
{false, 0, 0, nil},
{false, 0, 1, nil},
{false, 0, 0, nil, false},
{false, 0, 1, nil, true},
} }
for _, tc := range cases {
for i, tc := range cases {
idx := fmt.Sprintf("%d", i)
// now we query for the tx. // now we query for the tx.
// since there's only one tx, we know index=0. // since there's only one tx, we know index=0.
tmResult = new(ctypes.TMResult) tmResult = new(ctypes.TMResult)
@ -212,21 +218,22 @@ func testTx(t *testing.T, client rpc.HTTPClient) {
"height": tc.height, "height": tc.height,
"index": tc.index, "index": tc.index,
"hash": tc.hash, "hash": tc.hash,
"prove": tc.prove,
} }
_, err = client.Call("tx", query, tmResult) _, err = client.Call("tx", query, tmResult)
if !tc.valid { if !tc.valid {
require.NotNil(err)
require.NotNil(err, idx)
} else { } else {
require.Nil(err)
require.Nil(err, idx)
res2 := (*tmResult).(*ctypes.ResultTx) res2 := (*tmResult).(*ctypes.ResultTx)
assert.Equal(tx, res2.Tx, "tx is not correct")
assert.Equal(res.Height, res2.Height)
assert.Equal(0, res2.Index)
assert.Equal(abci.CodeType_OK, res2.DeliverTx.Code)
assert.Equal(tx, res2.Tx, idx)
assert.Equal(res.Height, res2.Height, idx)
assert.Equal(0, res2.Index, idx)
assert.Equal(abci.CodeType_OK, res2.DeliverTx.Code, idx)
// time to verify the proof // time to verify the proof
proof := res2.Proof proof := res2.Proof
if assert.Equal(tx, proof.Data) {
assert.True(proof.Proof.Verify(proof.Index, proof.Total, tx.Hash(), proof.RootHash))
if tc.prove && assert.Equal(tx, proof.Data, idx) {
assert.True(proof.Proof.Verify(proof.Index, proof.Total, tx.Hash(), proof.RootHash), idx)
} }
} }
} }


Loading…
Cancel
Save