multi: add fuzzer to make

This commit is contained in:
Oliver Gugger 2022-08-03 19:56:43 +02:00
parent 986d889b74
commit 1c9de5652e
No known key found for this signature in database
GPG key ID: 8E4256593F177720
3 changed files with 28 additions and 0 deletions

View file

@ -106,6 +106,7 @@ jobs:
unit_type:
- unit-race
- unit-cover
- fuzz
steps:
- name: git checkout
uses: actions/checkout@v2

View file

@ -12,6 +12,7 @@ GOIMPORTS_BIN := $(GO_BIN)/gosimports
GOBUILD := go build -v
GOINSTALL := go install -v
GOTEST := go test -v
GOFUZZ := go test -fuzztime 1m -fuzz
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name "*pb.go" -not -name "*pb.gw.go" -not -name "*.pb.json.go")
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
@ -100,6 +101,10 @@ unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
fuzz:
@$(call print, "Running fuzz tests.")
$(GOFUZZ) FuzzWitnessSpendDetection ./poolscript
# =============
# FLAKE HUNTING
# =============

View file

@ -89,3 +89,25 @@ func TestIncrementBatchKey(t *testing.T) {
require.Equal(t, startBatchKey, currentKey)
}
// FuzzWitnessSpendDetection fuzz tests the witness spend detection functions.
func FuzzWitnessSpendDetection(f *testing.F) {
f.Fuzz(func(t *testing.T, a, b, c, d []byte, num uint8) {
witness := make([][]byte, num)
if num > 0 {
witness[0] = a
}
if num > 1 {
witness[1] = b
}
if num > 2 {
witness[2] = c
}
if num > 3 {
witness[3] = d
}
_ = IsMultiSigSpend(witness)
_ = IsExpirySpend(witness)
})
}