func TestHashOverFiles(t *testing.T) {
	b := []byte("firstcontent")
	hash := util.ComputeSHA256(b)
	hash, err := HashFilesInDir(".", "hashtestfiles1", hash, nil)
	if err != nil {
		t.Fail()
		t.Logf("error : %s", err)
	}
	expectedHash := "0c92180028200dfabd08d606419737f5cdecfcbab403e3f0d79e8d949f4775bc"
	computedHash := hex.EncodeToString(hash[:])
	if expectedHash != computedHash {
		t.Error("Hash expected to be unchanged")
	}
}
TestHashOverFiles computes hash over a directory and ensures it matches precomputed, hardcoded, hash
package util
import (
	"archive/tar"
	"bytes"
	"compress/gzip"
	"encoding/hex"
	"fmt"
	"io"
	"io/ioutil"
	"math/rand"
	"os"
	"strings"
	"testing"
	"time"
	"github.com/inklabsfoundation/inkchain/common/util"
	"github.com/inklabsfoundation/inkchain/core/config"
	cutil "github.com/inklabsfoundation/inkchain/core/container/util"
	"github.com/spf13/viper"
	"github.com/stretchr/testify/assert"
)
func TestHashContentChange(t *testing.T) {
	b := []byte("firstcontent")
	hash := util.ComputeSHA256(b)
	b2 := []byte("To be, or not to be- that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune Or to take arms against a sea of troubles, And by opposing end them. To die- to sleep- No more; and by a sleep to say we end The heartache, and the thousand natural shocks That flesh is heir to. 'Tis a consummation Devoutly to be wish'd.")
	h1 := ComputeHash(b2, hash)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	randIndex := (int(r.Uint32())) % len(b2)
	randByte := byte((int(r.Uint32())) % 128)
	for {
		if randByte != b2[randIndex] {
			break
		}
		randByte = byte((int(r.Uint32())) % 128)
	}
	b2[randIndex] = randByte
	h2 := ComputeHash(b2, hash)
	if bytes.Compare(h1, h2) == 0 {
		t.Error("Hash expected to be different but is same")
	}
}
func TestHashLenChange(t *testing.T) {
	b := []byte("firstcontent")
	hash := util.ComputeSHA256(b)
	b2 := []byte("To be, or not to be-")
	h1 := ComputeHash(b2, hash)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	randIndex := (int(r.Uint32())) % len(b2)
	b2 = b2[0:randIndex]
	h2 := ComputeHash(b2, hash)
	if bytes.Compare(h1, h2) == 0 {
		t.Error("Hash expected to be different but is same")
	}
}
func TestHashOrderChange(t *testing.T) {
	b := []byte("firstcontent")
	hash := util.ComputeSHA256(b)
	b2 := [][]byte{[]byte("To be, or not to be- that is the question:"),
		[]byte("Whether 'tis nobler in the mind to suffer"),
		[]byte("The slings and arrows of outrageous fortune"),
		[]byte("Or to take arms against a sea of troubles,"),
		[]byte("And by opposing end them."),
		[]byte("To die- to sleep- No more; and by a sleep to say we end"),
		[]byte("The heartache, and the thousand natural shocks"),
		[]byte("That flesh is heir to."),
		[]byte("'Tis a consummation Devoutly to be wish'd.")}
	h1 := hash
	for _, l := range b2 {
		h1 = ComputeHash(l, h1)
	}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	randIndex1 := (int(r.Uint32())) % len(b2)
	randIndex2 := (int(r.Uint32())) % len(b2)
	for {
		if randIndex2 != randIndex1 {
			break
		}
		randIndex2 = (int(r.Uint32())) % len(b2)
	}
	tmp := b2[randIndex2]
	b2[randIndex2] = b2[randIndex1]
	b2[randIndex1] = tmp
	h2 := hash
	for _, l := range b2 {
		h2 = ComputeHash(l, hash)
	}
	if bytes.Compare(h1, h2) == 0 {
		t.Error("Hash expected to be different but is same")
	}
}