From 3b1d06cec448c20f2ff4e2cdb81314e993810c66 Mon Sep 17 00:00:00 2001 From: "iteyelmp@gmail.com" Date: Thu, 9 Nov 2023 16:05:49 +0800 Subject: [PATCH] fix test error --- cmd/es-utils/utils/utils_test.go | 1 + ethstorage/p2p/protocol/sync_test.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/es-utils/utils/utils_test.go b/cmd/es-utils/utils/utils_test.go index 7fa81905..3db3d8b1 100644 --- a/cmd/es-utils/utils/utils_test.go +++ b/cmd/es-utils/utils/utils_test.go @@ -21,6 +21,7 @@ func TestEncodeDecodeBlob(t *testing.T) { t.Run("", func(t *testing.T) { encoded := EncodeBlobs(data) decoded := DecodeBlob(encoded[0][:]) + decoded = decoded[:len(data)] if !bytes.Equal(data, decoded) { t.Errorf("data:\n%v\nencoded/decoded:\n%v\n", data, decoded) } diff --git a/ethstorage/p2p/protocol/sync_test.go b/ethstorage/p2p/protocol/sync_test.go index 1325b204..28c1d0f5 100644 --- a/ethstorage/p2p/protocol/sync_test.go +++ b/ethstorage/p2p/protocol/sync_test.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" + "github.com/ethstorage/go-ethstorage/cmd/es-utils/utils" "github.com/ethstorage/go-ethstorage/ethstorage" prv "github.com/ethstorage/go-ethstorage/ethstorage/prover" "github.com/ethstorage/go-ethstorage/ethstorage/rollup" @@ -718,15 +719,21 @@ func TestReadWrite(t *testing.T) { }(files) sm := ethstorage.ContractToShardManager[contract] - success, err := sm.TryWrite(0, []byte{1}, common.Hash{}) + + bs := []byte{1} + blobs := utils.EncodeBlobs(bs) + _, _, versionedHashes, err := utils.ComputeBlobs(blobs) + success, err := sm.TryWrite(0, blobs[0][:], versionedHashes[0]) if !success || err != nil { t.Fatalf("failed to write") } - rdata, success, err := sm.TryRead(0, 1, common.Hash{}) + // blob is 01000...000 + rdata, success, err := sm.TryRead(0, 2, versionedHashes[0]) if !success || err != nil { t.Fatalf("failed to read") } - if !bytes.Equal([]byte{1}, rdata) { + // data is blob 2 index + if !bytes.Equal([]byte{1}, rdata[1:2]) { t.Fatalf("failed to compare") } }