mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
a069738c20
* 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>
111 lines
3.5 KiB
Go
111 lines
3.5 KiB
Go
package helpers
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestRandaoMix_OK(t *testing.T) {
|
|
randaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
|
for i := 0; i < len(randaoMixes); i++ {
|
|
intInBytes := make([]byte, 32)
|
|
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
|
|
randaoMixes[i] = intInBytes
|
|
}
|
|
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{RandaoMixes: randaoMixes})
|
|
require.NoError(t, err)
|
|
tests := []struct {
|
|
epoch types.Epoch
|
|
randaoMix []byte
|
|
}{
|
|
{
|
|
epoch: 10,
|
|
randaoMix: randaoMixes[10],
|
|
},
|
|
{
|
|
epoch: 2344,
|
|
randaoMix: randaoMixes[2344],
|
|
},
|
|
{
|
|
epoch: 99999,
|
|
randaoMix: randaoMixes[99999%params.BeaconConfig().EpochsPerHistoricalVector],
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
require.NoError(t, state.SetSlot(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(test.epoch+1))))
|
|
mix, err := RandaoMix(state, test.epoch)
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, test.randaoMix, mix, "Incorrect randao mix")
|
|
}
|
|
}
|
|
|
|
func TestRandaoMix_CopyOK(t *testing.T) {
|
|
randaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
|
for i := 0; i < len(randaoMixes); i++ {
|
|
intInBytes := make([]byte, 32)
|
|
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
|
|
randaoMixes[i] = intInBytes
|
|
}
|
|
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{RandaoMixes: randaoMixes})
|
|
require.NoError(t, err)
|
|
tests := []struct {
|
|
epoch types.Epoch
|
|
randaoMix []byte
|
|
}{
|
|
{
|
|
epoch: 10,
|
|
randaoMix: randaoMixes[10],
|
|
},
|
|
{
|
|
epoch: 2344,
|
|
randaoMix: randaoMixes[2344],
|
|
},
|
|
{
|
|
epoch: 99999,
|
|
randaoMix: randaoMixes[99999%params.BeaconConfig().EpochsPerHistoricalVector],
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
require.NoError(t, state.SetSlot(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(test.epoch+1))))
|
|
mix, err := RandaoMix(state, test.epoch)
|
|
require.NoError(t, err)
|
|
uniqueNumber := uint64(params.BeaconConfig().EpochsPerHistoricalVector.Add(1000))
|
|
binary.LittleEndian.PutUint64(mix, uniqueNumber)
|
|
|
|
for _, mx := range randaoMixes {
|
|
mxNum := bytesutil.FromBytes8(mx)
|
|
assert.NotEqual(t, uniqueNumber, mxNum, "two distinct slices which have different representations in memory still contain the same value: %d", mxNum)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGenerateSeed_OK(t *testing.T) {
|
|
randaoMixes := make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector)
|
|
for i := 0; i < len(randaoMixes); i++ {
|
|
intInBytes := make([]byte, 32)
|
|
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
|
|
randaoMixes[i] = intInBytes
|
|
}
|
|
slot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().MinSeedLookahead * 10))
|
|
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
|
RandaoMixes: randaoMixes,
|
|
Slot: slot,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
got, err := Seed(state, 10, params.BeaconConfig().DomainBeaconAttester)
|
|
require.NoError(t, err)
|
|
|
|
wanted := [32]byte{102, 82, 23, 40, 226, 79, 171, 11, 203, 23, 175, 7, 88, 202, 80,
|
|
103, 68, 126, 195, 143, 190, 249, 210, 85, 138, 196, 158, 208, 11, 18, 136, 23}
|
|
assert.Equal(t, wanted, got, "Incorrect generated seeds")
|
|
}
|