mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
73443208a1
* Remove native state flag and use native state in spectests * remove feature from tests * use e2e config in slasher simulator * use params.BeaconConfig in testutil * use correct function * use minimal config in go_test * fix TestListValidators * parameterize sync committee bits and aggregation bits * Fix TestServer_ListIndexedAttestations_GenesisEpoch (cherry picked from commit 254ab623dde08ae8886b152facdbbd8889ed79db) * fix more tests * fix even more * moreeee * aaaand more * one more fix * one more * simplify TestGetAltairDuties_UnknownPubkey * comment out problematic test * one more fix * one more * aaaand one more * another * use fieldparams in HydrateBlindedBeaconBlockBodyBellatrix * create new package for mainnet tests * TestServer_GetBellatrixBeaconBlock * change slashed validator index * clear cache in reward_test.go * deprecate flag * create bazel mainnet target * move attester mainnet test to mainnet target * "fix" proposer tests * use minimal config in TestServer_circuitBreakBuilder * fix TestProposer_ProposeBlock_OK * more fixes in validator package * more fixes * more fixes * test code * move TestProposer_GetBeaconBlock_BellatrixEpoch to minimal * finally * remove proposer_bellatrix_mainnet_test.go * fix TestServer_GetBellatrixBeaconBlock_HappyCase * fix TestServer_GetBellatrixBeaconBlock_BuilderCase * Preston needs to fix this! * Revert "Preston needs to fix this!" This reverts commit b03d97a16e3080e254c7b19d7f193d3c600ca869. * remove proto state tests * fix migration tests * static analysis fix * review * remove proto state * swap state in tests * fix BUILD file in /proto/testing * remove metrics test with nil state
127 lines
3.0 KiB
Go
127 lines
3.0 KiB
Go
package cache
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
|
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestSyncCommitteeHeadState(t *testing.T) {
|
|
beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{
|
|
Fork: ðpb.Fork{
|
|
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
|
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
phase0State, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{
|
|
Fork: ðpb.Fork{
|
|
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
|
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
bellatrixState, err := state_native.InitializeFromProtoBellatrix(ðpb.BeaconStateBellatrix{
|
|
Fork: ðpb.Fork{
|
|
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
|
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
type put struct {
|
|
slot types.Slot
|
|
state state.BeaconState
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
key types.Slot
|
|
put *put
|
|
want state.BeaconState
|
|
wantErr bool
|
|
wantPutErr bool
|
|
}{
|
|
{
|
|
name: "putting error in",
|
|
key: types.Slot(1),
|
|
put: &put{
|
|
slot: types.Slot(1),
|
|
state: nil,
|
|
},
|
|
wantPutErr: true,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "putting invalid state in",
|
|
key: types.Slot(1),
|
|
put: &put{
|
|
slot: types.Slot(1),
|
|
state: phase0State,
|
|
},
|
|
wantPutErr: true,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "not found when empty cache",
|
|
key: types.Slot(1),
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "not found when non-existent key in non-empty cache",
|
|
key: types.Slot(2),
|
|
put: &put{
|
|
slot: types.Slot(1),
|
|
state: beaconState,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "found with key",
|
|
key: types.Slot(1),
|
|
put: &put{
|
|
slot: types.Slot(1),
|
|
state: beaconState,
|
|
},
|
|
want: beaconState,
|
|
},
|
|
{
|
|
name: "not found when non-existent key in non-empty cache (bellatrix state)",
|
|
key: types.Slot(2),
|
|
put: &put{
|
|
slot: types.Slot(1),
|
|
state: bellatrixState,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "found with key (bellatrix state)",
|
|
key: types.Slot(100),
|
|
put: &put{
|
|
slot: types.Slot(100),
|
|
state: bellatrixState,
|
|
},
|
|
want: bellatrixState,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
c := NewSyncCommitteeHeadState()
|
|
if tt.put != nil {
|
|
err := c.Put(tt.put.slot, tt.put.state)
|
|
if (err != nil) != tt.wantPutErr {
|
|
t.Fatalf("Put() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
}
|
|
got, err := c.Get(tt.key)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("Get() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
require.DeepEqual(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|