mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
e0eee87bf4
* first node test * adding in configuration flags for code coverage * adding line to remove file on unit test * adding new test for compressed field trie but is currently broken * changing limit on trie * adding new trie length coverage * adding in test for empty copy of trie * adding more trie tests * adding new field trie * adding more field trie tests * adding clarity to chunking equation * fixing linting * clarifying function for limit * updating native state settings to improve ease of future unit tests * improving unit test * fixing unit tests * adding more tests and fixing linting * adding more coverage and removing unused file * increasing node coverage * adding new test for checking config for booleans * fixing db test * fixing linting * adding signing root test * fixing linting * removing accidently created beacondata * switching not non native state * reverting back to proto use for spec test * reverting back to proto for some tests * turning off native state on some tests * switching more to proto state * rolling back disablenativestate * switching to native state in the state-native package for tests * fixing linting * fixing deepsource complaint * fixing some tests to native state and removing some unused flag checks * convert to native state * fixing linting * issues are being triggered by deleting the db this way so reverting change in hopes of changing this * rolling back testing util * rolling back some tests from native state * rolling back db deletion * test switching native state off after test runs * fixing hasher test * fixing altair and bellatrix hashers for native state * Update beacon-chain/node/node_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/auth_token_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * fixing imports * adding altair proof test Co-authored-by: Radosław Kapka <rkapka@wp.pl>
69 lines
2.8 KiB
Go
69 lines
2.8 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"
|
|
"github.com/prysmaticlabs/prysm/v3/config/features"
|
|
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) {
|
|
features.Init(&features.Flags{EnableNativeState: true})
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
return statenative.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{
|
|
Validators: nil,
|
|
})
|
|
})
|
|
features.Init(&features.Flags{EnableNativeState: false})
|
|
}
|
|
|
|
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Altair(t *testing.T) {
|
|
features.Init(&features.Flags{EnableNativeState: true})
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
return statenative.InitializeFromProtoUnsafeAltair(ðpb.BeaconStateAltair{
|
|
Validators: nil,
|
|
})
|
|
})
|
|
features.Init(&features.Flags{EnableNativeState: false})
|
|
}
|
|
|
|
func TestBeaconState_ValidatorAtIndexReadOnly_HandlesNilSlice_Bellatrix(t *testing.T) {
|
|
features.Init(&features.Flags{EnableNativeState: true})
|
|
testtmpl.VerifyBeaconStateValidatorAtIndexReadOnlyHandlesNilSlice(t, func() (state.BeaconState, error) {
|
|
return statenative.InitializeFromProtoUnsafeBellatrix(ðpb.BeaconStateBellatrix{
|
|
Validators: nil,
|
|
})
|
|
})
|
|
features.Init(&features.Flags{EnableNativeState: false})
|
|
}
|
|
|
|
func TestValidatorIndexOutOfRangeError(t *testing.T) {
|
|
features.Init(&features.Flags{EnableNativeState: true})
|
|
err := statenative.NewValidatorIndexOutOfRangeError(1)
|
|
require.Equal(t, err.Error(), "index 1 out of range")
|
|
features.Init(&features.Flags{EnableNativeState: false})
|
|
}
|
|
|
|
func TestValidatorIndexes(t *testing.T) {
|
|
features.Init(&features.Flags{EnableNativeState: true})
|
|
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[:]))
|
|
})
|
|
features.Init(&features.Flags{EnableNativeState: false})
|
|
}
|