mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
4de92bafc4
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
package v2_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
v2 "github.com/prysmaticlabs/prysm/beacon-chain/state/v2"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
|
)
|
|
|
|
func TestBeaconState_ValidatorMutation_Altair(t *testing.T) {
|
|
testState, _ := util.DeterministicGenesisStateAltair(t, 400)
|
|
pbState, err := v2.ProtobufBeaconState(testState.InnerStateUnsafe())
|
|
require.NoError(t, err)
|
|
testState, err = v2.InitializeFromProto(pbState)
|
|
require.NoError(t, err)
|
|
|
|
_, err = testState.HashTreeRoot(context.Background())
|
|
require.NoError(t, err)
|
|
|
|
// Reset tries
|
|
require.NoError(t, testState.UpdateValidatorAtIndex(200, new(ethpb.Validator)))
|
|
_, err = testState.HashTreeRoot(context.Background())
|
|
require.NoError(t, err)
|
|
|
|
newState1 := testState.Copy()
|
|
_ = testState.Copy()
|
|
|
|
require.NoError(t, testState.UpdateValidatorAtIndex(15, ðpb.Validator{
|
|
PublicKey: make([]byte, 48),
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
EffectiveBalance: 1111,
|
|
Slashed: false,
|
|
ActivationEligibilityEpoch: 1112,
|
|
ActivationEpoch: 1114,
|
|
ExitEpoch: 1116,
|
|
WithdrawableEpoch: 1117,
|
|
}))
|
|
|
|
rt, err := testState.HashTreeRoot(context.Background())
|
|
require.NoError(t, err)
|
|
pbState, err = v2.ProtobufBeaconState(testState.InnerStateUnsafe())
|
|
require.NoError(t, err)
|
|
|
|
copiedTestState, err := v2.InitializeFromProto(pbState)
|
|
require.NoError(t, err)
|
|
|
|
rt2, err := copiedTestState.HashTreeRoot(context.Background())
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, rt, rt2)
|
|
|
|
require.NoError(t, newState1.UpdateValidatorAtIndex(150, ðpb.Validator{
|
|
PublicKey: make([]byte, 48),
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
EffectiveBalance: 2111,
|
|
Slashed: false,
|
|
ActivationEligibilityEpoch: 2112,
|
|
ActivationEpoch: 2114,
|
|
ExitEpoch: 2116,
|
|
WithdrawableEpoch: 2117,
|
|
}))
|
|
|
|
rt, err = newState1.HashTreeRoot(context.Background())
|
|
require.NoError(t, err)
|
|
pbState, err = v2.ProtobufBeaconState(newState1.InnerStateUnsafe())
|
|
require.NoError(t, err)
|
|
|
|
copiedTestState, err = v2.InitializeFromProto(pbState)
|
|
require.NoError(t, err)
|
|
|
|
rt2, err = copiedTestState.HashTreeRoot(context.Background())
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, rt, rt2)
|
|
}
|