mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 23:48:06 -05:00
* update shared/params * update eth2-types deps * update protobufs * update shared/* * fix testutil/state * update beacon-chain/state * update beacon-chain/db * update tests * fix test * update beacon-chain/core * update beacon-chain/blockchain * update beacon-chain/cache * beacon-chain/forkchoice * update beacon-chain/operations * update beacon-chain/p2p * update beacon-chain/rpc * update sync/initial-sync * update deps * update deps * go fmt * update beacon-chain/sync * update endtoend/ * bazel build //beacon-chain - works w/o issues * update slasher code * udpate tools/ * update validator/ * update fastssz * fix build * fix test building * update tests * update ethereumapis deps * fix tests * update state/stategen * fix build * fix test * add FarFutureSlot * go imports * Radek's suggestions * Ivan's suggestions * type conversions * Nishant's suggestions * add more tests to rpc_send_request * fix test * clean up * fix conflicts Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
67 lines
2.3 KiB
Go
67 lines
2.3 KiB
Go
package precompute_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
|
|
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestNew(t *testing.T) {
|
|
ffe := params.BeaconConfig().FarFutureEpoch
|
|
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
|
Slot: params.BeaconConfig().SlotsPerEpoch,
|
|
// Validator 0 is slashed
|
|
// Validator 1 is withdrawable
|
|
// Validator 2 is active prev epoch and current epoch
|
|
// Validator 3 is active prev epoch
|
|
Validators: []*ethpb.Validator{
|
|
{Slashed: true, WithdrawableEpoch: ffe, EffectiveBalance: 100},
|
|
{EffectiveBalance: 100},
|
|
{WithdrawableEpoch: ffe, ExitEpoch: ffe, EffectiveBalance: 100},
|
|
{WithdrawableEpoch: ffe, ExitEpoch: 1, EffectiveBalance: 100},
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
e := params.BeaconConfig().FarFutureSlot
|
|
v, b, err := precompute.New(context.Background(), s)
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, &precompute.Validator{
|
|
IsSlashed: true,
|
|
CurrentEpochEffectiveBalance: 100,
|
|
InclusionDistance: e,
|
|
InclusionSlot: e,
|
|
}, v[0], "Incorrect validator 0 status")
|
|
assert.DeepEqual(t, &precompute.Validator{
|
|
IsWithdrawableCurrentEpoch: true,
|
|
CurrentEpochEffectiveBalance: 100,
|
|
InclusionDistance: e,
|
|
InclusionSlot: e,
|
|
}, v[1], "Incorrect validator 1 status")
|
|
assert.DeepEqual(t, &precompute.Validator{
|
|
IsActiveCurrentEpoch: true,
|
|
IsActivePrevEpoch: true,
|
|
CurrentEpochEffectiveBalance: 100,
|
|
InclusionDistance: e,
|
|
InclusionSlot: e,
|
|
}, v[2], "Incorrect validator 2 status")
|
|
assert.DeepEqual(t, &precompute.Validator{
|
|
IsActivePrevEpoch: true,
|
|
CurrentEpochEffectiveBalance: 100,
|
|
InclusionDistance: e,
|
|
InclusionSlot: e,
|
|
}, v[3], "Incorrect validator 3 status")
|
|
|
|
wantedBalances := &precompute.Balance{
|
|
ActiveCurrentEpoch: 100,
|
|
ActivePrevEpoch: 200,
|
|
}
|
|
assert.DeepEqual(t, wantedBalances, b, "Incorrect wanted balance")
|
|
}
|