From c8d2888cf43318a44bd5e2abf070f5024bd4fc7f Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:57:31 +0300 Subject: [PATCH] fix: unit test fix --- pkg/pusher/pusher_test.go | 2 +- pkg/storage/storage.go | 2 +- pkg/storage/testing/chunk.go | 5 ++++- pkg/storer/reserve_test.go | 2 +- pkg/storer/sample_test.go | 4 ++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/pusher/pusher_test.go b/pkg/pusher/pusher_test.go index 3925e80ec31..fbdfb3a9acd 100644 --- a/pkg/pusher/pusher_test.go +++ b/pkg/pusher/pusher_test.go @@ -333,7 +333,7 @@ func TestPusherRetryShallow(t *testing.T) { // generate a chunk at PO 1 with closestPeer, meaning that we get a // receipt which is shallower than the pivot peer's depth, resulting // in retries - chunk := testingc.GenerateTestRandomChunkAt(t, closestPeer, 1) + chunk := testingc.GenerateValidRandomChunkAt(t, closestPeer, 1) storer.chunks <- chunk diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 0e2e0ac895d..312364e2676 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -324,5 +324,5 @@ func IdentityAddress(chunk swarm.Chunk) (swarm.Address, error) { return swarm.NewAddress(h.Sum(nil)), nil } - return swarm.EmptyAddress, fmt.Errorf("identity address failed on chunk %s: %w", chunk, ErrUnknownChunkType) + return swarm.ZeroAddress, fmt.Errorf("identity address failed on chunk %s: %w", chunk, ErrUnknownChunkType) } diff --git a/pkg/storage/testing/chunk.go b/pkg/storage/testing/chunk.go index f51c1079974..c5e83f845aa 100644 --- a/pkg/storage/testing/chunk.go +++ b/pkg/storage/testing/chunk.go @@ -91,10 +91,13 @@ func GenerateTestRandomChunkAt(tb testing.TB, target swarm.Address, po int) swar addr := swarm.RandAddressAt(tb, target, po) stamp := postagetesting.MustNewStamp() return swarm.NewChunk(addr, data).WithStamp(stamp) + } // GenerateTestRandomChunkAt generates an invalid (!) chunk with address of proximity order po wrt target. -func GenerateValidRandomChunkAt(target swarm.Address, po int) swarm.Chunk { +func GenerateValidRandomChunkAt(tb testing.TB, target swarm.Address, po int) swarm.Chunk { + tb.Helper() + data := make([]byte, swarm.ChunkSize) var ch swarm.Chunk diff --git a/pkg/storer/reserve_test.go b/pkg/storer/reserve_test.go index 79b38ac2ecd..c354f92cdbe 100644 --- a/pkg/storer/reserve_test.go +++ b/pkg/storer/reserve_test.go @@ -695,7 +695,7 @@ func TestNeighborhoodStats(t *testing.T) { putChunks := func(addr swarm.Address, startingRadius int, st *storer.DB) { putter := st.ReservePutter() for i := 0; i < chunkCountPerPO; i++ { - ch := chunk.GenerateValidRandomChunkAt(addr, startingRadius) + ch := chunk.GenerateValidRandomChunkAt(t, addr, startingRadius) err := putter.Put(context.Background(), ch) if err != nil { t.Fatal(err) diff --git a/pkg/storer/sample_test.go b/pkg/storer/sample_test.go index 2f97aaab13f..07f4e36cd6d 100644 --- a/pkg/storer/sample_test.go +++ b/pkg/storer/sample_test.go @@ -27,7 +27,7 @@ func TestReserveSampler(t *testing.T) { var chs []swarm.Chunk for po := 0; po < maxPO; po++ { for i := 0; i < chunkCountPerPO; i++ { - ch := chunk.GenerateValidRandomChunkAt(baseAddr, po).WithBatch(3, 2, false) + ch := chunk.GenerateValidRandomChunkAt(t, baseAddr, po).WithBatch(3, 2, false) if rand.Intn(2) == 0 { // 50% chance to wrap CAC into SOC ch = chunk.GenerateTestRandomSoChunk(t, ch) } @@ -156,7 +156,7 @@ func TestReserveSamplerSisterNeighborhood(t *testing.T) { var chs []swarm.Chunk for po := startingRadius; po < maxPO; po++ { for i := 0; i < chunkCountPerPO; i++ { - ch := chunk.GenerateValidRandomChunkAt(baseAddr, po).WithBatch(3, 2, false) + ch := chunk.GenerateValidRandomChunkAt(t, baseAddr, po).WithBatch(3, 2, false) if rand.Intn(2) == 0 { // 50% chance to wrap CAC into SOC ch = chunk.GenerateTestRandomSoChunk(t, ch) }