From 839db68571037f6fff8273aaade6ea0bd14ea8a5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 16 May 2018 14:59:10 +0200 Subject: Fix TSLint rules --- .../contract_wrappers_public_network_config_schema.ts | 16 +++++++++++++++- packages/contract-wrappers/src/utils/constants.ts | 1 + packages/contract-wrappers/src/utils/filter_utils.ts | 8 ++++---- packages/contract-wrappers/src/utils/utils.ts | 3 ++- .../contract-wrappers/test/ether_token_wrapper_test.ts | 4 ++-- packages/contract-wrappers/test/global_hooks.ts | 3 ++- .../contract-wrappers/test/order_validation_test.ts | 17 ++++++++++++----- 7 files changed, 38 insertions(+), 14 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts b/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts index bf1000afa..304cd100b 100644 --- a/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts +++ b/packages/contract-wrappers/src/schemas/contract_wrappers_public_network_config_schema.ts @@ -1,9 +1,23 @@ +const networkNameToId: { [networkName: string]: number } = { + mainnet: 1, + ropsten: 3, + rinkeby: 4, + kovan: 42, + ganache: 50, +}; + export const contractWrappersPublicNetworkConfigSchema = { id: '/ZeroExContractPublicNetworkConfig', properties: { networkId: { type: 'number', - enum: [1, 3, 4, 42, 50], + enum: [ + networkNameToId.mainnet, + networkNameToId.kovan, + networkNameToId.ropsten, + networkNameToId.rinkeby, + networkNameToId.ganache, + ], }, gasPrice: { $ref: '/Number' }, zrxContractAddress: { $ref: '/Address' }, diff --git a/packages/contract-wrappers/src/utils/constants.ts b/packages/contract-wrappers/src/utils/constants.ts index 07da6745d..76d805cac 100644 --- a/packages/contract-wrappers/src/utils/constants.ts +++ b/packages/contract-wrappers/src/utils/constants.ts @@ -6,6 +6,7 @@ export const constants = { INVALID_JUMP_PATTERN: 'invalid JUMP at', OUT_OF_GAS_PATTERN: 'out of gas', INVALID_TAKER_FORMAT: 'instance.taker is not of a type(s) string', + // tslint:disable-next-line:custom-no-magic-numbers UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1), DEFAULT_BLOCK_POLLING_INTERVAL: 1000, }; diff --git a/packages/contract-wrappers/src/utils/filter_utils.ts b/packages/contract-wrappers/src/utils/filter_utils.ts index c5df7321e..4ec9e256b 100644 --- a/packages/contract-wrappers/src/utils/filter_utils.ts +++ b/packages/contract-wrappers/src/utils/filter_utils.ts @@ -73,14 +73,14 @@ export const filterUtils = { return false; } if (!_.isUndefined(filter.topics)) { - return filterUtils.matchesTopics(log.topics, filter.topics); + return filterUtils.doesMatchTopics(log.topics, filter.topics); } return true; }, - matchesTopics(logTopics: string[], filterTopics: Array): boolean { + doesMatchTopics(logTopics: string[], filterTopics: Array): boolean { const matchesTopic = _.zipWith(logTopics, filterTopics, filterUtils.matchesTopic.bind(filterUtils)); - const matchesTopics = _.every(matchesTopic); - return matchesTopics; + const doesMatchTopics = _.every(matchesTopic); + return doesMatchTopics; }, matchesTopic(logTopic: string, filterTopic: string[] | string | null): boolean { if (_.isArray(filterTopic)) { diff --git a/packages/contract-wrappers/src/utils/utils.ts b/packages/contract-wrappers/src/utils/utils.ts index af1125632..7cf9450a0 100644 --- a/packages/contract-wrappers/src/utils/utils.ts +++ b/packages/contract-wrappers/src/utils/utils.ts @@ -5,7 +5,8 @@ export const utils = { return new Error(`Unexpected switch value: ${value} encountered for ${name}`); }, getCurrentUnixTimestampSec(): BigNumber { - return new BigNumber(Date.now() / 1000).round(); + const milisecondsInSecond = 1000; + return new BigNumber(Date.now() / milisecondsInSecond).round(); }, getCurrentUnixTimestampMs(): BigNumber { return new BigNumber(Date.now()); diff --git a/packages/contract-wrappers/test/ether_token_wrapper_test.ts b/packages/contract-wrappers/test/ether_token_wrapper_test.ts index e9a9705b1..74f84a485 100644 --- a/packages/contract-wrappers/test/ether_token_wrapper_test.ts +++ b/packages/contract-wrappers/test/ether_token_wrapper_test.ts @@ -41,7 +41,7 @@ describe('EtherTokenWrapper', () => { let addressWithETH: string; let wethContractAddress: string; let depositWeiAmount: BigNumber; - let decimalPlaces: number; + const decimalPlaces = 7; let addressWithoutFunds: string; const gasPrice = new BigNumber(1); const zeroExConfig = { @@ -59,7 +59,6 @@ describe('EtherTokenWrapper', () => { addressWithETH = userAddresses[0]; wethContractAddress = contractWrappers.etherToken.getContractAddressIfExists() as string; depositWeiAmount = Web3Wrapper.toWei(new BigNumber(5)); - decimalPlaces = 7; addressWithoutFunds = userAddresses[1]; }); beforeEach(async () => { @@ -154,6 +153,7 @@ describe('EtherTokenWrapper', () => { const preWETHBalance = await contractWrappers.token.getBalanceAsync(wethContractAddress, addressWithETH); expect(preWETHBalance).to.be.bignumber.equal(0); + // tslint:disable-next-line:custom-no-magic-numbers const overWETHBalance = preWETHBalance.add(999999999); return expect( diff --git a/packages/contract-wrappers/test/global_hooks.ts b/packages/contract-wrappers/test/global_hooks.ts index 53b3ef545..fa1dfae38 100644 --- a/packages/contract-wrappers/test/global_hooks.ts +++ b/packages/contract-wrappers/test/global_hooks.ts @@ -8,7 +8,8 @@ import { provider } from './utils/web3_wrapper'; before('migrate contracts', async function(): Promise { // HACK: Since the migrations take longer then our global mocha timeout limit // we manually increase it for this before hook. - this.timeout(20000); + const mochaTestTimeoutMs = 20000; + this.timeout(mochaTestTimeoutMs); const txDefaults = { gas: devConstants.GAS_ESTIMATE, from: devConstants.TESTRPC_FIRST_ADDRESS, diff --git a/packages/contract-wrappers/test/order_validation_test.ts b/packages/contract-wrappers/test/order_validation_test.ts index d28549ba2..ed2159026 100644 --- a/packages/contract-wrappers/test/order_validation_test.ts +++ b/packages/contract-wrappers/test/order_validation_test.ts @@ -105,6 +105,7 @@ describe('OrderValidation', () => { }); it('should succeed if the order is asymmetric and fillable', async () => { const makerFillableAmount = fillableAmount; + // tslint:disable-next-line:custom-no-magic-numbers const takerFillableAmount = fillableAmount.minus(4); const signedOrder = await fillScenarios.createAsymmetricFillableSignedOrderAsync( makerTokenAddress, @@ -171,6 +172,7 @@ describe('OrderValidation', () => { fillableAmount, ); // 27 <--> 28 + // tslint:disable-next-line:custom-no-magic-numbers signedOrder.ecSignature.v = 28 - signedOrder.ecSignature.v + 27; return expect( contractWrappers.exchange.validateFillOrderThrowIfInvalidAsync( @@ -205,7 +207,8 @@ describe('OrderValidation', () => { takerAddress, fillableAmount, ); - const nonTakerAddress = userAddresses[6]; + const sixthIndex = 6; + const nonTakerAddress = userAddresses[sixthIndex]; return expect( contractWrappers.exchange.validateFillOrderThrowIfInvalidAsync( signedOrder, @@ -352,7 +355,8 @@ describe('OrderValidation', () => { takerAddress, zrxTokenAddress, ); - expect(transferFromAsync.callCount).to.be.equal(4); + const expectedCallCount = 4; + expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); expect( transferFromAsync .getCall(0) @@ -422,7 +426,8 @@ describe('OrderValidation', () => { takerAddress, zrxTokenAddress, ); - expect(transferFromAsync.callCount).to.be.equal(4); + const expectedCallCount = 4; + expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); expect( transferFromAsync .getCall(0) @@ -490,7 +495,8 @@ describe('OrderValidation', () => { takerAddress, zrxTokenAddress, ); - expect(transferFromAsync.callCount).to.be.equal(4); + const expectedCallCount = 4; + expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); const makerFillAmount = transferFromAsync.getCall(0).args[3]; expect(makerFillAmount).to.be.bignumber.equal(makerTokenAmount); }); @@ -517,7 +523,8 @@ describe('OrderValidation', () => { ); const makerPartialFee = makerFee.div(2); const takerPartialFee = takerFee.div(2); - expect(transferFromAsync.callCount).to.be.equal(4); + const expectedCallCount = 4; + expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); const partialMakerFee = transferFromAsync.getCall(2).args[3]; expect(partialMakerFee).to.be.bignumber.equal(makerPartialFee); const partialTakerFee = transferFromAsync.getCall(3).args[3]; -- cgit v1.2.3 From cf7967e6296aac0a328143e92a22c5682541a576 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 17 May 2018 14:07:44 +0200 Subject: Disable magic number rule in more places where it isn't helping code readability --- .../contract-wrappers/test/order_validation_test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/test/order_validation_test.ts b/packages/contract-wrappers/test/order_validation_test.ts index ed2159026..d9077d6e4 100644 --- a/packages/contract-wrappers/test/order_validation_test.ts +++ b/packages/contract-wrappers/test/order_validation_test.ts @@ -207,8 +207,8 @@ describe('OrderValidation', () => { takerAddress, fillableAmount, ); - const sixthIndex = 6; - const nonTakerAddress = userAddresses[sixthIndex]; + // tslint:disable-next-line:custom-no-magic-numbers + const nonTakerAddress = userAddresses[6]; return expect( contractWrappers.exchange.validateFillOrderThrowIfInvalidAsync( signedOrder, @@ -355,8 +355,8 @@ describe('OrderValidation', () => { takerAddress, zrxTokenAddress, ); - const expectedCallCount = 4; - expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); + // tslint:disable-next-line:custom-no-magic-numbers + expect(transferFromAsync.callCount).to.be.equal(4); expect( transferFromAsync .getCall(0) @@ -426,8 +426,8 @@ describe('OrderValidation', () => { takerAddress, zrxTokenAddress, ); - const expectedCallCount = 4; - expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); + // tslint:disable-next-line:custom-no-magic-numbers + expect(transferFromAsync.callCount).to.be.equal(4); expect( transferFromAsync .getCall(0) @@ -495,8 +495,8 @@ describe('OrderValidation', () => { takerAddress, zrxTokenAddress, ); - const expectedCallCount = 4; - expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); + // tslint:disable-next-line:custom-no-magic-numbers + expect(transferFromAsync.callCount).to.be.equal(4); const makerFillAmount = transferFromAsync.getCall(0).args[3]; expect(makerFillAmount).to.be.bignumber.equal(makerTokenAmount); }); @@ -523,8 +523,8 @@ describe('OrderValidation', () => { ); const makerPartialFee = makerFee.div(2); const takerPartialFee = takerFee.div(2); - const expectedCallCount = 4; - expect(transferFromAsync.callCount).to.be.equal(expectedCallCount); + // tslint:disable-next-line:custom-no-magic-numbers + expect(transferFromAsync.callCount).to.be.equal(4); const partialMakerFee = transferFromAsync.getCall(2).args[3]; expect(partialMakerFee).to.be.bignumber.equal(makerPartialFee); const partialTakerFee = transferFromAsync.getCall(3).args[3]; -- cgit v1.2.3