Add policy decode fuzz tests #219
5 changed files with 45 additions and 13 deletions
1
go.mod
1
go.mod
|
@ -34,6 +34,7 @@ require (
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230615193820-9185820289ce // indirect
|
||||
github.com/nspcc-dev/rfc6979 v0.2.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rogpeppe/go-internal v1.8.1 // indirect
|
||||
github.com/twmb/murmur3 v1.1.8 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/goleak v1.2.1 // indirect
|
||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
|
@ -7,8 +7,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDecodeString(t *testing.T) {
|
||||
testCases := []string{
|
||||
var validPlacementPolicy = []string{
|
||||
`REP 2
|
||||
CBF 2
|
||||
SELECT 2 FROM *`,
|
||||
|
@ -46,11 +45,12 @@ REP 1
|
|||
REP 1`,
|
||||
`EC 1.2 IN X
|
||||
SELECT 3 IN City FROM * AS X`,
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeString(t *testing.T) {
|
||||
var p PlacementPolicy
|
||||
|
||||
for _, testCase := range testCases {
|
||||
for _, testCase := range validPlacementPolicy {
|
||||
require.NoError(t, p.DecodeString(testCase), "unable parse %s", testCase)
|
||||
var b strings.Builder
|
||||
require.NoError(t, p.WriteStringTo(&b))
|
||||
|
|
14
netmap/policy_fuzz.go
Normal file
14
netmap/policy_fuzz.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
//go:build gofuzz
|
||||
// +build gofuzz
|
||||
|
||||
package netmap
|
||||
|
||||
func DoFuzzPlacementPolicyDecode(data []byte) int {
|
||||
p := string(data)
|
||||
if p == "" {
|
||||
return 0
|
||||
}
|
||||
var pp PlacementPolicy
|
||||
_ = pp.DecodeString(p)
|
||||
return 1
|
||||
}
|
17
netmap/policy_fuzz_test.go
Normal file
17
netmap/policy_fuzz_test.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
//go:build gofuzz
|
||||
// +build gofuzz
|
||||
|
||||
package netmap
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func FuzzDecodeString(f *testing.F) {
|
||||
for _, pp := range validPlacementPolicy {
|
||||
f.Add([]byte(pp))
|
||||
}
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
DoFuzzPlacementPolicyDecode(data)
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue