Skip to content

Commit

Permalink
fix: unit test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Nov 11, 2024
1 parent 8760edc commit c8d2888
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/pusher/pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 4 additions & 1 deletion pkg/storage/testing/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/storer/reserve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/storer/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit c8d2888

Please sign in to comment.