mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
edeb359ded
* Use ssz htr as baseline to compare * Merge branch 'master' into fix-test * One more. Fix for TestBlockBodyRoot_NilIsSameAsEmpty * Merge branch 'fix-test' of github.com:prysmaticlabs/prysm into fix-test
61 lines
1.5 KiB
Go
61 lines
1.5 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"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
func TestBlockBodyRoot_NilIsSameAsEmpty(t *testing.T) {
|
|
a, err := ssz.HashTreeRoot(ð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")
|
|
}
|
|
}
|