prysm-pulse/beacon-chain/state/v3/state_test.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* 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>
2022-08-16 12:20:13 +00:00

80 lines
2.4 KiB
Go

package v3_test
import (
"context"
"testing"
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/assert"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/util"
)
func TestBeaconState_ValidatorMutation_Bellatrix(t *testing.T) {
testState, _ := util.DeterministicGenesisStateBellatrix(t, 400)
pbState, err := v3.ProtobufBeaconState(testState.InnerStateUnsafe())
require.NoError(t, err)
testState, err = v3.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, &ethpb.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 = v3.ProtobufBeaconState(testState.InnerStateUnsafe())
require.NoError(t, err)
copiedTestState, err := v3.InitializeFromProtoUnsafe(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, &ethpb.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 = v3.ProtobufBeaconState(newState1.InnerStateUnsafe())
require.NoError(t, err)
copiedTestState, err = v3.InitializeFromProto(pbState)
require.NoError(t, err)
rt2, err = copiedTestState.HashTreeRoot(context.Background())
require.NoError(t, err)
assert.Equal(t, rt, rt2)
}