func TestHasherReuse(t *testing.T) {
	t.Run(fmt.Sprintf("poolsize_%d", 1), func(t *testing.T) {
		testHasherReuse(t, 1)
	})
	t.Run(fmt.Sprintf("poolsize_%d", testPoolSize), func(t *testing.T) {
		testHasherReuse(t, testPoolSize)
	})
}
tests that the BMT hasher can be synchronously reused with poolsizes 1 and testPoolSize
package bmt_test
import (
	"bytes"
	"context"
	"fmt"
	"io"
	"math/rand"
	"sort"
	"testing"
	"time"
	"github.com/ethsana/sana/pkg/bmt"
	"github.com/ethsana/sana/pkg/bmt/reference"
	"github.com/ethsana/sana/pkg/swarm"
	"golang.org/x/sync/errgroup"
)
const (
	testPoolSize = 16
	testSegmentCount = 128
)
var (
	testSegmentCounts = []int{1, 2, 3, 4, 5, 8, 9, 15, 16, 17, 32, 37, 42, 53, 63, 64, 65, 111, 127, 128}
	hashSize          = swarm.NewHasher().Size()
	seed              = time.Now().Unix()
)
func refHash(count int, data []byte) ([]byte, error) {
	rbmt := reference.NewRefHasher(swarm.NewHasher(), count)
	refNoMetaHash, err := rbmt.Hash(data)
	if err != nil {
		return nil, err
	}
	return bmt.Sha3hash(bmt.LengthToSpan(int64(len(data))), refNoMetaHash)
}
func syncHash(h *bmt.Hasher, data []byte) ([]byte, error) {
	h.Reset()
	h.SetHeaderInt64(int64(len(data)))
	_, err := h.Write(data)
	if err != nil {
		return nil, err
	}
	return h.Hash(nil)
}
func TestHasherEmptyData(t *testing.T) {
	for _, count := range testSegmentCounts {
		t.Run(fmt.Sprintf("%d_segments", count), func(t *testing.T) {
			expHash, err := refHash(count, nil)
			if err != nil {
				t.Fatal(err)
			}
			pool := bmt.NewPool(bmt.NewConf(swarm.NewHasher, count, 1))
			h := pool.Get()
			resHash, err := syncHash(h, nil)
			if err != nil {
				t.Fatal(err)
			}
			pool.Put(h)
			if !bytes.Equal(expHash, resHash) {
				t.Fatalf("hash mismatch with reference. expected %x, got %x", expHash, resHash)
			}
		})
	}
}
func TestSyncHasherCorrectness(t *testing.T) {
	testData := randomBytes(t, seed)
	for _, count := range testSegmentCounts {
		t.Run(fmt.Sprintf("segments_%v", count), func(t *testing.T) {
			max := count * hashSize
			var incr int
			capacity := 1
			pool := bmt.NewPool(bmt.NewConf(swarm.NewHasher, count, capacity))
			for n := 0; n <= max; n += incr {
				h := pool.Get()
				incr = 1 + rand.Intn(5)
				err := testHasherCorrectness(h, testData, n, count)
				if err != nil {
					t.Fatalf("seed %d: %v", seed, err)
				}
				pool.Put(h)
			}
		})
	}
}