Files
prysm/testing/util/state_test.go
Bastin 1b2524b0fe add NewBeaconStateGloas() (#16275)
**What does this PR do? Why is it needed?**
adds `util.NewBeaconStateGloas()`

also adds a missing fulu test.
2026-01-23 18:39:05 +00:00

117 lines
3.2 KiB
Go

package util
import (
"testing"
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
"github.com/OffchainLabs/prysm/v7/testing/assert"
"github.com/OffchainLabs/prysm/v7/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))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
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))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
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))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
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))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
func TestNewBeaconStateDeneb(t *testing.T) {
st, err := NewBeaconStateDeneb()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconStateDeneb{}
require.NoError(t, got.UnmarshalSSZ(b))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
func TestNewBeaconStateElectra(t *testing.T) {
st, err := NewBeaconStateElectra()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconStateElectra{}
require.NoError(t, got.UnmarshalSSZ(b))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
func TestNewBeaconStateFulu(t *testing.T) {
st, err := NewBeaconStateFulu()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconStateFulu{}
require.NoError(t, got.UnmarshalSSZ(b))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
func TestNewBeaconStateGloas(t *testing.T) {
st, err := NewBeaconStateGloas()
require.NoError(t, err)
b, err := st.MarshalSSZ()
require.NoError(t, err)
got := &ethpb.BeaconStateGloas{}
require.NoError(t, got.UnmarshalSSZ(b))
assert.DeepEqual(t, st.ToProtoUnsafe(), got)
}
func TestNewBeaconState_HashTreeRoot(t *testing.T) {
st, err := NewBeaconState()
require.NoError(t, err)
_, err = st.HashTreeRoot(t.Context())
require.NoError(t, err)
st, err = NewBeaconStateAltair()
require.NoError(t, err)
_, err = st.HashTreeRoot(t.Context())
require.NoError(t, err)
st, err = NewBeaconStateBellatrix()
require.NoError(t, err)
_, err = st.HashTreeRoot(t.Context())
require.NoError(t, err)
st, err = NewBeaconStateCapella()
require.NoError(t, err)
_, err = st.HashTreeRoot(t.Context())
require.NoError(t, err)
st, err = NewBeaconStateDeneb()
require.NoError(t, err)
_, err = st.HashTreeRoot(t.Context())
require.NoError(t, err)
st, err = NewBeaconStateElectra()
require.NoError(t, err)
_, err = st.HashTreeRoot(t.Context())
require.NoError(t, err)
}