Skip to content

Commit

Permalink
chore: Remove lodash times in favor of foundation fn (AztecProtocol#3877
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino authored Jan 18, 2024
1 parent 5658468 commit a10eef0
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 55 deletions.
1 change: 0 additions & 1 deletion yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"concurrently": "^8.0.1",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.4",
"lodash.times": "^4.3.2",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ExtendedContractData, L2Block, L2BlockL2Logs, LogType } from '@aztec/circuit-types';
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { times } from '@aztec/foundation/collection';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { sleep } from '@aztec/foundation/sleep';
import { ContractDeploymentEmitterAbi, InboxAbi, RollupAbi } from '@aztec/l1-artifacts';

import { MockProxy, mock } from 'jest-mock-extended';
import times from 'lodash.times';
import { Chain, HttpTransport, Log, PublicClient, Transaction, encodeFunctionData, toHex } from 'viem';

import { Archiver } from './archiver.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuit-types/src/l2_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import {
STRING_ENCODING,
} from '@aztec/circuits.js';
import { makeAppendOnlyTreeSnapshot, makeGlobalVariables, makeHeader } from '@aztec/circuits.js/factories';
import { times } from '@aztec/foundation/collection';
import { keccak, sha256 } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import times from 'lodash.times';

import { ContractData } from './contract_data.js';
import { L2Tx } from './l2_tx.js';
import { LogType, TxL2Logs } from './logs/index.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuit-types/src/l2_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import {
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
Vector,
} from '@aztec/circuits.js';
import { times } from '@aztec/foundation/collection';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';

import times from 'lodash.times';

import { ContractData } from './contract_data.js';
import { PublicDataWrite } from './public_data_write.js';
import { TxHash } from './tx/tx_hash.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuit-types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import {
} from '@aztec/circuits.js';
import { makePrivateKernelPublicInputsFinal, makePublicCallRequest } from '@aztec/circuits.js/factories';
import { ContractArtifact } from '@aztec/foundation/abi';
import { times } from '@aztec/foundation/collection';
import { randomBytes } from '@aztec/foundation/crypto';
import { Tuple } from '@aztec/foundation/serialize';

import times from 'lodash.times';

import { ExtendedContractData } from './contract_data.js';
import { DeployedContract } from './interfaces/index.js';
import { FunctionL2Logs, Note, TxL2Logs } from './logs/index.js';
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/circuits.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@
"@aztec/foundation": "workspace:^",
"eslint": "^8.35.0",
"lodash.chunk": "^4.2.0",
"lodash.times": "^4.3.2",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/lodash.chunk": "^4.2.7",
"@types/lodash.times": "^4.3.7",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"prettier": "^2.8.4",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/abis/abis.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import times from 'lodash.times';
import { times } from '@aztec/foundation/collection';

import {
AztecAddress,
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/structs/aggregation_object.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { times } from '@aztec/foundation/collection';
import { Fq, Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import times from 'lodash.times';

import { UInt32, Vector } from './shared.js';
import { G1AffineElement } from './verification_key.js';

Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/structs/verification_key.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { times } from '@aztec/foundation/collection';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import times from 'lodash.times';

import { Fq } from './index.js';
import { CircuitType } from './shared.js';

Expand Down
2 changes: 0 additions & 2 deletions yarn-project/end-to-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@types/koa-static": "^4.0.2",
"@types/levelup": "^5.1.2",
"@types/lodash.every": "^4.6.7",
"@types/lodash.times": "^4.3.7",
"@types/memdown": "^3.0.3",
"@types/node": "^18.7.23",
"buffer": "^6.0.3",
Expand All @@ -61,7 +60,6 @@
"lmdb": "^2.9.1",
"lodash.compact": "^3.0.1",
"lodash.every": "^4.6.0",
"lodash.times": "^4.3.2",
"memdown": "^6.1.1",
"process": "^0.11.10",
"puppeteer": "^21.3.4",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/benchmarks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
retryUntil,
sleep,
} from '@aztec/aztec.js';
import { times } from '@aztec/foundation/collection';
import { BenchmarkingContract } from '@aztec/noir-contracts/Benchmarking';
import { PXEService, createPXEService } from '@aztec/pxe';

import { mkdirpSync } from 'fs-extra';
import { globSync } from 'glob';
import times from 'lodash.times';
import { join } from 'path';

import { EndToEndContext, setup } from '../fixtures/utils.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import {
Wallet,
isContractDeployed,
} from '@aztec/aztec.js';
import { times } from '@aztec/foundation/collection';
import { pedersenHash } from '@aztec/foundation/crypto';
import { TestContract, TestContractArtifact } from '@aztec/noir-contracts/Test';
import { TokenContract } from '@aztec/noir-contracts/Token';

import times from 'lodash.times';

import { setup } from './fixtures/utils.js';

