Add fuzz testing for Section encoding/decoding with multiple edge cases

This commit is contained in:
adman
2026-04-28 09:31:35 +02:00
parent ce0c58e7c5
commit 719a3bacd8
15 changed files with 289 additions and 65 deletions
+43
View File
@@ -0,0 +1,43 @@
package level_test
import (
"bytes"
"testing"
"github.com/admin-else/strom/level"
)
func FuzzSectionDeEnCodePacket(f *testing.F) {
f.Fuzz(func(t *testing.T, raw []byte) {
r := bytes.NewReader(raw)
s1, err := level.SectionDecodePacket(r, TestVersion)
if err != nil {
t.Skipf("decode failed: %v", err)
return
}
buf := bytes.NewBuffer(nil)
err = level.SectionEncodePacket(buf, s1)
if err != nil {
t.Fatal(err)
return
}
s2, err := level.SectionDecodePacket(buf, TestVersion)
if err != nil {
t.Fatal(err)
return
}
if s1.BlockCount != s2.BlockCount {
t.Error("BlockCount mismatch")
}
if level.CompareStorage(s1.Blocks, s2.Blocks) {
t.Error("Blocks mismatch")
}
if level.CompareStorage(s1.Biomes, s2.Biomes) {
t.Error("Biomes mismatch")
}
})
}