github.com/prysmaticlabs/prysm@v1.4.4/shared/testutil/state_test.go (about)

     1  package testutil
     2  
     3  import (
     4  	"context"
     5  	"reflect"
     6  	"testing"
     7  
     8  	pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
     9  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
    10  )
    11  
    12  func TestNewBeaconState(t *testing.T) {
    13  	st, err := NewBeaconState()
    14  	require.NoError(t, err)
    15  	b, err := st.MarshalSSZ()
    16  	require.NoError(t, err)
    17  	got := &pb.BeaconState{}
    18  	require.NoError(t, got.UnmarshalSSZ(b))
    19  	if !reflect.DeepEqual(st.InnerStateUnsafe(), got) {
    20  		t.Fatal("State did not match after round trip marshal")
    21  	}
    22  }
    23  
    24  func TestNewBeaconState_HashTreeRoot(t *testing.T) {
    25  	st, err := NewBeaconState()
    26  	require.NoError(t, err)
    27  	_, err = st.HashTreeRoot(context.Background())
    28  	require.NoError(t, err)
    29  	st, err = NewBeaconState()
    30  	require.NoError(t, err)
    31  	_, err = st.HashTreeRoot(context.Background())
    32  	require.NoError(t, err)
    33  }