2022-05-09 13:02:34 +00:00
|
|
|
package state_native_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-16 16:19:01 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
|
|
|
|
statenative "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native"
|
|
|
|
testtmpl "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
2022-05-09 13:02:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Phase0(t *testing.T) {
|
|
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
|
|
return statenative.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{
|
|
|
|
Validators: nil,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Altair(t *testing.T) {
|
|
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
|
|
return statenative.InitializeFromProtoUnsafeAltair(ðpb.BeaconStateAltair{
|
|
|
|
Validators: nil,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Bellatrix(t *testing.T) {
|
|
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
|
|
return statenative.InitializeFromProtoUnsafeBellatrix(ðpb.BeaconStateBellatrix{
|
|
|
|
Validators: nil,
|
|
|
|
})
|
|
|
|
})
|
2022-08-16 16:19:01 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 16:39:19 +00:00
|
|
|
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Capella(t *testing.T) {
|
|
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
|
|
return statenative.InitializeFromProtoUnsafeCapella(ðpb.BeaconStateCapella{
|
|
|
|
Validators: nil,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-09 21:38:13 +00:00
|
|
|
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Deneb(t *testing.T) {
|
|
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
|
|
return statenative.InitializeFromProtoUnsafeDeneb(ðpb.BeaconStateDeneb{
|
|
|
|
Validators: nil,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-16 16:19:01 +00:00
|
|
|
func TestValidatorIndexes(t *testing.T) {
|
|
|
|
dState, _ := util.DeterministicGenesisState(t, 10)
|
|
|
|
byteValue := dState.PubkeyAtIndex(1)
|
|
|
|
t.Run("ValidatorIndexByPubkey", func(t *testing.T) {
|
|
|
|
require.Equal(t, hexutil.Encode(byteValue[:]), "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b")
|
|
|
|
})
|
|
|
|
t.Run("ValidatorAtIndexReadOnly", func(t *testing.T) {
|
|
|
|
readOnlyState, err := dState.ValidatorAtIndexReadOnly(1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
readOnlyBytes := readOnlyState.PublicKey()
|
|
|
|
require.NotEmpty(t, readOnlyBytes)
|
|
|
|
require.Equal(t, hexutil.Encode(readOnlyBytes[:]), hexutil.Encode(byteValue[:]))
|
|
|
|
})
|
2022-05-09 13:02:34 +00:00
|
|
|
}
|