Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fuzz tests for utils #1982

Merged
merged 8 commits into from
Sep 25, 2024
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
kirugan marked this conversation as resolved.
Show resolved Hide resolved
./scripts/fuzz_all.sh
18 changes: 18 additions & 0 deletions scripts/fuzz_all.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions utils/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}