From 0284539015f4ca52a97c1cc92e9dbae8caa61de0 Mon Sep 17 00:00:00 2001 From: clearly <910372762@qq.com> Date: Thu, 7 Sep 2023 10:18:19 +0800 Subject: [PATCH] fix test --- core/snapshotdb/current.go | 7 +++++-- core/snapshotdb/db_test.go | 2 +- core/snapshotdb/snapshotdb_test.go | 12 ++++++------ eth/downloader/downloader_test.go | 10 +++++----- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/snapshotdb/current.go b/core/snapshotdb/current.go index f5909b01c1..5b58565f12 100644 --- a/core/snapshotdb/current.go +++ b/core/snapshotdb/current.go @@ -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 . - package snapshotdb import ( @@ -113,7 +112,7 @@ func (c *current) Valid() error { return nil } -//the current highest must not greater than block chain current +// the current highest must not greater than block chain current func (c *current) resetHighestByChainCurrentHeader(currentHead *types.Header, baseDB *leveldb.DB) error { if c.base.Num.Cmp(currentHead.Number) > 0 { return fmt.Errorf("base num %v can't be greater than currentHead Number %v", c.base.Num, currentHead.Number) @@ -206,6 +205,10 @@ func (c *current) EncodeBase() []byte { return base } +func (c *current) String() string { + return fmt.Sprintf("base:%d,hight:%d,%s,", c.base.Num, c.highest.Num, c.highest.Hash) +} + type CurrentHighest struct { Num *big.Int `rlp:"nil"` Hash common.Hash diff --git a/core/snapshotdb/db_test.go b/core/snapshotdb/db_test.go index 85232a3b6b..a6f661d528 100644 --- a/core/snapshotdb/db_test.go +++ b/core/snapshotdb/db_test.go @@ -107,7 +107,7 @@ func TestRecover(t *testing.T) { return } for _, value := range baseDBArr { - v, err := ch.db.baseDB.Get(value.key, nil) + v, err := ch.db.Get(ch.db.current.highest.Hash, value.key) if err != nil { t.Error("should be nil", err) return diff --git a/core/snapshotdb/snapshotdb_test.go b/core/snapshotdb/snapshotdb_test.go index 3f5965af57..f2cd9cbde8 100644 --- a/core/snapshotdb/snapshotdb_test.go +++ b/core/snapshotdb/snapshotdb_test.go @@ -593,11 +593,11 @@ func TestSnapshotDB_Ranking4(t *testing.T) { itr.Release() return o } - v := f(common.ZeroHash, "aaa", 1000) + v := f(ch.db.current.highest.Hash, "aaa", 1000) if err := v.compareWithkvs(generatekvs); err != nil { t.Error(err) } - v2 := f(common.ZeroHash, "aaa", 0) + v2 := f(ch.db.current.highest.Hash, "aaa", 0) if err := v2.compareWithkvs(generatekvs); err != nil { t.Error(err) } @@ -755,8 +755,8 @@ func TestSnapshotDB_WalkBaseDB(t *testing.T) { t.Run("kv should compare", func(t *testing.T) { var kvGetFromWalk kvs f := func(num *big.Int, iter iterator.Iterator) error { - if num.Int64() != 2 { - return fmt.Errorf("basenum is wrong:%v,should be 2", num) + if num.Int64() != 1 { + return fmt.Errorf("basenum is wrong:%v,should be 1", num) } for iter.Next() { k, v := make([]byte, len(iter.Key())), make([]byte, len(iter.Value())) @@ -858,7 +858,7 @@ func TestSnapshotDB_Compaction_del(t *testing.T) { } delkey := baseDBkv[0].key delVal := baseDBkv[0].value - v, err := ch.db.GetBaseDB(delkey) + v, err := ch.db.Get(ch.db.current.highest.Hash, delkey) if err != nil { t.Error(err) return @@ -872,7 +872,7 @@ func TestSnapshotDB_Compaction_del(t *testing.T) { t.Error(err) } - _, err = ch.db.GetBaseDB(delkey) + _, err = ch.db.Get(ch.db.current.highest.Hash, delkey) if err != ErrNotFound { t.Error(err) return diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index a89cf083f6..5a8e80ffc5 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -494,7 +494,7 @@ func (dlp *downloadTesterPeer) RequestNodeData(hashes []common.Hash) error { return nil } -func (dlp *downloadTesterPeer) RequestPPOSStorage() error { +func (dlp *downloadTesterPeer) RequestPPOSStorage(num uint64) error { dlp.dl.lock.RLock() defer dlp.dl.lock.RUnlock() Pivot := dlp.chain.headerm[dlp.chain.chain[dlp.chain.baseNum]] @@ -516,14 +516,14 @@ func (dlp *downloadTesterPeer) RequestPPOSStorage() error { KVNum++ count++ if count >= eth.PPOSStorageKVSizeFetch { - if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, false, KVNum); err != nil { + if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, false, KVNum, nil, 0); err != nil { logger.Error("[GetPPOSStorageMsg]send ppos meassage fail", "error", err, "kvnum", KVNum) return err } count = 0 ps = make([][2][]byte, 0) } - if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, true, KVNum); err != nil { + if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, true, KVNum, nil, 0); err != nil { logger.Error("[GetPPOSStorageMsg]send last ppos meassage fail", "error", err) return err } @@ -1592,8 +1592,8 @@ func (ftp *floodingTestPeer) RequestNodeData(hashes []common.Hash) error { return ftp.peer.RequestNodeData(hashes) } -func (ftp *floodingTestPeer) RequestPPOSStorage() error { - return ftp.peer.RequestPPOSStorage() +func (ftp *floodingTestPeer) RequestPPOSStorage(num uint64) error { + return ftp.peer.RequestPPOSStorage(num) } func (ftp *floodingTestPeer) RequestOriginAndPivotByCurrent(d uint64) error {