mirror of
https://github.com/arnaucube/go-merkletree-iden3.git
synced 2026-02-07 19:46:43 +01:00
Add golangci-lint to GHA & fix lint warnings
This commit is contained in:
@@ -3,13 +3,12 @@ package leveldb
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/iden3/go-merkletree/db"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
"github.com/syndtr/goleveldb/leveldb/errors"
|
||||
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||
"github.com/syndtr/goleveldb/leveldb/util"
|
||||
|
||||
"github.com/iden3/go-merkletree/db"
|
||||
)
|
||||
|
||||
// LevelDbStorage implements the db.Storage interface
|
||||
|
||||
@@ -57,7 +57,6 @@ func (m *MemoryStorage) Iterate(f func([]byte, []byte) (bool, error)) error {
|
||||
}
|
||||
localkey := v.K[len(m.prefix):]
|
||||
kvs = append(kvs, db.KV{K: localkey, V: v.V})
|
||||
|
||||
}
|
||||
sort.SliceStable(kvs, func(i, j int) bool { return bytes.Compare(kvs[i].K, kvs[j].K) < 0 })
|
||||
|
||||
@@ -73,7 +72,6 @@ func (m *MemoryStorage) Iterate(f func([]byte, []byte) (bool, error)) error {
|
||||
|
||||
// Get implements the method Get of the interface db.Tx
|
||||
func (tx *MemoryStorageTx) Get(key []byte) ([]byte, error) {
|
||||
|
||||
if v, ok := tx.kv.Get(db.Concat(tx.s.prefix, key)); ok {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func (tx *PebbleStorageTx) Add(atx db.Tx) {
|
||||
func (tx *PebbleStorageTx) Commit() error {
|
||||
batch := tx.PebbleStorage.pdb.NewBatch()
|
||||
for _, v := range tx.cache {
|
||||
batch.Set(v.K, v.V, nil)
|
||||
_ = batch.Set(v.K, v.V, nil)
|
||||
}
|
||||
|
||||
tx.cache = nil
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//nolint:gomnd
|
||||
package test
|
||||
|
||||
import (
|
||||
@@ -108,17 +109,17 @@ func TestIterate(t *testing.T, sto db.Storage) {
|
||||
err = sto1.Iterate(lister)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, len(r))
|
||||
assert.Equal(t, db.KV{[]byte{1}, []byte{4}}, r[0])
|
||||
assert.Equal(t, db.KV{[]byte{2}, []byte{5}}, r[1])
|
||||
assert.Equal(t, db.KV{[]byte{3}, []byte{6}}, r[2])
|
||||
assert.Equal(t, db.KV{K: []byte{1}, V: []byte{4}}, r[0])
|
||||
assert.Equal(t, db.KV{K: []byte{2}, V: []byte{5}}, r[1])
|
||||
assert.Equal(t, db.KV{K: []byte{3}, V: []byte{6}}, r[2])
|
||||
|
||||
r = []db.KV{}
|
||||
err = sto2.Iterate(lister)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, len(r))
|
||||
assert.Equal(t, db.KV{[]byte{1}, []byte{7}}, r[0])
|
||||
assert.Equal(t, db.KV{[]byte{2}, []byte{8}}, r[1])
|
||||
assert.Equal(t, db.KV{[]byte{3}, []byte{9}}, r[2])
|
||||
assert.Equal(t, db.KV{K: []byte{1}, V: []byte{7}}, r[0])
|
||||
assert.Equal(t, db.KV{K: []byte{2}, V: []byte{8}}, r[1])
|
||||
assert.Equal(t, db.KV{K: []byte{3}, V: []byte{9}}, r[2])
|
||||
}
|
||||
|
||||
// TestConcatTx checks that the implementation of the db.Storage interface
|
||||
@@ -180,13 +181,13 @@ func TestList(t *testing.T, sto db.Storage) {
|
||||
r, err := sto1.List(100)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, len(r))
|
||||
assert.Equal(t, r[0], db.KV{[]byte{1}, []byte{4}})
|
||||
assert.Equal(t, r[1], db.KV{[]byte{2}, []byte{5}})
|
||||
assert.Equal(t, r[2], db.KV{[]byte{3}, []byte{6}})
|
||||
assert.Equal(t, r[0], db.KV{K: []byte{1}, V: []byte{4}})
|
||||
assert.Equal(t, r[1], db.KV{K: []byte{2}, V: []byte{5}})
|
||||
assert.Equal(t, r[2], db.KV{K: []byte{3}, V: []byte{6}})
|
||||
|
||||
r, err = sto1.List(2)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, len(r))
|
||||
assert.Equal(t, r[0], db.KV{[]byte{1}, []byte{4}})
|
||||
assert.Equal(t, r[1], db.KV{[]byte{2}, []byte{5}})
|
||||
assert.Equal(t, r[0], db.KV{K: []byte{1}, V: []byte{4}})
|
||||
assert.Equal(t, r[1], db.KV{K: []byte{2}, V: []byte{5}})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user