prysm-pulse/beacon-chain/state/stateutil/blocks_test.go
Preston Van Loon b00bbfeec7
Release enableCustomBlockHTR to all (#5742)
* Release deprecatedEnableCustomBlockHTR to all

* Release deprecatedEnableCustomBlockHTR to all

* Fix builds

* Treat nil body as empty

* Use custom HTR in signing root

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-05-08 13:50:39 -07:00

59 lines
1.4 KiB
Go

package stateutil_test
import (
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
)
func TestBlockRoot(t *testing.T) {
genState, keys := testutil.DeterministicGenesisState(t, 100)
blk, err := testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 10)
if err != nil {
t.Fatal(err)
}
expectedRoot, err := stateutil.BlockRoot(blk.Block)
if err != nil {
t.Fatal(err)
}
receivedRoot, err := stateutil.BlockRoot(blk.Block)
if err != nil {
t.Fatal(err)
}
if receivedRoot != expectedRoot {
t.Fatalf("Wanted %#x but got %#x", expectedRoot, receivedRoot)
}
blk, err = testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 100)
if err != nil {
t.Fatal(err)
}
expectedRoot, err = stateutil.BlockRoot(blk.Block)
if err != nil {
t.Fatal(err)
}
receivedRoot, err = stateutil.BlockRoot(blk.Block)
if err != nil {
t.Fatal(err)
}
if receivedRoot != expectedRoot {
t.Fatalf("Wanted %#x but got %#x", expectedRoot, receivedRoot)
}
}
func TestBlockBodyRoot_NilIsSameAsEmpty(t *testing.T) {
a, err := stateutil.BlockBodyRoot(&ethpb.BeaconBlockBody{})
if err != nil {
t.Error(err)
}
b, err := stateutil.BlockBodyRoot(nil)
if err != nil {
t.Error(err)
}
if a != b {
t.Log(a)
t.Log(b)
t.Error("A nil and empty block body do not generate the same root")
}
}