mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
65 lines
2.6 KiB
Go
65 lines
2.6 KiB
Go
package state_native
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
)
|
|
|
|
func TestState_UnrealizedCheckpointBalances(t *testing.T) {
|
|
validators := make([]*ethpb.Validator, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
|
balances := make([]uint64, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
|
for i := 0; i < len(validators); i++ {
|
|
validators[i] = ðpb.Validator{
|
|
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
|
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
|
}
|
|
balances[i] = params.BeaconConfig().MaxEffectiveBalance
|
|
}
|
|
base := ðpb.BeaconStateAltair{
|
|
Slot: 66,
|
|
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
|
|
Validators: validators,
|
|
CurrentEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
PreviousEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
Balances: balances,
|
|
}
|
|
state, err := InitializeFromProtoAltair(base)
|
|
require.NoError(t, err)
|
|
|
|
// No one voted in the last two epochs
|
|
allActive := params.BeaconConfig().MinGenesisActiveValidatorCount * params.BeaconConfig().MaxEffectiveBalance
|
|
active, previous, current, err := state.UnrealizedCheckpointBalances()
|
|
require.NoError(t, err)
|
|
require.Equal(t, allActive, active.Uint64())
|
|
require.Equal(t, params.BeaconConfig().EffectiveBalanceIncrement, current.Uint64())
|
|
require.Equal(t, params.BeaconConfig().EffectiveBalanceIncrement, previous.Uint64())
|
|
|
|
// Add some votes in the last two epochs:
|
|
base.CurrentEpochParticipation[0] = 0xFF
|
|
base.PreviousEpochParticipation[0] = 0xFF
|
|
base.PreviousEpochParticipation[1] = 0xFF
|
|
|
|
state, err = InitializeFromProtoAltair(base)
|
|
require.NoError(t, err)
|
|
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
|
require.NoError(t, err)
|
|
require.Equal(t, allActive, active.Uint64())
|
|
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, current.Uint64())
|
|
require.Equal(t, 2*params.BeaconConfig().MaxEffectiveBalance, previous.Uint64())
|
|
|
|
// Slash some validators
|
|
validators[0].Slashed = true
|
|
state, err = InitializeFromProtoAltair(base)
|
|
require.NoError(t, err)
|
|
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
|
require.NoError(t, err)
|
|
require.Equal(t, allActive, active.Uint64())
|
|
require.Equal(t, params.BeaconConfig().EffectiveBalanceIncrement, current.Uint64())
|
|
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, previous.Uint64())
|
|
|
|
}
|