mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
66dcf2b80d
* Fixed bytesutil * Fix featureflag * Fix hashutil * Fix interop * Fix iputils * Fix mathutils * Fix messagehandler * Fix pagination * Fix params * Fix sliceutil * Fix merkletrie
32 lines
707 B
Go
32 lines
707 B
Go
package hashutil_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
|
)
|
|
|
|
func TestMerkleRoot(t *testing.T) {
|
|
valueSet := [][]byte{
|
|
{'a'},
|
|
{'b'},
|
|
{'c'},
|
|
{'d'},
|
|
}
|
|
|
|
hashedV1 := []byte{'a'}
|
|
hashedV2 := []byte{'b'}
|
|
hashedV3 := []byte{'c'}
|
|
hashedV4 := []byte{'d'}
|
|
|
|
leftNode := hashutil.Hash(append(hashedV1[:], hashedV2[:]...))
|
|
rightNode := hashutil.Hash(append(hashedV3[:], hashedV4[:]...))
|
|
expectedRoot := hashutil.Hash(append(leftNode[:], rightNode[:]...))
|
|
|
|
if !bytes.Equal(expectedRoot[:], hashutil.MerkleRoot(valueSet)) {
|
|
t.Errorf("Expected Merkle root and computed merkle root are not equal %#x , %#x", expectedRoot, hashutil.MerkleRoot(valueSet))
|
|
}
|
|
|
|
}
|