Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Jun 22, 2024
1 parent 739a880 commit fe1049e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions node/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ func (s *Store) DeleteKeys(ctx context.Context, keys *[][]byte) error {
//
// EncodeChunks implements encoding format "001"
func EncodeChunks(chunks [][]byte) ([]byte, error) {
if len(chunks) == 0 {
return []byte{}, nil
}
totalSize := 0
for _, chunk := range chunks {
totalSize += len(chunk)
}
result := make([]byte, totalSize+8)
if len(chunks) == 0 {
return result, nil
}
buf := result
chunkSize := uint64(len(chunks[0])) | (1 << 61)
binary.LittleEndian.PutUint64(buf, chunkSize)
Expand Down
12 changes: 7 additions & 5 deletions node/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,22 @@ func TestDecodeCompactChunks(t *testing.T) {
_, err = node.DecodeChunks(invalid)
assert.EqualError(t, err, "unrecognized chunks encoding format")
data := make([]byte, 0, 9)
data = append(data, byte(2))
for i := 0; i < 6; i++ {
data = append(data, byte(0))
}
data = append(data, byte(2))
data = append(data, byte(0b00100000))
data = append(data, byte(0))
data = append(data, byte(5))
_, err = node.DecodeChunks(data)
assert.EqualError(t, err, "invalid compact data to decode")
data = append(data, byte(0))
data = append(data, byte(6))
data = append(data, byte(7))
data = append(data, byte(8))
chunks, err := node.DecodeChunks(data)
assert.Nil(t, err)
assert.Equal(t, 2, len(chunks))
assert.Equal(t, byte(0), chunks[0])
assert.Equal(t, byte(1), chunks[1])
assert.Equal(t, []byte{byte(5), byte(6)}, chunks[0])
assert.Equal(t, []byte{byte(7), byte(8)}, chunks[1])
}

func TestStoringBlob(t *testing.T) {
Expand Down

0 comments on commit fe1049e

Please sign in to comment.