prysm-pulse/beacon-chain/state/stateutil/blocks_test.go
Preston Van Loon b7175b3482
Update fastssz: Attempt 2 (#7115)
* Revert "Revert "Update fastssz" (#7100)"

This reverts commit b954db9704.
* Preston's patch
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Update fssz, add regression test case
* more HTR with fssz
* fix some tests
* only one test left
* Make it so that HTR will work
* gofmt, imports
* gofmt, imports
* fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* fix
* Merge branch 'master' into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* gaz
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* fix test
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
2020-08-27 18:13:32 +00:00

46 lines
1.5 KiB
Go

package stateutil_test
import (
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestBlockRoot(t *testing.T) {
genState, keys := testutil.DeterministicGenesisState(t, 100)
blk, err := testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 10)
require.NoError(t, err)
expectedRoot, err := blk.Block.HashTreeRoot()
require.NoError(t, err)
receivedRoot, err := stateutil.BlockRoot(blk.Block)
require.NoError(t, err)
require.Equal(t, expectedRoot, receivedRoot)
blk, err = testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 100)
require.NoError(t, err)
expectedRoot, err = blk.Block.HashTreeRoot()
require.NoError(t, err)
receivedRoot, err = stateutil.BlockRoot(blk.Block)
require.NoError(t, err)
require.Equal(t, expectedRoot, receivedRoot)
}
func TestBlockBodyRoot_NilIsSameAsEmpty(t *testing.T) {
a, err := (&ethpb.BeaconBlockBody{
RandaoReveal: make([]byte, 96),
Graffiti: make([]byte, 32),
Eth1Data: &ethpb.Eth1Data{
BlockHash: make([]byte, 32),
DepositCount: 0,
DepositRoot: make([]byte, 32),
},
}).HashTreeRoot()
require.NoError(t, err)
b, err := stateutil.BlockBodyRoot(nil)
require.NoError(t, err)
assert.Equal(t, a, b, "A nil and empty block body do not generate the same root")
}