diff --git a/Makefile b/Makefile index 546dd7cb79..623b05154a 100644 --- a/Makefile +++ b/Makefile @@ -160,3 +160,6 @@ pathfinder: juno-cached --p2p-peers=/ip4/127.0.0.1/tcp/8888/p2p/12D3KooWF1JrZWQoBiBSjsFSuLbDiDvqcmJQRLaFQLmpVkHA9duk \ --p2p-private-key="54a695e2a5d5717d5ba8730efcafe6f17251a1955733cffc55a4085fbf7f5d2c1b4009314092069ef7ca9b364ce3eb3072531c64dfb2799c6bad76720a5bdff0" \ --metrics-port=9094 + +test-fuzz: ## run fuzzing script + ./scripts/fuzz_all.sh diff --git a/scripts/fuzz_all.sh b/scripts/fuzz_all.sh new file mode 100755 index 0000000000..ece67fb600 --- /dev/null +++ b/scripts/fuzz_all.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +fuzzTime=${1:-10} + +files=$(grep -r --include='**_test.go' --files-with-matches 'func Fuzz' .) + +for file in ${files} +do + funcs=$(grep -o 'func Fuzz\w*' $file | sed 's/func //') + for func in ${funcs} + do + echo "Fuzzing $func in $file" + parentDir=$(dirname $file) + go test $parentDir -run=$func -fuzz=$func -fuzztime=${fuzzTime}s + done +done diff --git a/utils/compression_test.go b/utils/compression_test.go index 647ae1c192..2aacb58c95 100644 --- a/utils/compression_test.go +++ b/utils/compression_test.go @@ -19,3 +19,13 @@ func TestGzip64(t *testing.T) { require.NoError(t, err) assert.Equal(t, bytes, decompBytes) } + +func FuzzGzip64(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + compressed, err := utils.Gzip64Encode(data) + require.NoError(t, err) + decompressed, err := utils.Gzip64Decode(compressed) + require.NoError(t, err) + assert.Equal(t, data, decompressed) + }) +}