Skip to content

Commit

Permalink
Add fuzz tests for utils (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil authored Sep 25, 2024
1 parent b240aba commit 48fb6c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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
./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)
})
}

0 comments on commit 48fb6c5

Please sign in to comment.