prysm-pulse/shared/aggregation/testing/bitlistutils.go
Preston Van Loon 7cc32c4dda
Various code inspection resolutions (#7438)
* remove unused code

* remove defer use in loop

* Remove unused methods and constants

* gofmt and gaz

* nilness check

* remove unused args

* Add TODO for refactoring subscribeWithBase to remove unused arg. It seems too involved to include in this sweeping PR. https://github.com/prysmaticlabs/prysm/issues/7437

* replace empty slice declaration

* Remove unnecessary type conversions

* remove redundant type declaration

* rename receivers to be consistent

* Remove bootnode query tool. It is now obsolete by discv5

* Remove relay node. It is no longer used or supported

* Revert "Remove relay node. It is no longer used or supported"

This reverts commit 4bd7717334dad85ef4766ed9bc4da711fb5fa810.

* Delete unused test directory

* Delete unsupported gcp startup script

* Delete old k8s script

* build fixes

* fix build

* go mod tidy

* revert slasher/db/kv/block_header.go

* fix build

* remove redundant nil check

* combine func args

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
2020-10-12 08:11:05 +00:00

62 lines
1.7 KiB
Go

package testing
import (
"math/rand"
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/timeutils"
)
// BitlistWithAllBitsSet creates list of bitlists with all bits set.
func BitlistWithAllBitsSet(length uint64) bitfield.Bitlist {
b := bitfield.NewBitlist(length)
for i := uint64(0); i < length; i++ {
b.SetBitAt(i, true)
}
return b
}
// BitlistsWithSingleBitSet creates list of bitlists with a single bit set in each.
func BitlistsWithSingleBitSet(n, length uint64) []bitfield.Bitlist {
lists := make([]bitfield.Bitlist, n)
for i := uint64(0); i < n; i++ {
b := bitfield.NewBitlist(length)
b.SetBitAt(i%length, true)
lists[i] = b
}
return lists
}
// BitlistsWithMultipleBitSet creates list of bitlists with random n bits set.
func BitlistsWithMultipleBitSet(t testing.TB, n, length, count uint64) []bitfield.Bitlist {
seed := timeutils.Now().UnixNano()
t.Logf("bitlistsWithMultipleBitSet random seed: %v", seed)
rand.Seed(seed)
lists := make([]bitfield.Bitlist, n)
for i := uint64(0); i < n; i++ {
b := bitfield.NewBitlist(length)
keys := rand.Perm(int(length))
for _, key := range keys[:count] {
b.SetBitAt(uint64(key), true)
}
lists[i] = b
}
return lists
}
// MakeAttestationsFromBitlists creates list of bitlists from list of attestations.
func MakeAttestationsFromBitlists(bl []bitfield.Bitlist) []*ethpb.Attestation {
atts := make([]*ethpb.Attestation, len(bl))
for i, b := range bl {
atts[i] = &ethpb.Attestation{
AggregationBits: b,
Data: nil,
Signature: bls.NewAggregateSignature().Marshal(),
}
}
return atts
}