Skip to content

Commit

Permalink
fix: add reserve test case
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Oct 31, 2024
1 parent ec01cf9 commit 6e0a231
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/storer/internal/reserve/reserve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func TestSameChunkAddress(t *testing.T) {
t.Run("same address but index collision with different chunk", func(t *testing.T) {
size1 := r.Size()
batch := postagetesting.MustNewBatch()
ch1 := chunk.GenerateTestRandomChunkAt(t, baseAddr, 0).WithStamp(postagetesting.MustNewFields(batch.ID, 0, 0))
ch1 := chunk.GenerateTestRandomChunkAt(t, baseAddr, 0).WithStamp(postagetesting.MustNewFields(batch.ID, 0, 1))
err = r.Put(ctx, ch1)
if err != nil {
t.Fatal(err)
Expand All @@ -414,7 +414,7 @@ func TestSameChunkAddress(t *testing.T) {

signer := getSigner(t)
s1 := soctesting.GenerateMockSocWithSigner(t, []byte("data"), signer)
ch2 := s1.Chunk().WithStamp(postagetesting.MustNewFields(batch.ID, 1, 1))
ch2 := s1.Chunk().WithStamp(postagetesting.MustNewFields(batch.ID, 1, 2))
err = r.Put(ctx, ch2)
if err != nil {
t.Fatal(err)
Expand All @@ -432,8 +432,16 @@ func TestSameChunkAddress(t *testing.T) {
checkStore(t, ts.IndexStore(), &reserve.ChunkBinItem{Bin: bin1, BinID: binBinIDs[bin1], StampHash: ch1StampHash}, false)
checkStore(t, ts.IndexStore(), &reserve.ChunkBinItem{Bin: bin2, BinID: binBinIDs[bin2], StampHash: ch2StampHash}, false)

// attempt to replace existing (unrelated) chunk that has timestamp
s2 := soctesting.GenerateMockSocWithSigner(t, []byte("update"), signer)
ch3 := s2.Chunk().WithStamp(postagetesting.MustNewFields(batch.ID, 0, 2))
ch3 := s2.Chunk().WithStamp(postagetesting.MustNewFields(batch.ID, 0, 0))
err = r.Put(ctx, ch3)
if !errors.Is(err, storage.ErrOverwriteNewerChunk) {
t.Fatal("expected error")
}

s2 = soctesting.GenerateMockSocWithSigner(t, []byte("update"), signer)
ch3 = s2.Chunk().WithStamp(postagetesting.MustNewFields(batch.ID, 0, 3))
err = r.Put(ctx, ch3)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 6e0a231

Please sign in to comment.