prysm-pulse/beacon-chain/state/stateutil/blocks_test.go
Preston Van Loon 9be8a456eb
Use stateutil.BlockRoot everywhere (#5739)
* Sweeping replace of ssz.HashTreeRoot(block) to stateutil.BlockRoot, minor tweaks to critical path of proposeBlock
* imports
* Merge branch 'master' into better-block-htr
* Add --enable-custom-block-htr to e2e flags
* Merge branch 'better-block-htr' of github.com:prysmaticlabs/prysm into better-block-htr
2020-05-05 04:30:24 +00:00

46 lines
1.2 KiB
Go

package stateutil_test
import (
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
func TestBlockRoot(t *testing.T) {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableBlockHTR: true})
defer resetCfg()
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)
}
}