Skip to content

Commit

Permalink
fix: add TestGetWrappedChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Dec 12, 2024
1 parent fc11edd commit 16a6fdc
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions pkg/feeds/getter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package feeds

import (
"bytes"
"context"
"encoding/binary"
"testing"

soctesting "github.com/ethersphere/bee/v2/pkg/soc/testing"
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"
)

func TestGetWrappedChunk(t *testing.T) {
storer := mockstorer.New()

// new format (wraps chunk)
ch := soctesting.GenerateMockSOC(t, []byte("data")).Chunk()
wch, err := GetWrappedChunk(context.Background(), storer.ChunkStore(), ch)
if err != nil {
t.Fatal(err)
}

if !bytes.Equal(wch.Data()[8:], []byte("data")) {
t.Fatal("data mismatch")
}

// old format (ts + ref)
timestamp := make([]byte, 8)
binary.BigEndian.PutUint64(timestamp, 1)
ch = soctesting.GenerateMockSOC(t, append(timestamp, wch.Address().Bytes()...)).Chunk()

err = storer.Put(context.Background(), wch)
if err != nil {
t.Fatal(err)
}

wch, err = GetWrappedChunk(context.Background(), storer.ChunkStore(), ch)
if err != nil {
t.Fatal(err)
}

if !bytes.Equal(wch.Data()[8:], []byte("data")) {
t.Fatal("data mismatch")
}
}

0 comments on commit 16a6fdc

Please sign in to comment.