2021-11-29 16:30:17 +00:00
|
|
|
package stateutil
|
2021-11-17 09:04:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
2021-11-17 09:04:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestArraysTreeRoot_OnlyPowerOf2(t *testing.T) {
|
2022-05-09 13:02:34 +00:00
|
|
|
_, err := ArraysRoot([][]byte{}, 1)
|
2021-11-17 09:04:49 +00:00
|
|
|
assert.NoError(t, err)
|
2022-05-09 13:02:34 +00:00
|
|
|
_, err = ArraysRoot([][]byte{}, 4)
|
2021-11-17 09:04:49 +00:00
|
|
|
assert.NoError(t, err)
|
2022-05-09 13:02:34 +00:00
|
|
|
_, err = ArraysRoot([][]byte{}, 8)
|
2021-11-17 09:04:49 +00:00
|
|
|
assert.NoError(t, err)
|
2022-05-09 13:02:34 +00:00
|
|
|
_, err = ArraysRoot([][]byte{}, 10)
|
2021-11-17 09:04:49 +00:00
|
|
|
assert.ErrorContains(t, "hash layer is a non power of 2", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestArraysTreeRoot_ZeroLength(t *testing.T) {
|
2022-05-09 13:02:34 +00:00
|
|
|
_, err := ArraysRoot([][]byte{}, 0)
|
2021-11-17 09:04:49 +00:00
|
|
|
assert.ErrorContains(t, "zero leaves provided", err)
|
|
|
|
}
|