Skip to content

Commit

Permalink
Add lint for ts files. Remove the majority of unused variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Dec 21, 2020
1 parent 75555e9 commit fb0e91c
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
**/node_modules/**
build/
dist/
volumes/
volumes/
.tslintrc.js
18 changes: 18 additions & 0 deletions .tslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file has nothing to do with TSLint library
// It's just ESLint config file for the typescript language

module.exports = {
root: true,
env: {
browser: true,
node: true,
es6: true,
mocha: true
},
parser: '@typescript-eslint/parser',
plugins: ["@typescript-eslint"],
rules: {
// This is the only rule that should be enforced in typescript
'@typescript-eslint/no-unused-vars': 'error',
}
}
2 changes: 1 addition & 1 deletion contracts/test/unit_tests/proxy_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');
const { deployContract } = require('ethereum-waffle');
const { wallet, wallet1, wallet2, deployTestContract, getCallRevertReason } = require('./common');
const { wallet, wallet2, deployTestContract, getCallRevertReason } = require('./common');

import { Contract, constants } from 'ethers';

Expand Down
4 changes: 1 addition & 3 deletions contracts/test/unit_tests/specific_tokens_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { ETHProxy } from 'zksync';
import { Address, TokenAddress } from 'zksync/build/types';
import { Deployer, readContractCode, readTestContracts } from '../../src.ts/deploy';

const { simpleEncode } = require('ethereumjs-abi');
const { expect } = require('chai');
const { deployContract } = require('ethereum-waffle');
const { wallet, exitWallet, deployTestContract, getCallRevertReason, IERC20_INTERFACE } = require('./common');
import * as zksync from 'zksync';
const { wallet, exitWallet, getCallRevertReason, IERC20_INTERFACE } = require('./common');

async function onchainTokenBalanceOfContract(
ethWallet: ethers.Wallet,
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/unit_tests/upgradeGatekeeper_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { constants } from 'ethers';

const { expect } = require('chai');
const { deployContract } = require('ethereum-waffle');
const { provider, wallet, wallet1, wallet2, deployTestContract, getCallRevertReason } = require('./common');
const { provider, wallet, wallet2, deployTestContract, getCallRevertReason } = require('./common');

const { performance } = require('perf_hooks');

// some random constants for checking write and read from storage
const bytes = [133, 174, 97, 255];

import { Contract, ethers } from 'ethers';
import { Contract } from 'ethers';

const TX_OPTIONS = {
gasLimit: 900000
Expand Down
3 changes: 2 additions & 1 deletion contracts/test/unit_tests/zksync_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('zkSync signature verification unit tests', function () {
const signature = await randomWallet.signMessage(
zksync.utils.getChangePubkeyMessage(pubkeyHash, nonce, accountId)
);
const { revertReason, result } = await getCallRevertReason(() =>
const { result } = await getCallRevertReason(() =>
testContract.changePubkeySignatureCheck(
signature,
pubkeyHash.replace('sync:', '0x'),
Expand Down Expand Up @@ -410,6 +410,7 @@ describe('zkSync withdraw unit tests', function () {
await zksyncContract.setBalanceToWithdraw(wallet.address, tokenId, withdrawAmount);

const onchainBalBefore = await onchainBalance(wallet, tokenContract.address);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { revertReason } = await getCallRevertReason(
async () => await performWithdraw(wallet, tokenContract.address, tokenId, withdrawAmount.add(1))
);
Expand Down
3 changes: 1 addition & 2 deletions core/tests/ts-tests/tests/forced-exit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Tester } from './tester';
import { expect } from 'chai';
import { Wallet, types, utils } from 'zksync';
import { BigNumber } from 'ethers';
import { Wallet, types } from 'zksync';
import { sleep } from 'zksync/build/utils';

type TokenLike = types.TokenLike;
Expand Down
2 changes: 1 addition & 1 deletion core/tests/ts-tests/tests/misc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tester } from './tester';
import { expect } from 'chai';
import { Wallet, types, utils } from 'zksync';
import { Wallet, types } from 'zksync';
import { BigNumber } from 'ethers';

type TokenLike = types.TokenLike;
Expand Down
1 change: 0 additions & 1 deletion core/tests/ts-tests/tests/priority-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Tester } from './tester';
import { expect } from 'chai';
import { Wallet, types } from 'zksync';
import { BigNumber } from 'ethers';
import { sleep } from 'zksync/build/utils';

type TokenLike = types.TokenLike;

Expand Down
2 changes: 1 addition & 1 deletion core/tests/ts-tests/tests/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tester } from './tester';
import { expect } from 'chai';
import { Wallet, types, utils } from 'zksync';
import { Wallet, types } from 'zksync';
import { BigNumber } from 'ethers';

type TokenLike = types.TokenLike;
Expand Down
2 changes: 1 addition & 1 deletion core/tests/ts-tests/tests/withdraw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tester } from './tester';
import { expect } from 'chai';
import { Wallet, types, utils } from 'zksync';
import { Wallet, types } from 'zksync';
import { BigNumber } from 'ethers';
import { sleep } from 'zksync/build/utils';

Expand Down
3 changes: 1 addition & 2 deletions infrastructure/fee-seller/tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { types } from 'zksync';
import { BigNumber, BigNumberish, utils } from 'ethers';
import { BigNumber, utils } from 'ethers';
import { expect } from 'chai';
import { isOperationFeeAcceptable, numberAsFractionInBIPs } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/fee-seller/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function approveTokenIfNotApproved(signer: ethers.Signer, tokenAddr
const approved = BigNumber.from(currentAllowance).gte(ERC20_APPROVE_TRESHOLD);
if (!approved) {
console.log(`Approving token ${tokenAddress}`);
const tx = await erc20contract.approve(contractAddress, MAX_ERC20_APPROVE_AMOUNT);
await erc20contract.approve(contractAddress, MAX_ERC20_APPROVE_AMOUNT);
}
}

Expand Down
2 changes: 0 additions & 2 deletions infrastructure/sdk-test-vector-generator/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as zksync from 'zksync';

export interface TestVectorEntry {
inputs: any;
outputs: any;
Expand Down
1 change: 0 additions & 1 deletion infrastructure/zk/src/dummy-prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as utils from './utils';

import * as server from './server';
import * as contract from './contract';
import * as db from './db/db';

const VERIFIER_FILE = 'contracts/contracts/Verifier.sol';

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/zk/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ command
command
.command('deploy-eip1271')
.description('deploy test EIP-1271 "smart wallet"')
.action(async (cmd: Command) => {
.action(async () => {
await deployEIP1271();
});

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
"zk": "yarn workspace zk",
"lint:md": "markdownlint $(find . -name '*.md' -print -o -path '*/node_modules' -prune)",
"lint:sol": "solhint contracts/{,dev-}contracts{,/**}/*.sol",
"lint:js": "eslint $(find . -name '*.js' | grep -v 'node_modules\\|build\\|dist')"
"lint:js": "eslint $(find . -name '*.js' | grep -v 'node_modules\\|build\\|dist\\|.tslintrc.js')",
"lint:ts": "eslint --ext ts --no-eslintrc -c .tslintrc.js $(find . -name '*.ts' | grep -v 'node_modules\\|build\\|dist')"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.16.0",
"eslint-config-alloy": "^3.8.2",
Expand Down
1 change: 1 addition & 0 deletions sdk/zksync.js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export abstract class AbstractJSONRPCTransport {
subscriptionsSupported(): boolean {
return false;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async subscribe(subMethod: string, subParams, unsubMethod: string, cb: (data: any) => void): Promise<Subscription> {
throw new Error('subscription are not supported for this transport');
}
Expand Down
7 changes: 1 addition & 6 deletions sdk/zksync.js/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
PriorityOperationReceipt,
TransactionReceipt,
PubKeyHash,
TxEthSignature,
ChangePubKey,
EthSignerType,
SignedTransaction,
Expand All @@ -22,12 +21,8 @@ import {
IERC20_INTERFACE,
isTokenETH,
MAX_ERC20_APPROVE_AMOUNT,
getChangePubkeyMessage,
SYNC_MAIN_CONTRACT_INTERFACE,
getSignedBytesFromMessage,
signMessagePersonalAPI,
ERC20_DEPOSIT_GAS_LIMIT,
getEthSignatureType,
serializeTransfer
} from './utils';

Expand Down Expand Up @@ -632,7 +627,7 @@ export class Wallet {
try {
const gasEstimate = await mainZkSyncContract.estimateGas.depositERC20(...args).then(
(estimate) => estimate,
(_err) => BigNumber.from('0')
() => BigNumber.from('0')
);
txRequest.gasLimit = gasEstimate.gte(ERC20_DEPOSIT_GAS_LIMIT)
? gasEstimate
Expand Down
4 changes: 2 additions & 2 deletions sdk/zksync.js/tests/vectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ describe(txVectors['description'], function () {

it('ForcedExit signature', async function () {
for (const item of txVectors.items) {
const { type: txType, ethPrivateKey, data: forcedExit, ethSignData } = item.inputs;
const { type: txType, ethPrivateKey, data: forcedExit } = item.inputs;
const expected = item.outputs;
const privateKey = parseHexWithPrefix(ethPrivateKey);
const { signer, ethMessageSigner } = await getSigner(privateKey);
const { signer } = await getSigner(privateKey);

if (txType === 'ForcedExit') {
const signBytes = signer.forcedExitSignBytes(forcedExit);
Expand Down
6 changes: 2 additions & 4 deletions sdk/zksync.js/tests/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { assert, expect } from 'chai';
import { BigNumber, utils, ethers } from 'ethers';
import { expect } from 'chai';
import { BigNumber, ethers } from 'ethers';
import { Wallet } from '../src/wallet';
import { getTokens } from './helpers';

import { TokenSet, parseHexWithPrefix } from '../src/utils';
import { privateKeyFromSeed, signTransactionBytes } from '../src/crypto';
import { Provider } from '../src/provider';

describe('Wallet with mock provider', function () {
Expand Down
Loading

0 comments on commit fb0e91c

Please sign in to comment.