Skip to content

Commit

Permalink
only return height if there's an "height = XXX" condition
Browse files Browse the repository at this point in the history
previously, it was returning a height even for range conditions: "height
< 10000".

Refs #2759
  • Loading branch information
melekes committed Nov 22, 2018
1 parent b487feb commit 93499e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions rpc/client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,27 @@ func TestTxSearch(t *testing.T) {
}

// query by height
result, err = c.TxSearch(fmt.Sprintf("tx.height >= %d", txHeight), true, 1, 30)
result, err = c.TxSearch(fmt.Sprintf("tx.height=%d", txHeight), true, 1, 30)
require.Nil(t, err, "%+v", err)
require.Len(t, result.Txs, 1)

// we query for non existing tx
// query for non existing tx
result, err = c.TxSearch(fmt.Sprintf("tx.hash='%X'", anotherTxHash), false, 1, 30)
require.Nil(t, err, "%+v", err)
require.Len(t, result.Txs, 0)

// we query using a tag (see kvstore application)
// query using a tag (see kvstore application)
result, err = c.TxSearch("app.creator='Cosmoshi Netowoko'", false, 1, 30)
require.Nil(t, err, "%+v", err)
if len(result.Txs) == 0 {
t.Fatal("expected a lot of transactions")
}

// query using a tag (see kvstore application) and height
result, err = c.TxSearch("app.creator='Cosmoshi Netowoko' AND tx.height<10000", true, 1, 30)
require.Nil(t, err, "%+v", err)
if len(result.Txs) == 0 {
t.Fatal("expected a lot of transactions")
}
}
}
3 changes: 2 additions & 1 deletion state/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool)
return
}

// lookForHeight returns a height if there is an "height=X" condition.
func lookForHeight(conditions []query.Condition) (height int64) {
for _, c := range conditions {
if c.Tag == types.TxHeightKey {
if c.Tag == types.TxHeightKey && c.Op == query.OpEqual {
return c.Operand.(int64)
}
}
Expand Down

0 comments on commit 93499e5

Please sign in to comment.