-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathgetter_test.go
More file actions
84 lines (70 loc) · 1.92 KB
/
getter_test.go
File metadata and controls
84 lines (70 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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()
data := []byte("data")
// new format (wraps chunk)
ch := soctesting.GenerateMockSOC(t, data).Chunk()
wch, err := GetWrappedChunk(context.Background(), storer.ChunkStore(), ch, false)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(wch.Data()[8:], data) {
t.Fatal("data mismatch")
}
// old format
err = storer.Put(context.Background(), wch)
if err != nil {
t.Fatal(err)
}
tt := []struct {
name string
addr []byte
}{
{
name: "unencrypted",
addr: wch.Address().Bytes(),
},
{
name: "encrypted",
addr: append(wch.Address().Bytes(), wch.Address().Bytes()...),
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
timestamp := make([]byte, 8)
binary.BigEndian.PutUint64(timestamp, 1)
ch = soctesting.GenerateMockSOC(t, append(timestamp, tc.addr...)).Chunk()
wch, err = GetWrappedChunk(context.Background(), storer.ChunkStore(), ch, true)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(wch.Data()[8:], data) {
t.Fatal("data mismatch")
}
})
}
t.Run("returns feed legacy payload", func(t *testing.T) {
timestamp := make([]byte, 8)
binary.BigEndian.PutUint64(timestamp, 1)
feedChData := append(timestamp, wch.Address().Bytes()...)
ch = soctesting.GenerateMockSOC(t, feedChData).Chunk()
wch, err = GetWrappedChunk(context.Background(), storer.ChunkStore(), ch, false)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(wch.Data()[8:], feedChData) {
t.Fatal("data should be similar as old legacy feed payload format.")
}
})
}