mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
65 lines
2.4 KiB
Go
65 lines
2.4 KiB
Go
package v3
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/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.BeaconStateBellatrix{
|
|
Slot: 2,
|
|
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
|
|
Validators: validators,
|
|
CurrentEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
PreviousEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
Balances: balances,
|
|
}
|
|
state, err := InitializeFromProto(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)
|
|
require.Equal(t, uint64(0), current)
|
|
require.Equal(t, uint64(0), previous)
|
|
|
|
// Add some votes in the last two epochs:
|
|
base.CurrentEpochParticipation[0] = 0xFF
|
|
base.PreviousEpochParticipation[0] = 0xFF
|
|
base.PreviousEpochParticipation[1] = 0xFF
|
|
|
|
state, err = InitializeFromProto(base)
|
|
require.NoError(t, err)
|
|
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
|
require.NoError(t, err)
|
|
require.Equal(t, allActive, active)
|
|
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, current)
|
|
require.Equal(t, 2*params.BeaconConfig().MaxEffectiveBalance, previous)
|
|
|
|
// Slash some validators
|
|
validators[0].Slashed = true
|
|
state, err = InitializeFromProto(base)
|
|
require.NoError(t, err)
|
|
active, previous, current, err = state.UnrealizedCheckpointBalances()
|
|
require.NoError(t, err)
|
|
require.Equal(t, allActive-params.BeaconConfig().MaxEffectiveBalance, active)
|
|
require.Equal(t, uint64(0), current)
|
|
require.Equal(t, params.BeaconConfig().MaxEffectiveBalance, previous)
|
|
|
|
}
|