mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-14 15:51:20 +00:00
Improve tx tests for both prove true/false
This commit is contained in:
parent
20458564b2
commit
4ee9acb8a7
@ -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},
|
{true, res.Height, 0, nil, false},
|
||||||
{false, res.Height, 1, nil},
|
{true, res.Height, 0, nil, true},
|
||||||
{false, res.Height, -7, nil},
|
{false, res.Height, 1, nil, false},
|
||||||
{false, -10, -100, nil},
|
{false, res.Height, -7, nil, true},
|
||||||
{false, res.Height + 1, 0, nil},
|
{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()},
|
{true, 0, 0, tx.Hash(), false},
|
||||||
{false, res.Height, 0, tx.Hash()}, // TODO: or shall we allow this????
|
{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, 10, 0, tx.Hash(), false},
|
||||||
{false, 0, 2, tx.Hash()},
|
{false, 0, 2, tx.Hash(), true},
|
||||||
{false, 0, 0, []byte("jkh8y0fw")},
|
{false, 0, 0, []byte("jkh8y0fw"), false},
|
||||||
{false, 0, 0, nil},
|
{false, 0, 0, nil, true},
|
||||||
|
|
||||||
// missing height and hash fails
|
// missing height and hash fails
|
||||||
{false, 0, 0, nil},
|
{false, 0, 0, nil, false},
|
||||||
{false, 0, 1, nil},
|
{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(tx, res2.Tx, idx)
|
||||||
assert.Equal(res.Height, res2.Height)
|
assert.Equal(res.Height, res2.Height, idx)
|
||||||
assert.Equal(0, res2.Index)
|
assert.Equal(0, res2.Index, idx)
|
||||||
assert.Equal(abci.CodeType_OK, res2.DeliverTx.Code)
|
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) {
|
if tc.prove && assert.Equal(tx, proof.Data, idx) {
|
||||||
assert.True(proof.Proof.Verify(proof.Index, proof.Total, tx.Hash(), proof.RootHash))
|
assert.True(proof.Proof.Verify(proof.Index, proof.Total, tx.Hash(), proof.RootHash), idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user