2019-10-04 22:46:49 +00:00
|
|
|
package hashutil_test
|
2018-12-27 06:48:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-10-04 22:46:49 +00:00
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
2020-07-19 21:08:29 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
2018-12-27 06:48:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMerkleRoot(t *testing.T) {
|
|
|
|
valueSet := [][]byte{
|
2019-01-09 09:49:17 +00:00
|
|
|
{'a'},
|
|
|
|
{'b'},
|
|
|
|
{'c'},
|
|
|
|
{'d'},
|
2018-12-27 06:48:09 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 18:21:35 +00:00
|
|
|
hashedV1 := []byte{'a'}
|
|
|
|
hashedV2 := []byte{'b'}
|
|
|
|
hashedV3 := []byte{'c'}
|
|
|
|
hashedV4 := []byte{'d'}
|
2018-12-30 03:03:36 +00:00
|
|
|
|
2019-10-04 22:46:49 +00:00
|
|
|
leftNode := hashutil.Hash(append(hashedV1[:], hashedV2[:]...))
|
|
|
|
rightNode := hashutil.Hash(append(hashedV3[:], hashedV4[:]...))
|
|
|
|
expectedRoot := hashutil.Hash(append(leftNode[:], rightNode[:]...))
|
2020-07-19 21:08:29 +00:00
|
|
|
assert.DeepEqual(t, expectedRoot[:], hashutil.MerkleRoot(valueSet))
|
2018-12-27 06:48:09 +00:00
|
|
|
}
|