prysm-pulse/beacon-chain/state/stateutil/blocks_test.go
Nishant Das cdac3d61ea
Custom Block HTR (#5219)
* add custom htr

* fix root

* fix everything

* Apply suggestions from code review

* Update beacon-chain/state/stateutil/blocks.go

* Update beacon-chain/blockchain/receive_block.go

Co-Authored-By: terence tsao <terence@prysmaticlabs.com>

* Update beacon-chain/blockchain/process_block.go

Co-Authored-By: terence tsao <terence@prysmaticlabs.com>

* terence's review

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-03-26 13:10:22 -05:00

44 lines
1.1 KiB
Go

package stateutil_test
import (
"testing"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
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 := ssz.HashTreeRoot(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 = ssz.HashTreeRoot(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)
}
}