feat(container): versioning for the CBOR container

This commit is contained in:
Fabio Bozzo
2024-11-13 18:03:00 +01:00
committed by Michael Muré
parent 9057cbcba6
commit 25ca34923f
4 changed files with 69 additions and 10 deletions

View File

@@ -176,3 +176,30 @@ func randToken() (*delegation.Token, cid.Cid, []byte) {
}
return t, c, b
}
func FuzzContainerRead(f *testing.F) {
// Generate a corpus
for tokenCount := 0; tokenCount < 10; tokenCount++ {
writer := NewWriter()
for i := 0; i < tokenCount; i++ {
_, c, data := randToken()
writer.AddSealed(c, data)
}
buf := bytes.NewBuffer(nil)
err := writer.ToCbor(buf)
require.NoError(f, err)
f.Add(buf.Bytes())
}
f.Fuzz(func(t *testing.T, data []byte) {
start := time.Now()
// search for panics
_, _ = FromCbor(bytes.NewReader(data))
if time.Since(start) > 100*time.Millisecond {
panic("too long")
}
})
}