2020-03-26 18:10:22 +00:00
|
|
|
package stateutil_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-05-14 22:11:52 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-03-26 18:10:22 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
2020-07-18 07:56:48 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-03-26 18:10:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBlockRoot(t *testing.T) {
|
|
|
|
genState, keys := testutil.DeterministicGenesisState(t, 100)
|
|
|
|
blk, err := testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 10)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-27 18:13:32 +00:00
|
|
|
expectedRoot, err := blk.Block.HashTreeRoot()
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-03-26 18:10:22 +00:00
|
|
|
receivedRoot, err := stateutil.BlockRoot(blk.Block)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedRoot, receivedRoot)
|
2020-03-26 18:10:22 +00:00
|
|
|
blk, err = testutil.GenerateFullBlock(genState, keys, testutil.DefaultBlockGenConfig(), 100)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-27 18:13:32 +00:00
|
|
|
expectedRoot, err = blk.Block.HashTreeRoot()
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-03-26 18:10:22 +00:00
|
|
|
receivedRoot, err = stateutil.BlockRoot(blk.Block)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedRoot, receivedRoot)
|
2020-03-26 18:10:22 +00:00
|
|
|
}
|
2020-05-08 20:50:39 +00:00
|
|
|
|
|
|
|
func TestBlockBodyRoot_NilIsSameAsEmpty(t *testing.T) {
|
2020-08-27 18:13:32 +00:00
|
|
|
a, err := (ðpb.BeaconBlockBody{
|
|
|
|
RandaoReveal: make([]byte, 96),
|
|
|
|
Graffiti: make([]byte, 32),
|
|
|
|
Eth1Data: ðpb.Eth1Data{
|
|
|
|
BlockHash: make([]byte, 32),
|
|
|
|
DepositCount: 0,
|
|
|
|
DepositRoot: make([]byte, 32),
|
|
|
|
},
|
|
|
|
}).HashTreeRoot()
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-05-08 20:50:39 +00:00
|
|
|
b, err := stateutil.BlockBodyRoot(nil)
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, a, b, "A nil and empty block body do not generate the same root")
|
2020-05-14 22:11:52 +00:00
|
|
|
}
|