mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 20:07:17 +00:00
b7a878d011
* remove ToProto and ToProtoUnsafe wrappers * TestAppendBeyondIndicesLimit * change type of genesisValidatorsRoot * fuzz tests * check type assertion
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestNewBeaconState(t *testing.T) {
|
|
st, err := NewBeaconState()
|
|
require.NoError(t, err)
|
|
b, err := st.MarshalSSZ()
|
|
require.NoError(t, err)
|
|
got := ðpb.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 := ðpb.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 := ðpb.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 := ðpb.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)
|
|
}
|