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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2020-05-05 04:30:24 +00:00
|
|
|
expectedRoot, err := stateutil.BlockRoot(blk.Block)
|
2020-03-26 18:10:22 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-05-05 04:30:24 +00:00
|
|
|
expectedRoot, err = stateutil.BlockRoot(blk.Block)
|
2020-03-26 18:10:22 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2020-05-08 20:50:39 +00:00
|
|
|
|
|
|
|
func TestBlockBodyRoot_NilIsSameAsEmpty(t *testing.T) {
|
|
|
|
a, err := stateutil.BlockBodyRoot(ðpb.BeaconBlockBody{})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
b, err := stateutil.BlockBodyRoot(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if a != b {
|
|
|
|
t.Log(a)
|
|
|
|
t.Log(b)
|
|
|
|
t.Error("A nil and empty block body do not generate the same root")
|
|
|
|
}
|
2020-05-14 22:11:52 +00:00
|
|
|
}
|