prysm-pulse/testing/util/state_test.go
terencechain d17996f8b0
Update to V4 🚀 (#12134)
* Update V3 from V4

* Fix build v3 -> v4

* Update ssz

* Update beacon_chain.pb.go

* Fix formatter import

* Update update-mockgen.sh comment to v4

* Fix conflicts. Pass build and tests

* Fix test
2023-03-17 18:52:56 +00:00

78 lines
2.1 KiB
Go

package util
import (
"context"
"reflect"
"testing"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/testing/require"
)
func TestNewBeaconState(t *testing.T) {
st, err := NewBeaconState()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconState{}
require.NoError(t, got.UnmarshalSSZ(b))
if !reflect.DeepEqual(st.ToProtoUnsafe(), got) {
t.Fatal("State did not match after round trip marshal")
}
}
func TestNewBeaconStateAltair(t *testing.T) {
st, err := NewBeaconStateAltair()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconStateAltair{}
require.NoError(t, got.UnmarshalSSZ(b))
if !reflect.DeepEqual(st.ToProtoUnsafe(), got) {
t.Fatal("State did not match after round trip marshal")
}
}
func TestNewBeaconStateBellatrix(t *testing.T) {
st, err := NewBeaconStateBellatrix()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconStateBellatrix{}
require.NoError(t, got.UnmarshalSSZ(b))
if !reflect.DeepEqual(st.ToProtoUnsafe(), got) {
t.Fatal("State did not match after round trip marshal")
}
}
func TestNewBeaconStateCapella(t *testing.T) {
st, err := NewBeaconStateCapella()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconStateCapella{}
require.NoError(t, got.UnmarshalSSZ(b))
if !reflect.DeepEqual(st.ToProtoUnsafe(), got) {
t.Fatal("State did not match after round trip marshal")
}
}
func TestNewBeaconState_HashTreeRoot(t *testing.T) {
st, err := NewBeaconState()
require.NoError(t, err)
_, err = st.HashTreeRoot(context.Background())
require.NoError(t, err)
st, err = NewBeaconStateAltair()
require.NoError(t, err)
_, err = st.HashTreeRoot(context.Background())
require.NoError(t, err)
st, err = NewBeaconStateBellatrix()
require.NoError(t, err)
_, err = st.HashTreeRoot(context.Background())
require.NoError(t, err)
st, err = NewBeaconStateCapella()
require.NoError(t, err)
_, err = st.HashTreeRoot(context.Background())
require.NoError(t, err)
}