Skip to content

Commit

Permalink
Merge pull request #2206 from benbaley/feature/bump-version-to-1.5.1
Browse files Browse the repository at this point in the history
make lint
  • Loading branch information
benbaley authored Nov 28, 2023
2 parents f2a094b + dd78b8b commit e5ef480
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cmd/abidump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"encoding/hex"
"flag"
"fmt"
"github.com/PlatONnetwork/PlatON-Go/signer/core/apitypes"
"os"
"strings"

"github.com/PlatONnetwork/PlatON-Go/signer/core/apitypes"
"github.com/PlatONnetwork/PlatON-Go/signer/fourbyte"
)

Expand Down
8 changes: 2 additions & 6 deletions core/snapshotdb/heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the PlatON-Go library. If not, see <http://www.gnu.org/licenses/>.


package snapshotdb

import (
Expand All @@ -39,12 +38,9 @@ type rankingHeap struct {
hepMaxNum int
}

// the key is gt than or eq than heap top
// the key is gt than or eq than heap top
func (r *rankingHeap) geMaxHeap(k []byte) bool {
if bytes.Compare(k, r.heap[0].key) > 0 {
return true
}
return false
return bytes.Compare(k, r.heap[0].key) > 0
}

func (r *rankingHeap) addHandledKey(key []byte) {
Expand Down
38 changes: 19 additions & 19 deletions core/snapshotdb/snapshotdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestSnapshotDB_GetWithNoCommit(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(kv.value, val) != 0 {
if !bytes.Equal(kv.value, val) {
t.Error("must find key", i)
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestSnapshotDB_Get(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(kv.value, val) != 0 {
if !bytes.Equal(kv.value, val) {
t.Error("must find key")
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestSnapshotDB_Get(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(kv.value, val) != 0 {
if !bytes.Equal(kv.value, val) {
t.Error("must find key")
}
}
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestSnapshotDB_Get(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(kv.value, val) != 0 {
if !bytes.Equal(kv.value, val) {
t.Error("must find key")
}
}
Expand All @@ -306,7 +306,7 @@ func TestSnapshotDB_Get(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(kv.value, val) != 0 {
if !bytes.Equal(kv.value, val) {
t.Error("must find key")
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestSnapshotDB_GetFromCommitedBlock(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(key.value, val) != 0 {
if !bytes.Equal(key.value, val) {
t.Error("val not compare", key.value, val)
}
}
Expand All @@ -352,7 +352,7 @@ func TestSnapshotDB_GetFromCommitedBlock(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(commit2KV.value, val) != 0 {
if !bytes.Equal(commit2KV.value, val) {
t.Error("must find key")
}
})
Expand Down Expand Up @@ -450,7 +450,7 @@ func TestSnapshotDB_Ranking10(t *testing.T) {
itr := ch.db.Ranking(ch.CurrentHeader().Hash(), f[0:10], 5)
var i int
for itr.Next() {
if bytes.Compare(itr.Key(), base[i].key) != 0 {
if !bytes.Equal(itr.Key(), base[i].key) {
t.Errorf("should eq but not eq,want %v have %v", hex.EncodeToString(base[i].key), hex.EncodeToString(itr.Key()))
}
i++
Expand All @@ -463,11 +463,11 @@ func TestSnapshotDB_Ranking10(t *testing.T) {
i = 0
for itr.Next() {
if i == 0 {
if bytes.Compare(itr.Key(), a) != 0 {
if !bytes.Equal(itr.Key(), a) {
t.Errorf("should eq but not eq,want %v have %v", hex.EncodeToString(a), hex.EncodeToString(itr.Key()))
}
} else {
if bytes.Compare(itr.Key(), base[i-1].key) != 0 {
if !bytes.Equal(itr.Key(), base[i-1].key) {
t.Errorf("should eq but not eq,want %v have %v", hex.EncodeToString(base[i-1].key), hex.EncodeToString(itr.Key()))
}
}
Expand All @@ -484,11 +484,11 @@ func TestSnapshotDB_Ranking10(t *testing.T) {
i = 0
for itr.Next() {
if i == 0 {
if bytes.Compare(itr.Key(), a) != 0 {
if !bytes.Equal(itr.Key(), a) {
t.Errorf("should eq but not eq,want %v have %v", hex.EncodeToString(a), hex.EncodeToString(itr.Key()))
}
} else {
if bytes.Compare(itr.Key(), base[i-1].key) != 0 {
if !bytes.Equal(itr.Key(), base[i-1].key) {
t.Errorf("should eq but not eq,want %v have %v", hex.EncodeToString(base[i-1].key), hex.EncodeToString(itr.Key()))
}
}
Expand Down Expand Up @@ -523,10 +523,10 @@ func TestSnapshotDB_Ranking2(t *testing.T) {
if !itr.Next() {
return errors.New("it's must can itr")
}
if bytes.Compare(kv.value, itr.Value()) != 0 {
if !bytes.Equal(kv.value, itr.Value()) {
return fmt.Errorf("itr return wrong value :%v,should return:%v ", itr.Key(), kv.value)
}
if bytes.Compare(kv.key, itr.Key()) != 0 {
if !bytes.Equal(kv.key, itr.Key()) {
return fmt.Errorf("itr return wrong key :%v,should return:%v ", itr.Key(), kv.key)
}
}
Expand Down Expand Up @@ -824,7 +824,7 @@ func TestSnapshotDB_GetLastKVHash(t *testing.T) {
kvhash := ch.db.GetLastKVHash(common.ZeroHash)
lastkvhash = generateKVHash(arr[0], arr[0], lastkvhash)
lastkvhash = generateKVHash(arr[1], arr[1], lastkvhash)
if bytes.Compare(kvhash, lastkvhash.Bytes()) != 0 {
if !bytes.Equal(kvhash, lastkvhash.Bytes()) {
t.Error("kv hash must same", lastkvhash, kvhash)
}
})
Expand All @@ -833,7 +833,7 @@ func TestSnapshotDB_GetLastKVHash(t *testing.T) {
kvhash := ch.db.GetLastKVHash(recognizedHash)
lastkvhash = generateKVHash(arr[2], arr[2], lastkvhash)
lastkvhash = generateKVHash(arr[3], arr[3], lastkvhash)
if bytes.Compare(kvhash, lastkvhash.Bytes()) != 0 {
if !bytes.Equal(kvhash, lastkvhash.Bytes()) {
t.Error("kv hash must same", lastkvhash, kvhash)
}
})
Expand Down Expand Up @@ -863,7 +863,7 @@ func TestSnapshotDB_Compaction_del(t *testing.T) {
t.Error(err)
return
}
if bytes.Compare(v, delVal) != 0 {
if !bytes.Equal(v, delVal) {
t.Error("must same")
return
}
Expand Down Expand Up @@ -935,7 +935,7 @@ func TestSnapshotDB_Compaction222222(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(v, kv.value) != 0 {
if !bytes.Equal(v, kv.value) {
t.Error("value not the same")
}
}
Expand All @@ -957,7 +957,7 @@ func TestSnapshotDB_Compaction222222(t *testing.T) {
if err != nil {
t.Error(err)
}
if bytes.Compare(v, kv.value) != 0 {
if !bytes.Equal(v, kv.value) {
t.Error("value not the same")
}
}
Expand Down
13 changes: 4 additions & 9 deletions core/snapshotdb/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package snapshotdb

import (
"bytes"
"golang.org/x/crypto/sha3"
"math/big"
"math/rand"
"sort"
"time"

"golang.org/x/crypto/sha3"

"github.com/PlatONnetwork/PlatON-Go/core/types"

"github.com/PlatONnetwork/PlatON-Go/common"
Expand Down Expand Up @@ -108,10 +109,7 @@ func (k kvs) Len() int {

func (k kvs) Less(i, j int) bool {
n := bytes.Compare(k[i].key, k[j].key)
if n == -1 {
return true
}
return false
return n == -1
}

func (k kvs) Swap(i, j int) {
Expand All @@ -125,10 +123,7 @@ func (k kvsMaxToMin) Len() int {
}

func (k kvsMaxToMin) Less(i, j int) bool {
if bytes.Compare(k[i].key, k[j].key) >= 0 {
return true
}
return false
return bytes.Compare(k[i].key, k[j].key) >= 0
}

func (k kvsMaxToMin) Swap(i, j int) {
Expand Down

0 comments on commit e5ef480

Please sign in to comment.