From f592375d1b0fe24978a2f80ff879f9cbdd4d855b Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 8 Jul 2021 09:44:41 +0200 Subject: [PATCH] kvdb/test: fix cursor tests to match bbolt semantics From bbolt docs: // Seek positions the cursor at the passed seek key. If the key does not exist, // the cursor is moved to the next key after seek. Returns the new pair. --- kvdb/etcd/readwrite_cursor.go | 5 ----- kvdb/readwrite_cursor_test.go | 5 ++--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/kvdb/etcd/readwrite_cursor.go b/kvdb/etcd/readwrite_cursor.go index 75c0456d..fb408b8f 100644 --- a/kvdb/etcd/readwrite_cursor.go +++ b/kvdb/etcd/readwrite_cursor.go @@ -96,11 +96,6 @@ func (c *readWriteCursor) Prev() (key, value []byte) { // not exist, the cursor is moved to the next key after seek. Returns // the new pair. func (c *readWriteCursor) Seek(seek []byte) (key, value []byte) { - // Return nil if trying to seek to an empty key. - if seek == nil { - return nil, nil - } - // Seek to the first key with prefix + seek. If that key is not present // STM will seek to the next matching key with prefix. kv, err := c.bucket.tx.stm.Seek(c.prefix, c.prefix+string(seek)) diff --git a/kvdb/readwrite_cursor_test.go b/kvdb/readwrite_cursor_test.go index 3ac83ba3..de70196b 100644 --- a/kvdb/readwrite_cursor_test.go +++ b/kvdb/readwrite_cursor_test.go @@ -99,8 +99,8 @@ func testReadCursorNonEmptyInterval(t *testing.T, db walletdb.DB) { // Seek to nonexisting key. k, v = cursor.Seek(nil) - require.Nil(t, k) - require.Nil(t, v) + require.Equal(t, "b", string(k)) + require.Equal(t, "1", string(v)) k, v = cursor.Seek([]byte("x")) require.Nil(t, k) @@ -113,7 +113,6 @@ func testReadCursorNonEmptyInterval(t *testing.T, db walletdb.DB) { } func testReadWriteCursor(t *testing.T, db walletdb.DB) { - testKeyValues := []KV{ {"b", "1"}, {"c", "2"},