github.com/cosmos/cosmos-sdk@v0.50.10/fuzz/tests/types_parsetimebytes_test.go (about) 1 //go:build gofuzz || go1.18 2 3 package tests 4 5 import ( 6 "bytes" 7 "fmt" 8 "testing" 9 10 "github.com/cosmos/cosmos-sdk/types" 11 ) 12 13 func FuzzTypesParseTimeBytes(f *testing.F) { 14 f.Fuzz(func(t *testing.T, bin []byte) { 15 // Normalize input, reject invalid timestamps. 16 ti, err := types.ParseTimeBytes(bin) 17 if err != nil { 18 return 19 } 20 brt := types.FormatTimeBytes(ti) 21 // Check that roundtripping a normalized timestamp doesn't change it. 22 ti2, err := types.ParseTimeBytes(brt) 23 if err != nil { 24 panic(fmt.Errorf("failed to parse formatted time %q: %w", brt, err)) 25 } 26 brt2 := types.FormatTimeBytes(ti2) 27 if !bytes.Equal(brt, brt2) { 28 panic(fmt.Sprintf("Roundtrip failure, got\n%q\nwant\n%q", brt, brt2)) 29 } 30 }) 31 }