diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 02333ef..51442f3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -106,6 +106,7 @@ jobs: unit_type: - unit-race - unit-cover + - fuzz steps: - name: git checkout uses: actions/checkout@v2 diff --git a/Makefile b/Makefile index 3335cee..ca31a7a 100644 --- a/Makefile +++ b/Makefile @@ -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 # ============= diff --git a/poolscript/script_test.go b/poolscript/script_test.go index 88428cf..9678f30 100644 --- a/poolscript/script_test.go +++ b/poolscript/script_test.go @@ -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) + }) +}