From 864ad8546e56fa2778b85b499d06dbd1f6b4f629 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 29 Nov 2017 20:04:00 -0600 Subject: [PATCH] more test cases --- state/txindex/kv/kv.go | 34 ++++++++++++++++++++-------------- state/txindex/kv/kv_test.go | 4 ++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index ad1080697..413569b1d 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -284,22 +284,24 @@ LOOP: if !isTagKey(it.Key()) { continue } - // no other way to stop iterator other than checking for upperBound - switch (r.upperBound).(type) { - case int64: - v, err := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64) - if err == nil && v == r.upperBound { - if r.includeUpperBound { - hashes = append(hashes, it.Value()) + if r.upperBound != nil { + // no other way to stop iterator other than checking for upperBound + switch (r.upperBound).(type) { + case int64: + v, err := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64) + if err == nil && v == r.upperBound { + if r.includeUpperBound { + hashes = append(hashes, it.Value()) + } + break LOOP } - break LOOP + // XXX: passing time in a ABCI Tags is not yet implemented + // case time.Time: + // v := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64) + // if v == r.upperBound { + // break + // } } - // XXX: passing time in a ABCI Tags is not yet implemented - // case time.Time: - // v := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64) - // if v == r.upperBound { - // break - // } } hashes = append(hashes, it.Value()) } @@ -320,6 +322,10 @@ func startKey(c query.Condition, height uint64) []byte { } func startKeyForRange(r queryRange, height uint64) []byte { + if r.lowerBound == nil { + return []byte(fmt.Sprintf("%s", r.key)) + } + var lowerBound interface{} if r.includeLowerBound { lowerBound = r.lowerBound diff --git a/state/txindex/kv/kv_test.go b/state/txindex/kv/kv_test.go index a51bb4bf8..a5c46d6bf 100644 --- a/state/txindex/kv/kv_test.go +++ b/state/txindex/kv/kv_test.go @@ -75,6 +75,10 @@ func TestTxSearch(t *testing.T) { {"account.number = 1 AND account.owner = 'Vlad'", 0}, // search by range {"account.number >= 1 AND account.number <= 5", 1}, + // search by range (lower bound) + {"account.number >= 1", 1}, + // search by range (upper bound) + {"account.number <= 5", 1}, // search using not allowed tag {"not_allowed = 'boom'", 0}, // search for not existing tx result