mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27: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>
67 lines
2.5 KiB
Go
67 lines
2.5 KiB
Go
package state_native
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/config/features"
|
|
"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.BeaconStateAltair{
|
|
Slot: 2,
|
|
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
|
|
Validators: validators,
|
|
CurrentEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
PreviousEpochParticipation: make([]byte, params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
Balances: balances,
|
|
}
|
|
features.Init(&features.Flags{EnableNativeState: true})
|
|
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)
|
|
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 = InitializeFromProtoAltair(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 = InitializeFromProtoAltair(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)
|
|
|
|
}
|