prysm-pulse/beacon-chain/state/state-native/getters_validator_test.go
Radosław Kapka cafe0bd1f8
Capella beacon state (#11141)
* fork

* types

* cloners

* getters

* remove CapellaBlind from fork

* hasher

* setters

* spec params, config tests

* generate ssz

* executionPayloadHeaderCapella

* proto state

* BeaconStateCapella SSZ

* saving state

* configfork

* BUILD files

* fix RealPosition

* fix hasher

* SetLatestExecutionPayloadHeaderCapella

* fix error message

* reduce complexity of saveStatesEfficientInternal

* add latestExecutionPayloadHeaderCapella to minimal state

* halway done interface

* remove withdrawal methods

* merge setters

* change signatures for v1 and v2

* fixing errors pt. 1

* paylod_test fixes

* fix everything

* remove unused func

* fix tests

* state_trie_test improvements

* in progress...

* hasher test

* fix configs

* simplify hashing

* Revert "fix configs"

This reverts commit bcae2825fcc8ba45a2b43d68ad0ab57f8eac8952.

* remove capella from config test

* unify locking

* review

* hashing

* fixes

Co-authored-by: terencechain <terence@prysmaticlabs.com>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-10-12 11:39:19 -05:00

66 lines
2.5 KiB
Go

package state_native_test
import (
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
testtmpl "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/testing"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/util"
)
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Phase0(t *testing.T) {
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
return statenative.InitializeFromProtoUnsafePhase0(&ethpb.BeaconState{
Validators: nil,
})
})
}
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Altair(t *testing.T) {
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
return statenative.InitializeFromProtoUnsafeAltair(&ethpb.BeaconStateAltair{
Validators: nil,
})
})
}
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Bellatrix(t *testing.T) {
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
return statenative.InitializeFromProtoUnsafeBellatrix(&ethpb.BeaconStateBellatrix{
Validators: nil,
})
})
}
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Capella(t *testing.T) {
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
return statenative.InitializeFromProtoUnsafeCapella(&ethpb.BeaconStateCapella{
Validators: nil,
})
})
}
func TestValidatorIndexOutOfRangeError(t *testing.T) {
err := statenative.NewValidatorIndexOutOfRangeError(1)
require.Equal(t, err.Error(), "index 1 out of range")
}
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[:]))
})
}