mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
7ba500c417
* applies assertion funcs to beacon-chain/state tests * applies assertion funcs to beacon-chain/state/stategen tests * applies assertion funcs to beacon-chain/state/stateutil tests * gazelle * Merge refs/heads/master into state-apply-testutils-assertions * Merge refs/heads/master into state-apply-testutils-assertions * Merge refs/heads/master into state-apply-testutils-assertions
39 lines
1.4 KiB
Go
39 lines
1.4 KiB
Go
package stateutil_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
"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 := ssz.HashTreeRoot(blk.Block)
|
|
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 = ssz.HashTreeRoot(blk.Block)
|
|
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 := ssz.HashTreeRoot(ðpb.BeaconBlockBody{})
|
|
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")
|
|
}
|