github.com/consensys/gnark-crypto@v0.14.0/internal/generator/kzg/template/fuzz.test.go.tmpl (about)

     1  import (
     2  	"encoding/hex"
     3  	"io"
     4  	"math/rand"
     5  	"testing"
     6  	"time"
     7  	"runtime/debug"
     8  )
     9  
    10  func TestFuzz(t *testing.T) {
    11  	const maxBytes = 1 << 10
    12  	const testCount = 7
    13  	var bytes [maxBytes]byte
    14  	var i int
    15  	seed := time.Now().UnixNano()
    16  	defer func() {
    17  		if r := recover(); r != nil {
    18  			t.Error(r)
    19  			t.Error(string(debug.Stack()))
    20  			t.Fatal("test panicked", i, hex.EncodeToString(bytes[:i]), "seed", seed)
    21  		}
    22  	}()
    23  	r := rand.New(rand.NewSource(seed))
    24  
    25  	for i = 1; i < maxBytes; i++ {
    26  		for j := 0; j < testCount; j++ {
    27  			if _, err := io.ReadFull(r, bytes[:i]); err != nil {
    28  				t.Fatal("couldn't read random bytes", err)
    29  			}
    30  
    31  			Fuzz(bytes[:i]) 
    32  		}
    33  	}
    34  
    35  }