mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package state_native_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
statenative "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
|
)
|
|
|
|
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[:]))
|
|
})
|
|
}
|