Browse Source

Fix lint errors (#190)

* use increment and decrement operators.

* remove unnecessary else branches.

* fix receiver names.

* remove omittable code.

* fix dot imports.
pull/1780/head
Thomas Corbière 7 years ago
committed by Anton Kaliaev
parent
commit
ee67e34519
27 changed files with 121 additions and 145 deletions
  1. +3
    -4
      autofile/autofile.go
  2. +20
    -28
      autofile/group.go
  3. +1
    -1
      autofile/group_test.go
  4. +2
    -2
      clist/clist.go
  5. +3
    -3
      clist/clist_test.go
  6. +3
    -3
      common/async_test.go
  7. +1
    -2
      common/bit_array.go
  8. +1
    -2
      common/colors.go
  9. +3
    -4
      common/errors.go
  10. +1
    -2
      common/io.go
  11. +5
    -6
      common/os.go
  12. +5
    -8
      common/service.go
  13. +1
    -2
      common/string.go
  14. +1
    -2
      common/word.go
  15. +1
    -1
      db/backend_test.go
  16. +22
    -22
      db/common_test.go
  17. +6
    -6
      db/db_test.go
  18. +6
    -7
      db/go_level_db.go
  19. +1
    -1
      db/go_level_db_test.go
  20. +1
    -1
      db/mem_db.go
  21. +1
    -2
      db/types.go
  22. +13
    -15
      db/util.go
  23. +5
    -5
      db/util_test.go
  24. +4
    -4
      events/events.go
  25. +2
    -2
      events/events_test.go
  26. +5
    -6
      merkle/simple_proof.go
  27. +4
    -4
      test/mutate.go

+ 3
- 4
autofile/autofile.go View File

@ -5,7 +5,7 @@ import (
"sync"
"time"
. "github.com/tendermint/tmlibs/common"
cmn "github.com/tendermint/tmlibs/common"
)
/* AutoFile usage
@ -44,7 +44,7 @@ type AutoFile struct {
func OpenAutoFile(path string) (af *AutoFile, err error) {
af = &AutoFile{
ID: RandStr(12) + ":" + path,
ID: cmn.RandStr(12) + ":" + path,
Path: path,
ticker: time.NewTicker(autoFileOpenDuration),
}
@ -129,9 +129,8 @@ func (af *AutoFile) Size() (int64, error) {
if err != nil {
if err == os.ErrNotExist {
return 0, nil
} else {
return -1, err
}
return -1, err
}
}
stat, err := af.file.Stat()


+ 20
- 28
autofile/group.go View File

@ -15,7 +15,7 @@ import (
"sync"
"time"
. "github.com/tendermint/tmlibs/common"
cmn "github.com/tendermint/tmlibs/common"
)
const (
@ -54,7 +54,7 @@ The Group can also be used to binary-search for some line,
assuming that marker lines are written occasionally.
*/
type Group struct {
BaseService
cmn.BaseService
ID string
Head *AutoFile // The head AutoFile to write to
@ -90,7 +90,7 @@ func OpenGroup(headPath string) (g *Group, err error) {
minIndex: 0,
maxIndex: 0,
}
g.BaseService = *NewBaseService(nil, "Group", g)
g.BaseService = *cmn.NewBaseService(nil, "Group", g)
gInfo := g.readGroupInfo()
g.minIndex = gInfo.MinIndex
@ -267,7 +267,7 @@ func (g *Group) RotateFile() {
panic(err)
}
g.maxIndex += 1
g.maxIndex++
}
// NewReader returns a new group reader.
@ -277,9 +277,8 @@ func (g *Group) NewReader(index int) (*GroupReader, error) {
err := r.SetIndex(index)
if err != nil {
return nil, err
} else {
return r, nil
}
return r, nil
}
// Returns -1 if line comes after, 0 if found, 1 if line comes before.
@ -311,9 +310,8 @@ func (g *Group) Search(prefix string, cmp SearchFunc) (*GroupReader, bool, error
if err != nil {
r.Close()
return nil, false, err
} else {
return r, match, err
}
return r, match, err
}
// Read starting roughly at the middle file,
@ -349,9 +347,8 @@ func (g *Group) Search(prefix string, cmp SearchFunc) (*GroupReader, bool, error
if err != nil {
r.Close()
return nil, false, err
} else {
return r, true, err
}
return r, true, err
} else {
// We passed it
maxIndex = curIndex - 1
@ -429,9 +426,8 @@ GROUP_LOOP:
if err == io.EOF {
if found {
return match, found, nil
} else {
continue GROUP_LOOP
}
continue GROUP_LOOP
} else if err != nil {
return "", false, err
}
@ -442,9 +438,8 @@ GROUP_LOOP:
if r.CurIndex() > i {
if found {
return match, found, nil
} else {
continue GROUP_LOOP
}
continue GROUP_LOOP
}
}
}
@ -520,7 +515,7 @@ func (g *Group) readGroupInfo() GroupInfo {
minIndex, maxIndex = 0, 0
} else {
// Otherwise, the head file is 1 greater
maxIndex += 1
maxIndex++
}
return GroupInfo{minIndex, maxIndex, totalSize, headSize}
}
@ -528,9 +523,8 @@ func (g *Group) readGroupInfo() GroupInfo {
func filePathForIndex(headPath string, index int, maxIndex int) string {
if index == maxIndex {
return headPath
} else {
return fmt.Sprintf("%v.%03d", headPath, index)
}
return fmt.Sprintf("%v.%03d", headPath, index)
}
//--------------------------------------------------------------------------------
@ -567,9 +561,8 @@ func (gr *GroupReader) Close() error {
gr.curFile = nil
gr.curLine = nil
return err
} else {
return nil
}
return nil
}
// Read implements io.Reader, reading bytes from the current Reader
@ -598,10 +591,10 @@ func (gr *GroupReader) Read(p []byte) (n int, err error) {
if err == io.EOF {
if n >= lenP {
return n, nil
} else { // Open the next file
if err1 := gr.openFile(gr.curIndex + 1); err1 != nil {
return n, err1
}
}
// Open the next file
if err1 := gr.openFile(gr.curIndex + 1); err1 != nil {
return n, err1
}
} else if err != nil {
return n, err
@ -643,10 +636,9 @@ func (gr *GroupReader) ReadLine() (string, error) {
}
if len(bytesRead) > 0 && bytesRead[len(bytesRead)-1] == byte('\n') {
return linePrefix + string(bytesRead[:len(bytesRead)-1]), nil
} else {
linePrefix += string(bytesRead)
continue
}
linePrefix += string(bytesRead)
continue
} else if err != nil {
return "", err
}
@ -726,11 +718,11 @@ func (gr *GroupReader) SetIndex(index int) error {
func MakeSimpleSearchFunc(prefix string, target int) SearchFunc {
return func(line string) (int, error) {
if !strings.HasPrefix(line, prefix) {
return -1, errors.New(Fmt("Marker line did not have prefix: %v", prefix))
return -1, errors.New(cmn.Fmt("Marker line did not have prefix: %v", prefix))
}
i, err := strconv.Atoi(line[len(prefix):])
if err != nil {
return -1, errors.New(Fmt("Failed to parse marker line: %v", err.Error()))
return -1, errors.New(cmn.Fmt("Failed to parse marker line: %v", err.Error()))
}
if target < i {
return 1, nil


+ 1
- 1
autofile/group_test.go View File

@ -175,7 +175,7 @@ func TestSearch(t *testing.T) {
if !strings.HasPrefix(line, fmt.Sprintf("INFO %v ", cur)) {
t.Fatalf("Unexpected INFO #. Expected %v got:\n%v", cur, line)
}
cur += 1
cur++
}
gr.Close()
}


+ 2
- 2
clist/clist.go View File

@ -316,7 +316,7 @@ func (l *CList) PushBack(v interface{}) *CElement {
l.wg.Done()
close(l.waitCh)
}
l.len += 1
l.len++
// Modify the tail
if l.tail == nil {
@ -357,7 +357,7 @@ func (l *CList) Remove(e *CElement) interface{} {
}
// Update l.len
l.len -= 1
l.len--
// Connect next/prev and set head/tail
if prev == nil {


+ 3
- 3
clist/clist_test.go View File

@ -122,7 +122,7 @@ func _TestGCRandom(t *testing.T) {
v.Int = i
l.PushBack(v)
runtime.SetFinalizer(v, func(v *value) {
gcCount += 1
gcCount++
})
}
@ -177,10 +177,10 @@ func TestScanRightDeleteRandom(t *testing.T) {
}
if el == nil {
el = l.FrontWait()
restartCounter += 1
restartCounter++
}
el = el.Next()
counter += 1
counter++
}
fmt.Printf("Scanner %v restartCounter: %v counter: %v\n", scannerID, restartCounter, counter)
}(i)


+ 3
- 3
common/async_test.go View File

@ -33,13 +33,13 @@ func TestParallel(t *testing.T) {
taskResult, ok := trs.LatestResult(i)
if !ok {
assert.Fail(t, "Task #%v did not complete.", i)
failedTasks += 1
failedTasks++
} else if taskResult.Error != nil {
assert.Fail(t, "Task should not have errored but got %v", taskResult.Error)
failedTasks += 1
failedTasks++
} else if !assert.Equal(t, -1*i, taskResult.Value.(int)) {
assert.Fail(t, "Task should have returned %v but got %v", -1*i, taskResult.Value.(int))
failedTasks += 1
failedTasks++
} else {
// Good!
}


+ 1
- 2
common/bit_array.go View File

@ -168,9 +168,8 @@ func (bA *BitArray) Sub(o *BitArray) *BitArray {
}
}
return c
} else {
return bA.and(o.Not()) // Note degenerate case where o == nil
}
return bA.and(o.Not()) // Note degenerate case where o == nil
}
func (bA *BitArray) IsEmpty() bool {


+ 1
- 2
common/colors.go View File

@ -38,9 +38,8 @@ const (
func treat(s string, color string) string {
if len(s) > 2 && s[:2] == "\x1b[" {
return s
} else {
return color + s + ANSIReset
}
return color + s + ANSIReset
}
func treatAll(color string, args ...interface{}) string {


+ 3
- 4
common/errors.go View File

@ -13,11 +13,10 @@ func ErrorWrap(cause interface{}, format string, args ...interface{}) Error {
msg := Fmt(format, args...)
if causeCmnError, ok := cause.(*cmnError); ok {
return causeCmnError.TraceFrom(1, msg)
} else {
// NOTE: cause may be nil.
// NOTE: do not use causeCmnError here, not the same as nil.
return newError(msg, cause, cause).Stacktrace()
}
// NOTE: cause may be nil.
// NOTE: do not use causeCmnError here, not the same as nil.
return newError(msg, cause, cause).Stacktrace()
}
//----------------------------------------


+ 1
- 2
common/io.go View File

@ -20,9 +20,8 @@ func (pr *PrefixedReader) Read(p []byte) (n int, err error) {
read := copy(p, pr.Prefix)
pr.Prefix = pr.Prefix[read:]
return read, nil
} else {
return pr.reader.Read(p)
}
return pr.reader.Read(p)
}
// NOTE: Not goroutine safe


+ 5
- 6
common/os.go View File

@ -183,11 +183,10 @@ func Prompt(prompt string, defaultValue string) (string, error) {
line, err := reader.ReadString('\n')
if err != nil {
return defaultValue, err
} else {
line = strings.TrimSpace(line)
if line == "" {
return defaultValue, nil
}
return line, nil
}
line = strings.TrimSpace(line)
if line == "" {
return defaultValue, nil
}
return line, nil
}

+ 5
- 8
common/service.go View File

@ -125,9 +125,8 @@ func (bs *BaseService) Start() error {
if atomic.LoadUint32(&bs.stopped) == 1 {
bs.Logger.Error(Fmt("Not starting %v -- already stopped", bs.name), "impl", bs.impl)
return ErrAlreadyStopped
} else {
bs.Logger.Info(Fmt("Starting %v", bs.name), "impl", bs.impl)
}
bs.Logger.Info(Fmt("Starting %v", bs.name), "impl", bs.impl)
err := bs.impl.OnStart()
if err != nil {
// revert flag
@ -135,10 +134,9 @@ func (bs *BaseService) Start() error {
return err
}
return nil
} else {
bs.Logger.Debug(Fmt("Not starting %v -- already started", bs.name), "impl", bs.impl)
return ErrAlreadyStarted
}
bs.Logger.Debug(Fmt("Not starting %v -- already started", bs.name), "impl", bs.impl)
return ErrAlreadyStarted
}
// OnStart implements Service by doing nothing.
@ -154,10 +152,9 @@ func (bs *BaseService) Stop() error {
bs.impl.OnStop()
close(bs.quit)
return nil
} else {
bs.Logger.Debug(Fmt("Stopping %v (ignoring: already stopped)", bs.name), "impl", bs.impl)
return ErrAlreadyStopped
}
bs.Logger.Debug(Fmt("Stopping %v (ignoring: already stopped)", bs.name), "impl", bs.impl)
return ErrAlreadyStopped
}
// OnStop implements Service by doing nothing.


+ 1
- 2
common/string.go View File

@ -10,9 +10,8 @@ import (
var Fmt = func(format string, a ...interface{}) string {
if len(a) == 0 {
return format
} else {
return fmt.Sprintf(format, a...)
}
return fmt.Sprintf(format, a...)
}
// IsHex returns true for non-empty hex-string prefixed with "0x"


+ 1
- 2
common/word.go View File

@ -72,9 +72,8 @@ func (tuple Tuple256) Compare(other Tuple256) int {
firstCompare := tuple.First.Compare(other.First)
if firstCompare == 0 {
return tuple.Second.Compare(other.Second)
} else {
return firstCompare
}
return firstCompare
}
func Tuple256Split(t Tuple256) (Word256, Word256) {


+ 1
- 1
db/backend_test.go View File

@ -47,7 +47,7 @@ func testBackendGetSetDelete(t *testing.T, backend DBBackendType) {
}
func TestBackendsGetSetDelete(t *testing.T) {
for dbType, _ := range backends {
for dbType := range backends {
testBackendGetSetDelete(t, dbType)
}
}


+ 22
- 22
db/common_test.go View File

@ -82,73 +82,73 @@ func (mdb *mockDB) Mutex() *sync.Mutex {
}
func (mdb *mockDB) Get([]byte) []byte {
mdb.calls["Get"] += 1
mdb.calls["Get"]++
return nil
}
func (mdb *mockDB) Has([]byte) bool {
mdb.calls["Has"] += 1
mdb.calls["Has"]++
return false
}
func (mdb *mockDB) Set([]byte, []byte) {
mdb.calls["Set"] += 1
mdb.calls["Set"]++
}
func (mdb *mockDB) SetSync([]byte, []byte) {
mdb.calls["SetSync"] += 1
mdb.calls["SetSync"]++
}
func (mdb *mockDB) SetNoLock([]byte, []byte) {
mdb.calls["SetNoLock"] += 1
mdb.calls["SetNoLock"]++
}
func (mdb *mockDB) SetNoLockSync([]byte, []byte) {
mdb.calls["SetNoLockSync"] += 1
mdb.calls["SetNoLockSync"]++
}
func (mdb *mockDB) Delete([]byte) {
mdb.calls["Delete"] += 1
mdb.calls["Delete"]++
}
func (mdb *mockDB) DeleteSync([]byte) {
mdb.calls["DeleteSync"] += 1
mdb.calls["DeleteSync"]++
}
func (mdb *mockDB) DeleteNoLock([]byte) {
mdb.calls["DeleteNoLock"] += 1
mdb.calls["DeleteNoLock"]++
}
func (mdb *mockDB) DeleteNoLockSync([]byte) {
mdb.calls["DeleteNoLockSync"] += 1
mdb.calls["DeleteNoLockSync"]++
}
func (mdb *mockDB) Iterator(start, end []byte) Iterator {
mdb.calls["Iterator"] += 1
mdb.calls["Iterator"]++
return &mockIterator{}
}
func (mdb *mockDB) ReverseIterator(start, end []byte) Iterator {
mdb.calls["ReverseIterator"] += 1
mdb.calls["ReverseIterator"]++
return &mockIterator{}
}
func (mdb *mockDB) Close() {
mdb.calls["Close"] += 1
mdb.calls["Close"]++
}
func (mdb *mockDB) NewBatch() Batch {
mdb.calls["NewBatch"] += 1
mdb.calls["NewBatch"]++
return &memBatch{db: mdb}
}
func (mdb *mockDB) Print() {
mdb.calls["Print"] += 1
mdb.calls["Print"]++
fmt.Printf("mockDB{%v}", mdb.Stats())
}
func (mdb *mockDB) Stats() map[string]string {
mdb.calls["Stats"] += 1
mdb.calls["Stats"]++
res := make(map[string]string)
for key, count := range mdb.calls {
@ -162,24 +162,24 @@ func (mdb *mockDB) Stats() map[string]string {
type mockIterator struct{}
func (_ mockIterator) Domain() (start []byte, end []byte) {
func (mockIterator) Domain() (start []byte, end []byte) {
return nil, nil
}
func (_ mockIterator) Valid() bool {
func (mockIterator) Valid() bool {
return false
}
func (_ mockIterator) Next() {
func (mockIterator) Next() {
}
func (_ mockIterator) Key() []byte {
func (mockIterator) Key() []byte {
return nil
}
func (_ mockIterator) Value() []byte {
func (mockIterator) Value() []byte {
return nil
}
func (_ mockIterator) Close() {
func (mockIterator) Close() {
}

+ 6
- 6
db/db_test.go View File

@ -8,7 +8,7 @@ import (
)
func TestDBIteratorSingleKey(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
db.SetSync(bz("1"), bz("value_1"))
@ -26,7 +26,7 @@ func TestDBIteratorSingleKey(t *testing.T) {
}
func TestDBIteratorTwoKeys(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
db.SetSync(bz("1"), bz("value_1"))
@ -52,7 +52,7 @@ func TestDBIteratorTwoKeys(t *testing.T) {
}
func TestDBIteratorMany(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
@ -76,7 +76,7 @@ func TestDBIteratorMany(t *testing.T) {
}
func TestDBIteratorEmpty(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
itr := db.Iterator(nil, nil)
@ -87,7 +87,7 @@ func TestDBIteratorEmpty(t *testing.T) {
}
func TestDBIteratorEmptyBeginAfter(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
itr := db.Iterator(bz("1"), nil)
@ -98,7 +98,7 @@ func TestDBIteratorEmptyBeginAfter(t *testing.T) {
}
func TestDBIteratorNonemptyBeginAfter(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
db.SetSync(bz("1"), bz("value_1"))


+ 6
- 7
db/go_level_db.go View File

@ -10,7 +10,7 @@ import (
"github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/opt"
. "github.com/tendermint/tmlibs/common"
cmn "github.com/tendermint/tmlibs/common"
)
func init() {
@ -46,9 +46,8 @@ func (db *GoLevelDB) Get(key []byte) []byte {
if err != nil {
if err == errors.ErrNotFound {
return nil
} else {
panic(err)
}
panic(err)
}
return res
}
@ -64,7 +63,7 @@ func (db *GoLevelDB) Set(key []byte, value []byte) {
value = nonNilBytes(value)
err := db.db.Put(key, value, nil)
if err != nil {
PanicCrisis(err)
cmn.PanicCrisis(err)
}
}
@ -74,7 +73,7 @@ func (db *GoLevelDB) SetSync(key []byte, value []byte) {
value = nonNilBytes(value)
err := db.db.Put(key, value, &opt.WriteOptions{Sync: true})
if err != nil {
PanicCrisis(err)
cmn.PanicCrisis(err)
}
}
@ -83,7 +82,7 @@ func (db *GoLevelDB) Delete(key []byte) {
key = nonNilBytes(key)
err := db.db.Delete(key, nil)
if err != nil {
PanicCrisis(err)
cmn.PanicCrisis(err)
}
}
@ -92,7 +91,7 @@ func (db *GoLevelDB) DeleteSync(key []byte) {
key = nonNilBytes(key)
err := db.db.Delete(key, &opt.WriteOptions{Sync: true})
if err != nil {
PanicCrisis(err)
cmn.PanicCrisis(err)
}
}


+ 1
- 1
db/go_level_db_test.go View File

@ -30,7 +30,7 @@ func BenchmarkRandomReadsWrites(b *testing.B) {
// Write something
{
idx := (int64(cmn.RandInt()) % numItems)
internal[idx] += 1
internal[idx]++
val := internal[idx]
idxBytes := int642Bytes(int64(idx))
valBytes := int642Bytes(int64(val))


+ 1
- 1
db/mem_db.go View File

@ -235,7 +235,7 @@ func (itr *memDBIterator) assertIsValid() {
func (db *MemDB) getSortedKeys(start, end []byte, reverse bool) []string {
keys := []string{}
for key, _ := range db.db {
for key := range db.db {
if IsKeyInDomain([]byte(key), start, end, false) {
keys = append(keys, key)
}


+ 1
- 2
db/types.go View File

@ -129,7 +129,6 @@ func bz(s string) []byte {
func nonNilBytes(bz []byte) []byte {
if bz == nil {
return []byte{}
} else {
return bz
}
return bz
}

+ 13
- 15
db/util.go View File

@ -21,14 +21,13 @@ func cpIncr(bz []byte) (ret []byte) {
ret = cp(bz)
for i := len(bz) - 1; i >= 0; i-- {
if ret[i] < byte(0xFF) {
ret[i] += 1
ret[i]++
return
} else {
ret[i] = byte(0x00)
if i == 0 {
// Overflow
return nil
}
}
ret[i] = byte(0x00)
if i == 0 {
// Overflow
return nil
}
}
return nil
@ -44,13 +43,12 @@ func IsKeyInDomain(key, start, end []byte, isReverse bool) bool {
return false
}
return true
} else {
if start != nil && bytes.Compare(start, key) < 0 {
return false
}
if end != nil && bytes.Compare(key, end) <= 0 {
return false
}
return true
}
if start != nil && bytes.Compare(start, key) < 0 {
return false
}
if end != nil && bytes.Compare(key, end) <= 0 {
return false
}
return true
}

+ 5
- 5
db/util_test.go View File

@ -7,7 +7,7 @@ import (
// Empty iterator for empty db.
func TestPrefixIteratorNoMatchNil(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
itr := IteratePrefix(db, []byte("2"))
@ -19,7 +19,7 @@ func TestPrefixIteratorNoMatchNil(t *testing.T) {
// Empty iterator for db populated after iterator created.
func TestPrefixIteratorNoMatch1(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
itr := IteratePrefix(db, []byte("2"))
@ -32,7 +32,7 @@ func TestPrefixIteratorNoMatch1(t *testing.T) {
// Empty iterator for prefix starting after db entry.
func TestPrefixIteratorNoMatch2(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
db.SetSync(bz("3"), bz("value_3"))
@ -45,7 +45,7 @@ func TestPrefixIteratorNoMatch2(t *testing.T) {
// Iterator with single val for db with single val, starting from that val.
func TestPrefixIteratorMatch1(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)
db.SetSync(bz("2"), bz("value_2"))
@ -63,7 +63,7 @@ func TestPrefixIteratorMatch1(t *testing.T) {
// Iterator with prefix iterates over everything with same prefix.
func TestPrefixIteratorMatches1N(t *testing.T) {
for backend, _ := range backends {
for backend := range backends {
t.Run(fmt.Sprintf("Prefix w/ backend %s", backend), func(t *testing.T) {
db := newTempDB(t, backend)


+ 4
- 4
events/events.go View File

@ -6,7 +6,7 @@ package events
import (
"sync"
. "github.com/tendermint/tmlibs/common"
cmn "github.com/tendermint/tmlibs/common"
)
// Generic event data can be typed and registered with tendermint/go-amino
@ -27,7 +27,7 @@ type Fireable interface {
}
type EventSwitch interface {
Service
cmn.Service
Fireable
AddListenerForEvent(listenerID, event string, cb EventCallback)
@ -36,7 +36,7 @@ type EventSwitch interface {
}
type eventSwitch struct {
BaseService
cmn.BaseService
mtx sync.RWMutex
eventCells map[string]*eventCell
@ -45,7 +45,7 @@ type eventSwitch struct {
func NewEventSwitch() EventSwitch {
evsw := &eventSwitch{}
evsw.BaseService = *NewBaseService(nil, "EventSwitch", evsw)
evsw.BaseService = *cmn.NewBaseService(nil, "EventSwitch", evsw)
return evsw
}


+ 2
- 2
events/events_test.go View File

@ -221,11 +221,11 @@ func TestRemoveListener(t *testing.T) {
// add some listeners and make sure they work
evsw.AddListenerForEvent("listener", "event1",
func(data EventData) {
sum1 += 1
sum1++
})
evsw.AddListenerForEvent("listener", "event2",
func(data EventData) {
sum2 += 1
sum2++
})
for i := 0; i < count; i++ {
evsw.FireEvent("event1", true)


+ 5
- 6
merkle/simple_proof.go View File

@ -67,13 +67,12 @@ func computeHashFromAunts(index int, total int, leafHash []byte, innerHashes [][
return nil
}
return SimpleHashFromTwoHashes(leftHash, innerHashes[len(innerHashes)-1])
} else {
rightHash := computeHashFromAunts(index-numLeft, total-numLeft, leafHash, innerHashes[:len(innerHashes)-1])
if rightHash == nil {
return nil
}
return SimpleHashFromTwoHashes(innerHashes[len(innerHashes)-1], rightHash)
}
rightHash := computeHashFromAunts(index-numLeft, total-numLeft, leafHash, innerHashes[:len(innerHashes)-1])
if rightHash == nil {
return nil
}
return SimpleHashFromTwoHashes(innerHashes[len(innerHashes)-1], rightHash)
}
}


+ 4
- 4
test/mutate.go View File

@ -1,7 +1,7 @@
package test
import (
. "github.com/tendermint/tmlibs/common"
cmn "github.com/tendermint/tmlibs/common"
)
// Contract: !bytes.Equal(input, output) && len(input) >= len(output)
@ -17,11 +17,11 @@ func MutateByteSlice(bytez []byte) []byte {
bytez = mBytez
// Try a random mutation
switch RandInt() % 2 {
switch cmn.RandInt() % 2 {
case 0: // Mutate a single byte
bytez[RandInt()%len(bytez)] += byte(RandInt()%255 + 1)
bytez[cmn.RandInt()%len(bytez)] += byte(cmn.RandInt()%255 + 1)
case 1: // Remove an arbitrary byte
pos := RandInt() % len(bytez)
pos := cmn.RandInt() % len(bytez)
bytez = append(bytez[:pos], bytez[pos+1:]...)
}
return bytez


Loading…
Cancel
Save