Skip to content

Commit

Permalink
Update for loops over integers with range
Browse files Browse the repository at this point in the history
  • Loading branch information
KaloyanTanev committed Jul 19, 2024
1 parent f2d9a2d commit bc4c1ba
Show file tree
Hide file tree
Showing 75 changed files with 172 additions and 172 deletions.
2 changes: 1 addition & 1 deletion app/disk_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestCalculateTrackerDelay(t *testing.T) {

func TestSetFeeRecipient(t *testing.T) {
set := beaconmock.ValidatorSetA
for i := 0; i < len(set); i++ {
for i := range len(set) {
clone, err := set.Clone()
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions app/eth2wrap/eth2wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestErrors(t *testing.T) {
}

func TestCtxCancel(t *testing.T) {
for i := 0; i < 10; i++ {
for range 10 {
ctx, cancel := context.WithCancel(context.Background())

bmock, err := beaconmock.New()
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestOnlyTimeout(t *testing.T) {
const n = 10
var wg sync.WaitGroup
wg.Add(n)
for i := 0; i < n; i++ {
for range n {
go func() {
testCtxCancel(t, time.Millisecond*10)
wg.Done()
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestLazy(t *testing.T) {
enabled2.Store(true)

// Proxy2 is enabled, so this should succeed.
for i := 0; i < 5; i++ { // Do multiple request to make Proxy2 the "best".
for range 5 { // Do multiple request to make Proxy2 the "best".
_, err = eth2Cl.NodeSyncing(ctx, &eth2api.NodeSyncingOpts{})
require.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/eth2wrap/valcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestValidatorCache(t *testing.T) {
)

// Create a set of validators, half active, half random state.
for i := 0; i < 10; i++ {
for range 10 {
val := testutil.RandomValidator(t)
if rand.Intn(2) == 0 {
val.Status = eth2v1.ValidatorState(rand.Intn(10))
Expand Down
2 changes: 1 addition & 1 deletion app/expbackoff/expbackoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestConfigs(t *testing.T) {
})

var resps []string
for i := 0; i < len(test.backoffs); i++ {
for i := range len(test.backoffs) {
resp := expbackoff.Backoff(test.config, i)
resps = append(resps, resp.Truncate(time.Millisecond*10).String())
}
Expand Down
2 changes: 1 addition & 1 deletion app/forkjoin/forkjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func New[I, O any](rootCtx context.Context, work Work[I, O], opts ...Option) (Fo
}()
}

for i := 0; i < options.workers; i++ { // Start workers
for range options.workers { // Start workers
go func() {
for in := range input { // Process all inputs (channel closed on Join)
if workCtx.Err() != nil { // Skip work if failed fast
Expand Down
2 changes: 1 addition & 1 deletion app/forkjoin/forkjoin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestForkJoin(t *testing.T) {
defer cancel()

var allOutput []int
for i := 0; i < n; i++ {
for i := range n {
fork(i)
allOutput = append(allOutput, i)
}
Expand Down
2 changes: 1 addition & 1 deletion app/health/checks_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func testCheck(t *testing.T, m Metadata, checkName string, expect bool, metrics
}

multiFams := make([][]*pb.MetricFamily, max)
for i := 0; i < max; i++ {
for i := range max {
var fam []*pb.MetricFamily
if i < len(metrics) {
fam = append(fam, metrics[i])
Expand Down
4 changes: 2 additions & 2 deletions app/k1util/k1util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func BenchmarkRecoverVerify(b *testing.B) {
b.StartTimer()

b.Run("recover", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
recovered, err := k1util.Recover(
digest,
sig)
Expand All @@ -162,7 +162,7 @@ func BenchmarkRecoverVerify(b *testing.B) {
})

b.Run("verify", func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
ok, err := k1util.Verify64(
key.PubKey(),
digest,
Expand Down
2 changes: 1 addition & 1 deletion app/lifecycle/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestManager(t *testing.T) {

// Wait for the hooks to be called.
var calls []string
for i := 0; i < len(test.Hooks); i++ {
for i := range len(test.Hooks) {
if i == starts {
// Cancel application context after the starts hooks.
cancel()
Expand Down
6 changes: 3 additions & 3 deletions app/log/loki/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func TestLoki(t *testing.T) {

go cl.Run()

for i := 0; i < n; i++ {
for i := range n {
cl.Add(fmt.Sprint(i))
}

for i := 0; i < n; i++ {
for i := range n {
require.Equal(t, fmt.Sprint(i), <-received)
}

Expand Down Expand Up @@ -124,7 +124,7 @@ func TestLongLines(t *testing.T) {

cl.Add(normal)

for i := 0; i < 1000; i++ {
for range 1000 {
cl.Add(huge)
}

Expand Down
2 changes: 1 addition & 1 deletion app/monitoringapi_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestStartChecker(t *testing.T) {
hostsInfo []peer.AddrInfo
)

for i := 0; i < tt.numPeers; i++ {
for range tt.numPeers {
h := testutil.CreateHost(t, testutil.AvailableAddr(t))
info := peer.AddrInfo{
ID: h.ID(),
Expand Down
6 changes: 3 additions & 3 deletions app/peerinfo/peerinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestPeerInfo(t *testing.T) {
peerInfos []*peerinfo.PeerInfo
)

for i := 0; i < n; i++ {
for i := range n {
tcpNode := testutil.CreateHost(t, testutil.AvailableAddr(t))
for j, other := range tcpNodes {
tcpNode.Peerstore().AddAddrs(other.ID(), other.Addrs(), peerstore.PermanentAddrTTL)
Expand All @@ -85,7 +85,7 @@ func TestPeerInfo(t *testing.T) {
return func() time.Time { return now.Add(nodes[i].Offset) }
}

for i := 0; i < n; i++ {
for i := range n {
node := nodes[i]

// Most nodes are passive
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestPeerInfo(t *testing.T) {
peerInfos = append(peerInfos, peerInfo)
}

for i := 0; i < n; i++ {
for i := range n {
if nodes[i].Ignore {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion app/protonil/protonil.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Check(msg proto.Message) error {
// Check elements of list fields.
if field.IsList() {
list := rMsg.Get(field).List()
for i := 0; i < list.Len(); i++ {
for i := range list.Len() {
elem, ok := valueToMsg(list.Get(i))
if !ok {
// Not a message element type.
Expand Down
2 changes: 1 addition & 1 deletion app/protonil/protonil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestFuzz(t *testing.T) {

func BenchmarkCheck(b *testing.B) {
fuzzer := fuzz.New()
for i := 0; i < b.N; i++ {
for range b.N {
b.StopTimer()
m1 := new(v1.M1)
fuzzer.Fuzz(m1)
Expand Down
2 changes: 1 addition & 1 deletion app/qbftdebug_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestQBFTDebugger(t *testing.T) {
debug = new(qbftDebugger)
)

for i := 0; i < 10; i++ {
for range 10 {
instance := &pbv1.SniffedConsensusInstance{
Msgs: []*pbv1.SniffedConsensusMsg{
{
Expand Down
4 changes: 2 additions & 2 deletions app/retry/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestShutdown(t *testing.T) {
done := make(chan struct{})

// Start 3 long-running functions
for i := 0; i < 3; i++ {
for range 3 {
go retryer.DoAsync(ctx, core.NewProposerDuty(999999), "test", "test", func(ctx context.Context) error {
waiting <- struct{}{}
<-stop
Expand All @@ -127,7 +127,7 @@ func TestShutdown(t *testing.T) {
}

// Wait for functions to block
for i := 0; i < n; i++ {
for range n {
<-waiting
}

Expand Down
2 changes: 1 addition & 1 deletion app/vmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func newVMockEth2Provider(conf Config, pubshares []eth2p0.BLSPubKey) func() (eth

// Try three times to reduce test startup issues.
var err error
for i := 0; i < 3; i++ {
for range 3 {

Check warning on line 80 in app/vmock.go

View check run for this annotation

Codecov / codecov/patch

app/vmock.go#L80

Added line #L80 was not covered by tests
var eth2Svc eth2client.Service
eth2Svc, err = eth2http.New(context.Background(),
eth2http.WithLogLevel(1),
Expand Down
2 changes: 1 addition & 1 deletion cluster/cluster_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func randomDefinition(t *testing.T, cr Creator, op0, op1 Operator, opts ...func(
)

var feeRecipientAddrs, withdrawalAddrs []string
for i := 0; i < numVals; i++ {
for range numVals {
feeRecipientAddrs = append(feeRecipientAddrs, testutil.RandomETHAddress())
withdrawalAddrs = append(withdrawalAddrs, testutil.RandomETHAddress())
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestEncode(t *testing.T) {
}

var feeRecipientAddrs, withdrawalAddrs []string
for i := 0; i < numVals; i++ {
for range numVals {
feeRecipientAddrs = append(feeRecipientAddrs, testutil.RandomETHAddressSeed(r))
withdrawalAddrs = append(withdrawalAddrs, testutil.RandomETHAddressSeed(r))
}
Expand Down
6 changes: 3 additions & 3 deletions cluster/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func WithDKGAlgorithm(algorithm string) func(*Definition) {
func WithLegacyVAddrs(feeRecipientAddress, withdrawalAddress string) func(*Definition) {
return func(d *Definition) {
var vAddrs []ValidatorAddresses
for i := 0; i < d.NumValidators; i++ {
for range d.NumValidators {
vAddrs = append(vAddrs, ValidatorAddresses{
FeeRecipientAddress: feeRecipientAddress,
WithdrawalAddress: withdrawalAddress,
Expand Down Expand Up @@ -86,7 +86,7 @@ func NewDefinition(name string, numVals int, threshold int, feeRecipientAddresse
DepositAmounts: deposit.EthsToGweis(depositAmounts),
}

for i := 0; i < numVals; i++ {
for i := range numVals {
def.ValidatorAddresses = append(def.ValidatorAddresses, ValidatorAddresses{
FeeRecipientAddress: feeRecipientAddresses[i],
WithdrawalAddress: withdrawalAddresses[i],
Expand Down Expand Up @@ -938,7 +938,7 @@ func validatorAddressesFromJSON(vaddrs []validatorAddressesJSON) []ValidatorAddr
// repeatVAddrs returns a slice of n identical ValidatorAddresses.
func repeatVAddrs(addr ValidatorAddresses, n int) []ValidatorAddresses {
var resp []ValidatorAddresses
for i := 0; i < n; i++ {
for range n {
resp = append(resp, addr)
}

Expand Down
8 changes: 4 additions & 4 deletions cluster/test_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewForT(t *testing.T, dv, k, n, seed int, random *rand.Rand, opts ...func(*
}

var feeRecipientAddrs, withdrawalAddrs []string
for i := 0; i < dv; i++ {
for range dv {
rootSecret, err := tbls.GenerateInsecureKey(t, randomReader)
require.NoError(t, err)

Expand All @@ -53,7 +53,7 @@ func NewForT(t *testing.T, dv, k, n, seed int, random *rand.Rand, opts ...func(*

var pubshares [][]byte
var privshares []tbls.PrivateKey
for i := 0; i < n; i++ {
for i := range n {
sharePrivkey := shares[i+1] // Share indexes are 1-indexed.

sharePub, err := tbls.SecretToPublicKey(sharePrivkey)
Expand Down Expand Up @@ -91,7 +91,7 @@ func NewForT(t *testing.T, dv, k, n, seed int, random *rand.Rand, opts ...func(*
withdrawalAddrs = append(withdrawalAddrs, testutil.RandomETHAddressSeed(random))
}

for i := 0; i < n; i++ {
for i := range n {
// Generate ENR
p2pKey := testutil.GenerateInsecureK1Key(t, seed+i)

Expand Down Expand Up @@ -121,7 +121,7 @@ func NewForT(t *testing.T, dv, k, n, seed int, random *rand.Rand, opts ...func(*

// Definition version prior to v1.3.0 don't support EIP712 signatures.
if supportEIP712Sigs(def.Version) {
for i := 0; i < n; i++ {
for i := range n {
def.Operators[i], err = signOperator(p2pKeys[i], def, def.Operators[i])
require.NoError(t, err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/addvalidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func writeDepositDatas(ctx context.Context, clusterDir string, numOps int, secre

currTime := time.Now().Format("20060102150405")
filename := fmt.Sprintf("deposit-data-%s.json", currTime) // Ex: "deposit-data-20060102150405.json"
for i := 0; i < numOps; i++ {
for i := range numOps {
depositPath := filepath.Join(nodeDir(clusterDir, i), filename)
//nolint:gosec // File needs to be read-only for everybody
err = os.WriteFile(depositPath, bytes, 0o444)
Expand All @@ -300,7 +300,7 @@ func writeNewKeystores(clusterDir string, numOps, firstKeystoreIdx int, shareSet
}
}

for i := 0; i < numOps; i++ {
for i := range numOps {
var secrets []tbls.PrivateKey // All partial keys for node<i>
for _, shares := range shareSets {
secrets = append(secrets, shares[i])
Expand Down Expand Up @@ -392,7 +392,7 @@ func genNewVals(numOps, threshold int, forkVersion []byte, conf addValidatorsCon
shareSets [][]tbls.PrivateKey
)

for i := 0; i < conf.NumVals; i++ {
for i := range conf.NumVals {
// Generate private/public keypair
secret, err := tbls.GenerateSecretKey()
if err != nil {
Expand Down Expand Up @@ -491,7 +491,7 @@ func getP2PKeys(clusterDir string, numOps int, testConfig addValidatorTestConfig
}

var p2pKeys []*k1.PrivateKey
for i := 0; i < numOps; i++ {
for i := range numOps {

Check warning on line 494 in cmd/addvalidators.go

View check run for this annotation

Codecov / codecov/patch

cmd/addvalidators.go#L494

Added line #L494 was not covered by tests
dir := path.Join(clusterDir, fmt.Sprintf("node%d", i))
enrKeyFile := path.Join(dir, "charon-enr-private-key")
p2pKey, err := k1util.Load(enrKeyFile)
Expand Down Expand Up @@ -533,7 +533,7 @@ func validateP2PKeysOrder(p2pKeys []*k1.PrivateKey, ops []*manifestpb.Operator)
// repeatAddr repeats the same address for all the validators.
func repeatAddr(addr string, numVals int) []string {
var addrs []string
for i := 0; i < numVals; i++ {
for range numVals {
addrs = append(addrs, addr)
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/addvalidators_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestRunAddValidators(t *testing.T) {
)

var nodeDirnames []string
for i := 0; i < n; i++ {
for i := range n {
nodeDirnames = append(nodeDirnames, fmt.Sprintf("node%d", i))
}

Expand Down Expand Up @@ -192,7 +192,7 @@ func TestRunAddValidators(t *testing.T) {
// Delete existing deposit data file in each node directory since the deposit file names are same
// when add validators command is run twice consecutively. This is because the test finishes in
// milliseconds and filenames are named YYYYMMDDHHMMSS which doesn't account for milliseconds.
for i := 0; i < n; i++ {
for i := range n {
entries, err := os.ReadDir(nodeDir(tmp, i))
require.NoError(t, err)
for _, e := range entries {
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestValidateP2PKeysOrder(t *testing.T) {
ops []*manifestpb.Operator
)

for i := 0; i < n; i++ {
for i := range n {
key, enrStr := testutil.RandomENR(t, seed+i)
p2pKeys = append(p2pKeys, key)
ops = append(ops, &manifestpb.Operator{Enr: enrStr.String()})
Expand All @@ -257,7 +257,7 @@ func TestValidateP2PKeysOrder(t *testing.T) {
ops []*manifestpb.Operator
)

for i := 0; i < n; i++ {
for i := range n {
key, enrStr := testutil.RandomENR(t, seed+i)
p2pKeys = append(p2pKeys, key)
ops = append(ops, &manifestpb.Operator{Enr: enrStr.String()})
Expand Down
Loading

0 comments on commit bc4c1ba

Please sign in to comment.