describe('e2e_block_building', () => {
Expand Down
13 changes: 13 additions & 0 deletions yarn-project/foundation/src/collection/array.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { times } from './array.js';

describe('times', () => {
it('should return an array with the result from all executions', () => {
const result = times(5, i => i * 2);
expect(result).toEqual([0, 2, 4, 6, 8]);
});

it('should return an empty array when n is 0', () => {
const result = times(0, i => i * 2);
expect(result).toEqual([]);
});
});
10 changes: 10 additions & 0 deletions yarn-project/foundation/src/collection/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ export function isArrayEmpty<T>(arr: T[], isEmpty: (item: T) => boolean): boolea
export function arrayNonEmptyLength<T>(arr: T[], isEmpty: (item: T) => boolean): number {
return arr.reduce((sum, item) => (isEmpty(item) ? sum : sum + 1), 0);
}

/**
* Executes the given function n times and returns the results in an array.
* @param n - How many times to repeat.
* @param fn - Mapper from index to value.
* @returns The array with the result from all executions.
*/
export function times<T>(n: number, fn: (i: number) => T): T[] {
return [...Array(n).keys()].map(i => fn(i));
}
2 changes: 0 additions & 2 deletions yarn-project/noir-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"fs-extra": "^11.1.1",
"lodash.camelcase": "^4.3.0",
"lodash.capitalize": "^4.2.1",
"lodash.times": "^4.3.2",
"memfs": "^4.6.0",
"pako": "^2.1.0",
"semver": "^7.5.4",
Expand All @@ -66,7 +65,6 @@
"@types/jest": "^29.5.0",
"@types/lodash.camelcase": "^4.3.7",
"@types/lodash.capitalize": "^4.2.7",
"@types/lodash.times": "^4.3.7",
"@types/node": "^18.7.23",
"@types/pako": "^2.0.0",
"@types/semver": "^7.5.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
FunctionType,
StructType,
} from '@aztec/foundation/abi';
import { times } from '@aztec/foundation/collection';

import camelCase from 'lodash.camelcase';
import capitalize from 'lodash.capitalize';
import times from 'lodash.times';

/**
* Returns whether this function type corresponds to a private call.
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/p2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@
"@libp2p/tcp": "^8.0.4",
"it-pipe": "^3.0.1",
"libp2p": "^0.46.6",
"lodash.times": "^4.3.2",
"sha3": "^2.1.4",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/lodash.times": "^4.3.7",
"@types/node": "^18.14.6",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.4",
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/pxe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"koa": "^2.14.2",
"koa-router": "^12.0.0",
"lodash.omit": "^4.5.0",
"lodash.times": "^4.3.2",
"sha3": "^2.1.4",
"tslib": "^2.4.0",
"viem": "^1.2.5"
Expand All @@ -55,7 +54,6 @@
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/lodash.omit": "^4.5.7",
"@types/lodash.times": "^4.3.7",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.3",
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/sequencer-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@aztec/world-state": "workspace:^",
"lodash.chunk": "^4.2.0",
"lodash.pick": "^4.4.0",
"lodash.times": "^4.3.2",
"tslib": "^2.4.0",
"viem": "^1.2.5"
},
Expand All @@ -55,7 +54,6 @@
"@types/levelup": "^5.1.2",
"@types/lodash.chunk": "^4.2.7",
"@types/lodash.pick": "^4.4.7",
"@types/lodash.times": "^4.3.7",
"@types/memdown": "^3.0.0",
"@types/node": "^18.7.23",
"concurrently": "^7.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ import {
} from '@aztec/circuits.js/factories';
import { makeTuple, range } from '@aztec/foundation/array';
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
import { times } from '@aztec/foundation/collection';
import { to2Fields } from '@aztec/foundation/serialize';
import { MerkleTreeOperations, MerkleTrees } from '@aztec/world-state';

import { MockProxy, mock } from 'jest-mock-extended';
import { default as levelup } from 'levelup';
import times from 'lodash.times';
import { type MemDown, default as memdown } from 'memdown';

import { VerificationKeys, getVerificationKeys } from '../mocks/verification_keys.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ import {
makeSelector,
} from '@aztec/circuits.js/factories';
import { makeTuple } from '@aztec/foundation/array';
import { padArrayEnd } from '@aztec/foundation/collection';
import { padArrayEnd, times } from '@aztec/foundation/collection';
import { SiblingPath } from '@aztec/types/membership';
import { MerkleTreeOperations, TreeInfo } from '@aztec/world-state';

import { MockProxy, mock } from 'jest-mock-extended';
import times from 'lodash.times';

import { PublicProver } from '../prover/index.js';
import { PublicKernelCircuitSimulator } from '../simulator/index.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
makeEmptyProof,
} from '@aztec/circuits.js';
import { times } from '@aztec/foundation/collection';
import { P2P, P2PClientState } from '@aztec/p2p';
import { MerkleTreeOperations, WorldStateRunningState, WorldStateSynchronizer } from '@aztec/world-state';

import { MockProxy, mock, mockFn } from 'jest-mock-extended';
import times from 'lodash.times';

import { BlockBuilder } from '../block_builder/index.js';
import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { L1ToL2MessageSource, L2Block, L2BlockSource, MerkleTreeId, Tx } from '@aztec/circuit-types';
import { L2BlockBuiltStats } from '@aztec/circuit-types/stats';
import { GlobalVariables } from '@aztec/circuits.js';
import { times } from '@aztec/foundation/collection';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
import { Timer, elapsed } from '@aztec/foundation/timer';
import { P2P } from '@aztec/p2p';
import { WorldStateStatus, WorldStateSynchronizer } from '@aztec/world-state';

import times from 'lodash.times';

import { BlockBuilder } from '../block_builder/index.js';
import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
import { L1Publisher } from '../publisher/l1-publisher.js';
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/world-state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@
"@aztec/merkle-tree": "workspace:^",
"@aztec/types": "workspace:^",
"levelup": "^5.1.1",
"lodash.times": "^4.3.2",
"memdown": "^6.1.1",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/levelup": "^5.1.2",
"@types/lodash.times": "^4.3.7",
"@types/memdown": "^3.0.0",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
Expand Down
Loading

0 comments on commit a10eef0

Please sign in to comment.