mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 03:51:29 +00:00
8c04ced1a6
* fixed epoch_processing * penalize->slash * exit -> voluntary_exit * SEED_LOOKAHEAD -> MIN_SEED_LOOKAHED * ENTRY_EXIT_DELAY -> ACTIVATION_EXIT_DELAY * `INCLUDER_REWARD_QUOTIENT` -> `ATTESTATION_INCLUSION_REWARD_QUOTIEN` * LatestIndexRoots -> LatestActiveIndexRoots * `MIN_VALIDATOR_WITHDRAWAL_EPOCHS` -> `MIN_VALIDATOR_WITHDRAWAL_DELAY` * MAX_WITHDRAWALS_PER_EPOCH -> MAX_EXIT_DEQUEUES_PER_EPOCH * ETH1_DATA_VOTING_PERIOD -> EPOCHS_PER_ETH1_VOTING_PERIOD * SLOT_DURATION -> SECONDS_PER_SLOT * EPOCH_LENGTH -> SLOTS_PER_EPOCH * SLOT_DURATION -> SECONDS_PER_SLOT take 2 * rest of the misc fixes for config name changes * remove tools/bootnode/.!74296!bootnode.go * `current_epoch_start_shard` -> `current_shuffling_start_shard`, `current_shuffling_epoch`, `current_shuffling_see` * go fmt * fixed comment * updated pseudocode comments * merged master
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package utils
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
func TestFaultyShuffleIndices(t *testing.T) {
|
|
var list []uint64
|
|
|
|
upperBound := 1<<(params.BeaconConfig().RandBytes*8) - 1
|
|
|
|
for i := 0; i < upperBound+1; i++ {
|
|
list = append(list, uint64(i))
|
|
}
|
|
|
|
if _, err := ShuffleIndices(common.Hash{'a'}, list); err == nil {
|
|
t.Error("Shuffle should have failed when validator count exceeds ModuloBias")
|
|
}
|
|
}
|
|
|
|
func TestShuffleIndices(t *testing.T) {
|
|
hash1 := common.BytesToHash([]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g'})
|
|
hash2 := common.BytesToHash([]byte{'1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7', '1', '2', '3', '4', '5', '6', '7'})
|
|
var list1 []uint64
|
|
|
|
for i := 0; i < 10; i++ {
|
|
list1 = append(list1, uint64(i))
|
|
}
|
|
|
|
list2 := make([]uint64, len(list1))
|
|
copy(list2, list1)
|
|
|
|
list1, err := ShuffleIndices(hash1, list1)
|
|
if err != nil {
|
|
t.Errorf("Shuffle failed with: %v", err)
|
|
}
|
|
|
|
list2, err = ShuffleIndices(hash2, list2)
|
|
if err != nil {
|
|
t.Errorf("Shuffle failed with: %v", err)
|
|
}
|
|
|
|
if reflect.DeepEqual(list1, list2) {
|
|
t.Errorf("2 shuffled lists shouldn't be equal")
|
|
}
|
|
if !reflect.DeepEqual(list1, []uint64{5, 4, 9, 6, 7, 3, 0, 1, 8, 2}) {
|
|
t.Errorf("list 1 was incorrectly shuffled")
|
|
}
|
|
if !reflect.DeepEqual(list2, []uint64{9, 0, 1, 5, 3, 2, 4, 7, 8, 6}) {
|
|
t.Errorf("list 2 was incorrectly shuffled")
|
|
}
|
|
}
|
|
|
|
func TestSplitIndices(t *testing.T) {
|
|
var l []uint64
|
|
validators := 64000
|
|
for i := 0; i < validators; i++ {
|
|
l = append(l, uint64(i))
|
|
}
|
|
split := SplitIndices(l, params.BeaconConfig().SlotsPerEpoch)
|
|
if len(split) != int(params.BeaconConfig().SlotsPerEpoch) {
|
|
t.Errorf("Split list failed due to incorrect length, wanted:%v, got:%v", params.BeaconConfig().SlotsPerEpoch, len(split))
|
|
}
|
|
|
|
for _, s := range split {
|
|
if len(s) != validators/int(params.BeaconConfig().SlotsPerEpoch) {
|
|
t.Errorf("Split list failed due to incorrect length, wanted:%v, got:%v", validators/int(params.BeaconConfig().SlotsPerEpoch), len(s))
|
|
}
|
|
}
|
|
}
|