From 6aaa24d502c1b98b97d10f0b909da09652934e0b Mon Sep 17 00:00:00 2001 From: quentin Date: Tue, 19 Dec 2017 18:08:57 +0100 Subject: [PATCH 1/4] feat: add tslint + disable offended rules --- package-lock.json | 111 +++++++++++++++++++++++++++++++++++++++++----- package.json | 4 +- tslint.json | 43 ++++++++++++++++++ 3 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 tslint.json diff --git a/package-lock.json b/package-lock.json index 9551166399..8a7da24ddd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -795,11 +795,6 @@ "tweetnacl": "0.14.5" } }, - "bignumber.js": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-4.1.0.tgz", - "integrity": "sha512-eJzYkFYy9L4JzXsbymsFn3p54D+llV27oTQ+ziJG7WFRheJcNZilgVXMG0LoZtlQSKBsJdWtLFqOD0u+U0jZKA==" - }, "bindings": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz", @@ -1043,6 +1038,12 @@ "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" }, + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + }, "builtin-status-codes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz", @@ -1093,12 +1094,6 @@ "check-error": "1.0.2" } }, - "chai-bignumber": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/chai-bignumber/-/chai-bignumber-2.0.2.tgz", - "integrity": "sha512-BIdRNjRaoRj4bMsZLKbIZPMNKqmwnzNiyxqBYDSs6dFOCs9w8OHPuUE8e1bH60i1IhOzT0NjLtCD+lKEWB1KTQ==", - "dev": true - }, "chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", @@ -4769,6 +4764,100 @@ "strip-json-comments": "2.0.1" } }, + "tslib": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.8.1.tgz", + "integrity": "sha1-aUavLR1lGnsYY7Ux1uWvpBqkTqw=", + "dev": true + }, + "tslint": { + "version": "5.8.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.8.0.tgz", + "integrity": "sha1-H0mtWy53x2w69N3K5VKuTjYS6xM=", + "dev": true, + "requires": { + "babel-code-frame": "6.26.0", + "builtin-modules": "1.1.1", + "chalk": "2.3.0", + "commander": "2.12.2", + "diff": "3.3.1", + "glob": "7.1.2", + "minimatch": "3.0.4", + "resolve": "1.5.0", + "semver": "5.4.1", + "tslib": "1.8.1", + "tsutils": "2.13.1" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", + "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "dev": true, + "requires": { + "color-convert": "1.9.1" + } + }, + "chalk": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", + "integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==", + "dev": true, + "requires": { + "ansi-styles": "3.2.0", + "escape-string-regexp": "1.0.5", + "supports-color": "4.5.0" + } + }, + "commander": { + "version": "2.12.2", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz", + "integrity": "sha512-BFnaq5ZOGcDN7FlrtBT4xxkgIToalIIxwjxLWVJ8bGTpe1LroqMiqQXdA7ygc7CRvaYS+9zfPGFnJqFSayx+AA==", + "dev": true + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "1.1.8" + } + }, + "supports-color": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", + "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", + "dev": true, + "requires": { + "has-flag": "2.0.0" + } + } + } + }, + "tsutils": { + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.13.1.tgz", + "integrity": "sha512-XMOEvc2TiYesVSOJMI7OYPnBMSgcvERuGW5Li/J+2A0TuH607BPQnOLQ82oSPZCssB8c9+QGi6qhTBa/f1xQRA==", + "dev": true, + "requires": { + "tslib": "1.8.1" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", diff --git a/package.json b/package.json index e418987572..44d61c4d2c 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "test": "npm run build && node ./dist/test/test", "testunit": "npm run build && mocha --timeout 15000 dist/test/unit/*.js ", "testdeploy": "npm run build && node ./dist/test/deploy", - "testrpc": "testrpc -l 90000000 -p 8545 -m \"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat\"" + "testrpc": "testrpc -l 90000000 -p 8545 -m \"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat\"", + "lint": "tslint -p tsconfig.json -t verbose" }, "devDependencies": { "@types/chai": "^4.0.5", @@ -24,6 +25,7 @@ "dirty-chai": "^2.0.1", "mocha": "^4.0.1", "ts-node": "^3.3.0", + "tslint": "^5.8.0", "typings": "^2.1.1" }, "dependencies": { diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000000..61a8a4789a --- /dev/null +++ b/tslint.json @@ -0,0 +1,43 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "align": false, + "array-type": false, + "arrow-parens": false, + "arrow-return-shorthand": false, + "comment-format": false, + "curly": false, + "eofline": false, + "indent": false, + "interface-name": false, + "max-line-length": false, + "member-ordering": false, + "no-consecutive-blank-lines": false, + "no-console": false, + "no-shadowed-variable": false, + "no-trailing-whitespace": false, + "no-unused-expression": false, + "no-var-keyword": false, + "no-var-requires": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "object-literal-sort-keys": false, + "one-line": false, + "only-arrow-functions": false, + "ordered-imports": false, + "prefer-const": false, + "quotemark": false, + "semicolon": false, + "space-before-function-paren": false, + "trailing-comma": false, + "triple-equals": false, + "typedef-whitespace": false, + "variable-name": false, + "whitespace": false + }, + "rulesDirectory": [] +} From 3b81fcb6ecbde485edac4173f41d5590630fde20 Mon Sep 17 00:00:00 2001 From: quentin Date: Tue, 19 Dec 2017 18:10:45 +0100 Subject: [PATCH 2/4] feat(lint): enable no-trailing-whitespaces rule --- src/requestNetwork.ts | 2 +- .../requestEthereum-service.ts | 22 ++++----- src/servicesCore/requestCore-service.ts | 44 +++++++++--------- ...requestSynchroneExtensionEscrow-service.ts | 18 ++++---- src/servicesExternal/ipfs-service.ts | 8 ++-- src/servicesExternal/web3-single.ts | 22 ++++----- test/deploy.ts | 2 +- test/test.ts | 4 +- test/unit/accept.ts | 12 ++--- test/unit/cancel.ts | 18 ++++---- test/unit/createRequestAsPayee.ts | 46 +++++++++---------- test/unit/paymentAction.ts | 20 ++++---- test/unit/refundAction.ts | 18 ++++---- test/utils.ts | 2 +- tslint.json | 1 - 15 files changed, 119 insertions(+), 120 deletions(-) diff --git a/src/requestNetwork.ts b/src/requestNetwork.ts index b451a900c7..1f4531ab16 100644 --- a/src/requestNetwork.ts +++ b/src/requestNetwork.ts @@ -14,7 +14,7 @@ export default class RequestNetwork { public requestEthereumService: RequestEthereumService; public requestSynchroneExtensionEscrowService: RequestSynchroneExtensionEscrowService; public requestCoreService: RequestCoreService; - + constructor(provider? : any, networkId ? : number, useIpfsPublic : boolean = true) { if(provider && !networkId) { diff --git a/src/servicesContracts/requestEthereum-service.ts b/src/servicesContracts/requestEthereum-service.ts index 83ae4feee5..0ca326bdd8 100644 --- a/src/servicesContracts/requestEthereum-service.ts +++ b/src/servicesContracts/requestEthereum-service.ts @@ -100,7 +100,7 @@ export default class RequestEthereumService { // we do nothing here! }, (confirmationNumber: number, receipt: any) => { - if (confirmationNumber == _options.numberOfConfirmation) + if (confirmationNumber == _options.numberOfConfirmation) { let event = this.web3Single.decodeEvent(this.abiRequestCore, 'Created', receipt.events[0]); this.getRequest(event.requestId).then((request) => { @@ -283,7 +283,7 @@ export default class RequestEthereumService { this.getRequest(_requestId).then((request) => { if (_options.value.isNeg()) return promiEvent.reject(Error('_amount must a positive integer')); - + if ( request.state != Types.State.Accepted ) { return promiEvent.reject(Error('request must be accepted')); } @@ -435,7 +435,7 @@ export default class RequestEthereumService { let account = _options.from || defaultAccount; var method = this.instanceRequestEthereum.methods.withdraw(); - + this.web3Single.broadcastMethod( method, (transactionHash: string) => { @@ -468,15 +468,15 @@ export default class RequestEthereumService { public getRequest(_requestId: string): Promise < any > { return this.requestCoreServices.getRequest(_requestId); - } + } public getRequestHistory( _requestId: string, _fromBlock ?: number, _toBlock ?: number): Promise < any > { return this.requestCoreServices.getRequestHistory(_requestId,_fromBlock,_toBlock); - } - + } + public getRequestHistoryCurrencyContractInfo( _requestId: string, _fromBlock ?: number, @@ -484,14 +484,14 @@ export default class RequestEthereumService { return new Promise(async (resolve, reject) => { // let events = await this.instanceSynchroneExtensionEscrow.getPastEvents('allEvents', { // // allEvents and filter don't work together so far. issues created on web3 github - // // filter: {requestId: _requestId}, + // // filter: {requestId: _requestId}, // fromBlock: requestEthereum_Artifact.networks[this.web3Single.networkName].blockNumber, // toBlock: 'latest' // }); // events by event waiting for a patch of web3 let optionFilters = { - filter: { requestId: _requestId }, + filter: { requestId: _requestId }, fromBlock: requestEthereum_Artifact.networks[this.web3Single.networkName].blockNumber, toBlock: 'latest' }; @@ -500,7 +500,7 @@ export default class RequestEthereumService { let events = []; events = events.concat(await this.instanceRequestEthereum.getPastEvents('EtherAvailableToWithdraw', optionFilters)); - return resolve(await Promise.all(events.map(async e => { + return resolve(await Promise.all(events.map(async e => { return new Promise(async (resolve, reject) => { resolve({ _meta: { @@ -513,6 +513,6 @@ export default class RequestEthereumService { }); }); }))); - }); - } + }); + } } \ No newline at end of file diff --git a/src/servicesCore/requestCore-service.ts b/src/servicesCore/requestCore-service.ts index b7e9401521..36e0e31592 100644 --- a/src/servicesCore/requestCore-service.ts +++ b/src/servicesCore/requestCore-service.ts @@ -50,8 +50,8 @@ export default class RequestCoreService { } public getCollectEstimation( - _expectedAmount:any, - _currencyContract:string, + _expectedAmount:any, + _currencyContract:string, _extension:string): Promise < any > { _expectedAmount = new BN(_expectedAmount); @@ -74,7 +74,7 @@ export default class RequestCoreService { if (err) return reject(err); try { - if(data.creator == '0x0000000000000000000000000000000000000000') + if(data.creator == '0x0000000000000000000000000000000000000000') { return reject(Error('request not found')); } @@ -118,10 +118,10 @@ export default class RequestCoreService { public getRequestByTransactionHash( _hash: string): Promise < any > { return new Promise(async (resolve, reject) => { - try + try { let txReceipt = await this.web3Single.getTransactionReceipt(_hash); - + if(!txReceipt) { let tx = await this.web3Single.getTransaction(_hash); @@ -136,11 +136,11 @@ export default class RequestCoreService { } } - if(!txReceipt.logs || !txReceipt.logs[0] || !this.web3Single.areSameAddressesNoChecksum(txReceipt.logs[0].address,this.addressRequestCore)) + if(!txReceipt.logs || !txReceipt.logs[0] || !this.web3Single.areSameAddressesNoChecksum(txReceipt.logs[0].address,this.addressRequestCore)) { return reject(Error('transaction did not create a Request')); - } - + } + let event = this.web3Single.decodeTransactionLog(this.abiRequestCore, 'Created', txReceipt.logs[0]); if(!event) { @@ -153,7 +153,7 @@ export default class RequestCoreService { return reject(e); } }); - } + } public getRequestHistory( _requestId: string, @@ -169,14 +169,14 @@ export default class RequestCoreService { // let eventsCoreRaw = await this.instanceRequestCore.getPastEvents('allEvents', { // // allEvents and filter don't work together so far. issues created on web3 github - // // filter: {requestId: _requestId}, + // // filter: {requestId: _requestId}, // fromBlock: requestCore_Artifact.networks[this.web3Single.networkName].blockNumber, // toBlock: 'latest' // }); // events by event waiting for a patch of web3 let optionFilters = { - filter: { requestId: _requestId }, + filter: { requestId: _requestId }, fromBlock: _fromBlock?_fromBlock:requestCore_Artifact.networks[this.web3Single.networkName].blockNumber, toBlock: _toBlock?_toBlock:'latest' }; @@ -194,8 +194,8 @@ export default class RequestCoreService { eventsCoreRaw = eventsCoreRaw.concat(await this.instanceRequestCore.getPastEvents('NewData', optionFilters)); // waiting for filter working (see above) - let eventsCore = [] - eventsCore = await Promise.all(eventsCoreRaw.map(async e => { + let eventsCore = [] + eventsCore = await Promise.all(eventsCoreRaw.map(async e => { return new Promise(async (resolve, reject) => { resolve({ _meta: { @@ -224,10 +224,10 @@ export default class RequestCoreService { return diffBlockNumber != 0 ? diffBlockNumber : a._meta.logIndex - b._meta.logIndex; })); } catch(e) { - return reject(e); + return reject(e); } }); - }); + }); } public getRequestsByAddress( @@ -237,19 +237,19 @@ export default class RequestCoreService { return new Promise(async (resolve, reject) => { try { let eventsCorePayee = await this.instanceRequestCore.getPastEvents('Created', { - filter: { payee: _address }, + filter: { payee: _address }, fromBlock: _fromBlock?_fromBlock:requestCore_Artifact.networks[this.web3Single.networkName].blockNumber, toBlock: _toBlock?_toBlock:'latest' }); let eventsCorePayer = await this.instanceRequestCore.getPastEvents('Created', { - filter: { payer: _address }, + filter: { payer: _address }, fromBlock: _fromBlock?_fromBlock:requestCore_Artifact.networks[this.web3Single.networkName].blockNumber, toBlock: _toBlock?_toBlock:'latest' }); - eventsCorePayee = await Promise.all(eventsCorePayee.map(e => { + eventsCorePayee = await Promise.all(eventsCorePayee.map(e => { return new Promise(async (resolve, reject) => { - return resolve({requestId:e.returnValues.requestId, + return resolve({requestId:e.returnValues.requestId, _meta: { blockNumber:e.blockNumber, timestamp:await this.web3Single.getBlockTimestamp(e.blockNumber) @@ -257,9 +257,9 @@ export default class RequestCoreService { }); })); - eventsCorePayer = await Promise.all(eventsCorePayer.map(e => { + eventsCorePayer = await Promise.all(eventsCorePayer.map(e => { return new Promise(async (resolve, reject) => { - return resolve({requestId:e.returnValues.requestId, + return resolve({requestId:e.returnValues.requestId, _meta: { blockNumber:e.blockNumber, timestamp:await this.web3Single.getBlockTimestamp(e.blockNumber) @@ -269,7 +269,7 @@ export default class RequestCoreService { return resolve({asPayer : eventsCorePayer, asPayee : eventsCorePayee}); } catch(e) { - return reject(e); + return reject(e); } }); } diff --git a/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts b/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts index aeda2a4eec..e689933f95 100644 --- a/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts +++ b/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts @@ -43,7 +43,7 @@ export default class RequestSynchroneExtensionEscrowService { } let ret: any[] = []; - // parse escrow + // parse escrow ret.push(this.web3Single.toSolidityBytes32('address', _extensionParams[0])); for (let i = 1; i < 9; i++) { @@ -172,7 +172,7 @@ export default class RequestSynchroneExtensionEscrowService { } public getRequestExtensionInfo(_requestId: string): Promise < any > { - + return new Promise((resolve, reject) => { if (!this.web3Single.isHexStrictBytes32(_requestId)) return reject(Error('_requestId must be a 32 bytes hex string (eg.: \'0x0000000000000000000000000000000000000000000000000000000000000000\'')); @@ -196,8 +196,8 @@ export default class RequestSynchroneExtensionEscrowService { _fromBlock ?: number, _toBlock ?: number): Promise < any > { return this.requestCoreServices.getRequestHistory(_requestId,_fromBlock,_toBlock); - } - + } + public getRequestHistoryExtensionInfo( _requestId: string, _fromBlock ?: number, @@ -205,14 +205,14 @@ export default class RequestSynchroneExtensionEscrowService { return new Promise(async (resolve, reject) => { // let events = await this.instanceSynchroneExtensionEscrow.getPastEvents('allEvents', { // // allEvents and filter don't work together so far. issues created on web3 github - // // filter: {requestId: _requestId}, + // // filter: {requestId: _requestId}, // fromBlock: requestSynchroneExtensionEscrow_Artifact.networks[this.web3Single.networkName].blockNumber, // toBlock: 'latest' // }); // events by event waiting for a patch of web3 let optionFilters = { - filter: { requestId: _requestId }, + filter: { requestId: _requestId }, fromBlock: requestSynchroneExtensionEscrow_Artifact.networks[this.web3Single.networkName].blockNumber, toBlock: 'latest' }; @@ -222,7 +222,7 @@ export default class RequestSynchroneExtensionEscrowService { events = events.concat(await this.instanceSynchroneExtensionEscrow.getPastEvents('EscrowReleaseRequest', optionFilters)); events = events.concat(await this.instanceSynchroneExtensionEscrow.getPastEvents('EscrowRefundRequest', optionFilters)); - return resolve(await Promise.all(events.map(async e => { + return resolve(await Promise.all(events.map(async e => { return new Promise(async (resolve, reject) => { resolve({ _meta: { @@ -235,6 +235,6 @@ export default class RequestSynchroneExtensionEscrowService { }); }); }))); - }); - } + }); + } } \ No newline at end of file diff --git a/src/servicesExternal/ipfs-service.ts b/src/servicesExternal/ipfs-service.ts index 1188c2537c..b6ae05b24d 100644 --- a/src/servicesExternal/ipfs-service.ts +++ b/src/servicesExternal/ipfs-service.ts @@ -14,12 +14,12 @@ export default class Ipfs { this.ipfs = ipfsAPI(ipfsConfig.host, ipfsConfig.port, {protocol: ipfsConfig.protocol}) } - public static init(_publicIpfs : boolean = true) - { + public static init(_publicIpfs : boolean = true) + { this._instance = new this(_publicIpfs); } - public static getInstance() + public static getInstance() { return this._instance; } @@ -31,7 +31,7 @@ export default class Ipfs { return resolve(''); } let dataParsed = JSON.parse(_data); - + this.ipfs.add(Buffer.from(JSON.stringify(dataParsed)), (err:Error, result:any[]) => { if(err) return reject(err); return resolve(result[0].hash); diff --git a/src/servicesExternal/web3-single.ts b/src/servicesExternal/web3-single.ts index 96cc13266a..33e8c3f00e 100644 --- a/src/servicesExternal/web3-single.ts +++ b/src/servicesExternal/web3-single.ts @@ -20,16 +20,16 @@ export class Web3Single { this.networkName = networkId?Web3Single.getNetworkName(networkId):config.ethereum.default; } - public static init(web3Provider ? : any, networkId ? : number) - { + public static init(web3Provider ? : any, networkId ? : number) + { this._instance = new this(web3Provider,networkId); } - public static getInstance() + public static getInstance() { return this._instance; } - public static BN() + public static BN() { return Web3.utils.BN; } @@ -42,7 +42,7 @@ export class Web3Single { let options = Object.assign({}, _options || {}); ; options.numberOfConfirmation = undefined; - + if (!options.from) { try { let accounts = await this.web3.eth.getAccounts(); @@ -78,7 +78,7 @@ export class Web3Single { .on('transactionHash', _callbackTransactionHash) .on('receipt', _callbackTransactionReceipt) .on('confirmation', _callbackTransactionConfirmation) - .on('error', _callbackTransactionError); + .on('error', _callbackTransactionError); }); }); } @@ -153,7 +153,7 @@ export class Web3Single { } return false; }); - + if(log.topics[0] != signature) { return null; @@ -174,7 +174,7 @@ export class Web3Single { return this.web3.eth.abi.decodeLog(eventInput, event.raw.data, event.raw.topics.slice(1)); } - + public setUpOptions(_options:any) : any { if(!_options) _options = {}; @@ -210,17 +210,17 @@ export class Web3Single { public async getBlockTimestamp(_blockNumber:number) : Promise { return new Promise(async (resolve, reject) => { - try + try { if(!this.blockTimestamp[_blockNumber]) { let block = await this.web3.eth.getBlock(_blockNumber); if(!block) throw Error('block \''+_blockNumber+'\' not found'); - this.blockTimestamp[_blockNumber] = block.timestamp; + this.blockTimestamp[_blockNumber] = block.timestamp; } return resolve(this.blockTimestamp[_blockNumber]) } catch(e) - { + { console.warn(e); return resolve(null); } diff --git a/test/deploy.ts b/test/deploy.ts index 98e6d0ee44..fc115cc7a4 100644 --- a/test/deploy.ts +++ b/test/deploy.ts @@ -155,7 +155,7 @@ web3Single.getDefaultAccount().then(function(creator) { console.log(error) console.log('setFeesPerTenThousand - error ##########################') }); - + web3Single.broadcastMethod( newContractInstanceRequestCore.methods.setBurnManager(addressRequestBurnManagerSimple), (transactionHash: string) => { diff --git a/test/test.ts b/test/test.ts index 959d0a06de..b5d4b1ccc3 100644 --- a/test/test.ts +++ b/test/test.ts @@ -6,7 +6,7 @@ var rn = new RequestNetwork("http://localhost:8545",10000000000); async function foo() { try { - let result = await rn.requestEthereumService.createRequestAsPayee( + let result = await rn.requestEthereumService.createRequestAsPayee( '0xf17f52151ebef6c7334fad080c5704d77216b732', // 1 200000, // '{"reason":"wine purchased"}' @@ -14,7 +14,7 @@ async function foo() { console.log('createRequestAsPayee') console.log(result) - // result = await rn.requestEthereumService.createRequestAsPayee( + // result = await rn.requestEthereumService.createRequestAsPayee( // '0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e', // 1 // 200000, // '{"reason":"wine purchased"}', diff --git a/test/unit/accept.ts b/test/unit/accept.ts index 2402250d73..6978ea9aeb 100644 --- a/test/unit/accept.ts +++ b/test/unit/accept.ts @@ -36,11 +36,11 @@ describe('accept', () => { coreVersion = await rn.requestCoreService.getVersion(); currentNumRequest = await rn.requestCoreService.getCurrentNumRequest(); - let req = await rn.requestEthereumService.createRequestAsPayee( + let req = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '', - '', + '', [], {from: payee}); @@ -52,7 +52,7 @@ describe('accept', () => { let result = await rn.requestEthereumService.accept( '0x00000000000000', {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_requestId must be a 32 bytes hex string (eg.: \'0x0000000000000000000000000000000000000000000000000000000000000000\''),'exception not right'); } @@ -84,7 +84,7 @@ describe('accept', () => { let result = await rn.requestEthereumService.accept( requestId, {from: payee}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('account must be the payer'),'exception not right'); } @@ -93,7 +93,7 @@ describe('accept', () => { let result = await rn.requestEthereumService.accept( requestId, {from: otherGuy}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('account must be the payer'),'exception not right'); } @@ -109,7 +109,7 @@ describe('accept', () => { let result = await rn.requestEthereumService.accept( requestId, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('request state is not \'created\''),'exception not right'); } diff --git a/test/unit/cancel.ts b/test/unit/cancel.ts index 6b89170164..54eb234fad 100644 --- a/test/unit/cancel.ts +++ b/test/unit/cancel.ts @@ -37,11 +37,11 @@ describe('cancel', () => { coreVersion = await rn.requestCoreService.getVersion(); currentNumRequest = await rn.requestCoreService.getCurrentNumRequest(); - let req = await rn.requestEthereumService.createRequestAsPayee( + let req = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '', - '', + '', [], {from: payee}); @@ -53,7 +53,7 @@ describe('cancel', () => { let result = await rn.requestEthereumService.cancel( '0x00000000000000', {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_requestId must be a 32 bytes hex string (eg.: \'0x0000000000000000000000000000000000000000000000000000000000000000\''),'exception not right'); } @@ -85,7 +85,7 @@ describe('cancel', () => { let result = await rn.requestEthereumService.cancel( requestId, {from: otherGuy}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('account must be the payer or the payee'),'exception not right'); } @@ -100,7 +100,7 @@ describe('cancel', () => { let result = await rn.requestEthereumService.cancel( requestId, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('payer can cancel request in state \'created\''),'exception not right'); } @@ -115,7 +115,7 @@ describe('cancel', () => { let result = await rn.requestEthereumService.cancel( requestId, {from: payee}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('payee cannot cancel request already canceled'),'exception not right'); } @@ -127,7 +127,7 @@ describe('cancel', () => { {from: payee}); utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); - + utils.expectEqualsBN(result.request.balance,0,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); expect(result.request.extension, 'extension is wrong').to.be.undefined; @@ -157,7 +157,7 @@ describe('cancel', () => { }); utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); - + utils.expectEqualsBN(result.request.balance,0,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); expect(result.request.extension, 'extension is wrong').to.be.undefined; @@ -186,7 +186,7 @@ describe('cancel', () => { let result = await rn.requestEthereumService.cancel( requestId, {from: payee}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('impossible to cancel a Request with a balance != 0'),'exception not right'); } diff --git a/test/unit/createRequestAsPayee.ts b/test/unit/createRequestAsPayee.ts index 4a8a10ab4a..1a64007dff 100644 --- a/test/unit/createRequestAsPayee.ts +++ b/test/unit/createRequestAsPayee.ts @@ -36,11 +36,11 @@ describe('createRequestAsPayee', () => { }) it('create request without extension', async () => { - let result = await rn.requestEthereumService.createRequestAsPayee( + let result = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '{"reason":"weed purchased"}', - '', + '', [], {from: payee}) .on('broadcasted', (data:any) => { @@ -63,16 +63,16 @@ describe('createRequestAsPayee', () => { }); it('create request without extension (implicit parameters)', async () => { - let result = await rn.requestEthereumService.createRequestAsPayee( + let result = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount) .on('broadcasted', (data:any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); - expect(result).to.have.property('transactionHash'); + expect(result).to.have.property('transactionHash'); utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); - + utils.expectEqualsBN(result.request.balance,0,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(defaultAccount); expect(result.request.extension, 'extension is wrong').to.be.undefined; @@ -86,66 +86,66 @@ describe('createRequestAsPayee', () => { }); it('create request _payer not address', async () => { - try { - let result = await rn.requestEthereumService.createRequestAsPayee( + try { + let result = await rn.requestEthereumService.createRequestAsPayee( '0xNOTADDRESS', arbitraryAmount); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_payer must be a valid eth address'),'exception not right'); } }); it('create request payer == payee', async () => { - try { - let result = await rn.requestEthereumService.createRequestAsPayee( + try { + let result = await rn.requestEthereumService.createRequestAsPayee( defaultAccount, arbitraryAmount); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_payer must be a valid eth address'),'exception not right'); } }); it('create request amount < 0', async () => { - try { - let result = await rn.requestEthereumService.createRequestAsPayee( + try { + let result = await rn.requestEthereumService.createRequestAsPayee( payer, new Web3.utils.BN(-1)); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_expectedAmount must a positive integer'),'exception not right'); } }); it('create request _extension not address', async () => { - try { - let result = await rn.requestEthereumService.createRequestAsPayee( + try { + let result = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '', '0xNOTADDRESS'); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_extension must be a valid eth address'),'exception not right'); } }); it('create request _extension not handled', async () => { - try { - let result = await rn.requestEthereumService.createRequestAsPayee( + try { + let result = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '', addressRequestEthereum); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_extension is not supported'),'exception not right'); } }); it('create request with _extension handled', async () => { - let result = await rn.requestEthereumService.createRequestAsPayee( + let result = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '', @@ -155,10 +155,10 @@ describe('createRequestAsPayee', () => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); - expect(result).to.have.property('transactionHash'); + expect(result).to.have.property('transactionHash'); utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); - + utils.expectEqualsBN(result.request.balance,0,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(defaultAccount); expect(result.request.payee.toLowerCase(), 'payee is wrong').to.equal(defaultAccount); diff --git a/test/unit/paymentAction.ts b/test/unit/paymentAction.ts index 71eb8b59b0..8e4c64548f 100644 --- a/test/unit/paymentAction.ts +++ b/test/unit/paymentAction.ts @@ -36,11 +36,11 @@ describe('paymentAction', () => { coreVersion = await rn.requestCoreService.getVersion(); currentNumRequest = await rn.requestCoreService.getCurrentNumRequest(); - let req = await rn.requestEthereumService.createRequestAsPayee( + let req = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '', - '', + '', [], {from: payee}); @@ -62,7 +62,7 @@ describe('paymentAction', () => { }); utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); - + utils.expectEqualsBN(result.request.balance,arbitraryAmount,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); expect(result.request.extension, 'extension is wrong').to.be.undefined; @@ -85,7 +85,7 @@ describe('paymentAction', () => { arbitraryAmount, 10, {from: payer}); - + utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount+10,'expectedAmount is wrong'); utils.expectEqualsBN(result.request.balance,arbitraryAmount,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); @@ -110,7 +110,7 @@ describe('paymentAction', () => { arbitraryAmount, 0, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_requestId must be a 32 bytes hex string (eg.: \'0x0000000000000000000000000000000000000000000000000000000000000000\''),'exception not right'); } @@ -127,7 +127,7 @@ describe('paymentAction', () => { arbitraryAmount, -1, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_additional must a positive integer'),'exception not right'); } @@ -144,7 +144,7 @@ describe('paymentAction', () => { -1, 0, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_amount must a positive integer'),'exception not right'); } @@ -161,7 +161,7 @@ describe('paymentAction', () => { arbitraryAmount, 0, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('request must be accepted'),'exception not right'); } @@ -176,7 +176,7 @@ describe('paymentAction', () => { .on('broadcasted', (data:any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); - + utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); utils.expectEqualsBN(result.request.balance,arbitraryAmount,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); @@ -204,7 +204,7 @@ describe('paymentAction', () => { .on('broadcasted', (data:any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); - + utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount+2,'expectedAmount is wrong'); utils.expectEqualsBN(result.request.balance,1,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); diff --git a/test/unit/refundAction.ts b/test/unit/refundAction.ts index 879f4c2266..fa03bfaa03 100644 --- a/test/unit/refundAction.ts +++ b/test/unit/refundAction.ts @@ -37,11 +37,11 @@ describe('refundAction', () => { coreVersion = await rn.requestCoreService.getVersion(); currentNumRequest = await rn.requestCoreService.getCurrentNumRequest(); - let req = await rn.requestEthereumService.createRequestAsPayee( + let req = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount, '', - '', + '', [], {from: payee}); @@ -68,7 +68,7 @@ describe('refundAction', () => { }); utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); - + utils.expectEqualsBN(result.request.balance,0,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); expect(result.request.extension, 'extension is wrong').to.be.undefined; @@ -101,7 +101,7 @@ describe('refundAction', () => { }); utils.expectEqualsBN(result.request.expectedAmount,arbitraryAmount,'expectedAmount is wrong'); - + utils.expectEqualsBN(result.request.balance,arbitraryAmount-10,'balance is wrong'); expect(result.request.creator.toLowerCase(), 'creator is wrong').to.equal(payee); expect(result.request.extension, 'extension is wrong').to.be.undefined; @@ -129,7 +129,7 @@ describe('refundAction', () => { '0x00000000000000', arbitraryAmount, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_requestId must be a 32 bytes hex string (eg.: \'0x0000000000000000000000000000000000000000000000000000000000000000\''),'exception not right'); } @@ -151,7 +151,7 @@ describe('refundAction', () => { requestId, -1, {from: payee}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('_amount must a positive integer'),'exception not right'); } @@ -173,7 +173,7 @@ describe('refundAction', () => { requestId, arbitraryAmount, {from: payer}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('account must be payee'),'exception not right'); } @@ -195,7 +195,7 @@ describe('refundAction', () => { requestId, arbitraryAmount, {from: otherGuy}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('account must be payee'),'exception not right'); } @@ -218,7 +218,7 @@ describe('refundAction', () => { requestId, 11, {from: otherGuy}); - expect(false,'exception not thrown').to.be.true; + expect(false,'exception not thrown').to.be.true; } catch(e) { utils.expectEqualsObject(e,Error('You cannot payback more than what has been paid'),'exception not right'); } diff --git a/test/utils.ts b/test/utils.ts index 89754e1679..abf662eded 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -15,5 +15,5 @@ export const expectEqualsObject = function(obj1:any,obj2:any,msg:string) : void } export const expectEqualsBN = function(obj1:any,obj2:any,msg:string) : void { - expect(new BN(obj1).eq(new BN(obj2)), msg).to.be.true; + expect(new BN(obj1).eq(new BN(obj2)), msg).to.be.true; } \ No newline at end of file diff --git a/tslint.json b/tslint.json index 61a8a4789a..0aced966c6 100644 --- a/tslint.json +++ b/tslint.json @@ -19,7 +19,6 @@ "no-consecutive-blank-lines": false, "no-console": false, "no-shadowed-variable": false, - "no-trailing-whitespace": false, "no-unused-expression": false, "no-var-keyword": false, "no-var-requires": false, From acd95b66ecc94034e6f158a3202ab7f6cdec000b Mon Sep 17 00:00:00 2001 From: quentin Date: Tue, 19 Dec 2017 18:11:58 +0100 Subject: [PATCH 3/4] feat(lint): enable typedef-whitespace rule --- src/requestNetwork.ts | 2 +- src/servicesContracts.ts | 6 ++--- .../requestEthereum-service.ts | 24 +++++++++---------- src/servicesCore/requestCore-service.ts | 6 ++--- src/servicesExtensions.ts | 6 ++--- ...requestSynchroneExtensionEscrow-service.ts | 6 ++--- src/servicesExternal/ipfs-service.ts | 18 +++++++------- src/servicesExternal/web3-single.ts | 18 +++++++------- src/types.ts | 16 ++++++------- test/unit/accept.ts | 2 +- test/unit/cancel.ts | 6 ++--- test/unit/createRequestAsPayee.ts | 6 ++--- test/unit/paymentAction.ts | 8 +++---- test/unit/refundAction.ts | 4 ++-- test/utils.ts | 6 ++--- tslint.json | 1 - 16 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/requestNetwork.ts b/src/requestNetwork.ts index 1f4531ab16..41a7fcef61 100644 --- a/src/requestNetwork.ts +++ b/src/requestNetwork.ts @@ -15,7 +15,7 @@ export default class RequestNetwork { public requestSynchroneExtensionEscrowService: RequestSynchroneExtensionEscrowService; public requestCoreService: RequestCoreService; - constructor(provider? : any, networkId ? : number, useIpfsPublic : boolean = true) { + constructor(provider?: any, networkId ?: number, useIpfsPublic: boolean = true) { if(provider && !networkId) { throw Error('if you give provider you have to give the networkId too'); diff --git a/src/servicesContracts.ts b/src/servicesContracts.ts index 86c5a8d0d0..0262445ab2 100644 --- a/src/servicesContracts.ts +++ b/src/servicesContracts.ts @@ -2,7 +2,7 @@ import Artifacts from './artifacts'; import RequestEthereumService from './servicesContracts/requestEthereum-service'; -export const getServiceFromAddress = function(address:string) : any{ +export const getServiceFromAddress = function(address: string): any{ if(!address) return undefined; if(isThisArtifact(Artifacts.RequestEthereumArtifact, address)) { @@ -12,9 +12,9 @@ export const getServiceFromAddress = function(address:string) : any{ } } -const isThisArtifact = function(artifact:any,address:string) : boolean { +const isThisArtifact = function(artifact: any,address: string): boolean { if(!address) return false; - let found:boolean = false; + let found: boolean = false; Object.keys(artifact.networks).forEach(function(k) { found = found || (artifact.networks[k].address && artifact.networks[k].address.toLowerCase() == address.toLowerCase()); }) diff --git a/src/servicesContracts/requestEthereum-service.ts b/src/servicesContracts/requestEthereum-service.ts index 0ca326bdd8..ae5e693261 100644 --- a/src/servicesContracts/requestEthereum-service.ts +++ b/src/servicesContracts/requestEthereum-service.ts @@ -21,7 +21,7 @@ export default class RequestEthereumService { // RequestEthereum on blockchain protected abiRequestCore: any; - protected requestCoreServices:any; + protected requestCoreServices: any; protected abiRequestEthereum: any; protected addressRequestEthereum: string; @@ -47,10 +47,10 @@ export default class RequestEthereumService { public createRequestAsPayee ( _payer: string, _amountInitial: any, - _data ? : string, - _extension ? : string, - _extensionParams ? : Array < any > , - _options ? : any, + _data ?: string, + _extension ?: string, + _extensionParams ?: Array < any > , + _options ?: any, ): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _amountInitial = new BN(_amountInitial); @@ -121,7 +121,7 @@ export default class RequestEthereumService { public accept( _requestId: string, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); @@ -167,7 +167,7 @@ export default class RequestEthereumService { public cancel( _requestId: string, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); @@ -222,7 +222,7 @@ export default class RequestEthereumService { _requestId: string, _amount: any, _additionals: any, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _additionals = new BN(_additionals); @@ -272,7 +272,7 @@ export default class RequestEthereumService { public refundAction( _requestId: string, _amount: any, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); _options.value = new BN(_amount); @@ -322,7 +322,7 @@ export default class RequestEthereumService { public subtractAction( _requestId: string, _amount: any, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); _amount = new BN(_amount); @@ -375,7 +375,7 @@ export default class RequestEthereumService { public additionalAction( _requestId: string, _amount: any, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); _amount = new BN(_amount); @@ -426,7 +426,7 @@ export default class RequestEthereumService { - public withdraw(_options ? : any): Web3PromiEvent { + public withdraw(_options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); diff --git a/src/servicesCore/requestCore-service.ts b/src/servicesCore/requestCore-service.ts index 36e0e31592..c0d3e55431 100644 --- a/src/servicesCore/requestCore-service.ts +++ b/src/servicesCore/requestCore-service.ts @@ -50,9 +50,9 @@ export default class RequestCoreService { } public getCollectEstimation( - _expectedAmount:any, - _currencyContract:string, - _extension:string): Promise < any > { + _expectedAmount: any, + _currencyContract: string, + _extension: string): Promise < any > { _expectedAmount = new BN(_expectedAmount); return new Promise((resolve, reject) => { diff --git a/src/servicesExtensions.ts b/src/servicesExtensions.ts index 6cd080663d..4cf101754f 100644 --- a/src/servicesExtensions.ts +++ b/src/servicesExtensions.ts @@ -2,7 +2,7 @@ import Artifacts from './artifacts'; import RequestSynchroneExtensionEscrowService from './servicesExtensions/requestSynchroneExtensionEscrow-service'; -export const getServiceFromAddress = function(address:string) : any{ +export const getServiceFromAddress = function(address: string): any{ if(!address) return undefined; if(isThisArtifact(Artifacts.RequestSynchroneExtensionEscrowArtifact, address)) { @@ -12,9 +12,9 @@ export const getServiceFromAddress = function(address:string) : any{ } } -const isThisArtifact = function(artifact:any,address:string) : boolean { +const isThisArtifact = function(artifact: any,address: string): boolean { if(!address) return false; - let found:boolean = false; + let found: boolean = false; Object.keys(artifact.networks).forEach(function(k) { found = found || (artifact.networks[k].address && artifact.networks[k].address.toLowerCase() == address.toLowerCase()); }) diff --git a/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts b/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts index e689933f95..806a41488d 100644 --- a/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts +++ b/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts @@ -17,7 +17,7 @@ export default class RequestSynchroneExtensionEscrowService { // RequestEthereum on blockchain protected abiRequestCore: any; - protected requestCoreServices:any; + protected requestCoreServices: any; protected abiSynchroneExtensionEscrow: any; protected addressSynchroneExtensionEscrow: string; @@ -54,7 +54,7 @@ export default class RequestSynchroneExtensionEscrowService { public releaseToPayeeAction( _requestId: string, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); @@ -112,7 +112,7 @@ export default class RequestSynchroneExtensionEscrowService { public releaseToPayerAction( _requestId: string, - _options ? : any): Web3PromiEvent { + _options ?: any): Web3PromiEvent { let promiEvent = Web3PromiEvent(); _options = this.web3Single.setUpOptions(_options); diff --git a/src/servicesExternal/ipfs-service.ts b/src/servicesExternal/ipfs-service.ts index b6ae05b24d..a5831c42cc 100644 --- a/src/servicesExternal/ipfs-service.ts +++ b/src/servicesExternal/ipfs-service.ts @@ -5,16 +5,16 @@ import ipfsAPI = require('ipfs-api'); export default class Ipfs { - private static _instance:Ipfs; + private static _instance: Ipfs; public ipfs: any; - private constructor(_publicIpfs : boolean) { + private constructor(_publicIpfs: boolean) { let ipfsConfig = config.ipfs.nodeUrlDefault[_publicIpfs?'public':'private']; this.ipfs = ipfsAPI(ipfsConfig.host, ipfsConfig.port, {protocol: ipfsConfig.protocol}) } - public static init(_publicIpfs : boolean = true) + public static init(_publicIpfs: boolean = true) { this._instance = new this(_publicIpfs); } @@ -24,7 +24,7 @@ export default class Ipfs { return this._instance; } - public addFile(_data:string) : Promise + public addFile(_data: string): Promise { return new Promise((resolve, reject) => { if(!_data || _data == '') { @@ -32,24 +32,24 @@ export default class Ipfs { } let dataParsed = JSON.parse(_data); - this.ipfs.add(Buffer.from(JSON.stringify(dataParsed)), (err:Error, result:any[]) => { + this.ipfs.add(Buffer.from(JSON.stringify(dataParsed)), (err: Error, result: any[]) => { if(err) return reject(err); return resolve(result[0].hash); }); }); } - public getFile(_hash:string) : Promise + public getFile(_hash: string): Promise { return new Promise((resolve, reject) => { if(!_hash || _hash == '') { return resolve(); } let data = ''; - this.ipfs.cat(_hash, (err:Error, stream:any) => { + this.ipfs.cat(_hash, (err: Error, stream: any) => { if(err) return reject(err); - stream.on('data', function(chunk:string) { + stream.on('data', function(chunk: string) { data += chunk; }); @@ -57,7 +57,7 @@ export default class Ipfs { return resolve(data); }); - stream.on('error',function(err:Error){ + stream.on('error',function(err: Error){ return reject(err); }); }); diff --git a/src/servicesExternal/web3-single.ts b/src/servicesExternal/web3-single.ts index 33e8c3f00e..0c62a115fa 100644 --- a/src/servicesExternal/web3-single.ts +++ b/src/servicesExternal/web3-single.ts @@ -15,12 +15,12 @@ export class Web3Single { protected blockTimestamp: any = {}; - private constructor(web3Provider ? : any, networkId ? : number) { + private constructor(web3Provider ?: any, networkId ?: number) { this.web3 = new Web3(web3Provider ||  new Web3.providers.HttpProvider(config.ethereum.nodeUrlDefault[config.ethereum.default])); this.networkName = networkId?Web3Single.getNetworkName(networkId):config.ethereum.default; } - public static init(web3Provider ? : any, networkId ? : number) + public static init(web3Provider ?: any, networkId ?: number) { this._instance = new this(web3Provider,networkId); } @@ -38,7 +38,7 @@ export class Web3Single { _callbackTransactionReceipt: Types.CallbackTransactionReceipt, _callbackTransactionConfirmation: Types.CallbackTransactionConfirmation, _callbackTransactionError: Types.CallbackTransactionError, - _options?:any) { + _options?: any) { let options = Object.assign({}, _options || {}); ; options.numberOfConfirmation = undefined; @@ -103,7 +103,7 @@ export class Web3Single { }); } - public getDefaultAccountCallback(callback:Types.CallbackErrorData): void { + public getDefaultAccountCallback(callback: Types.CallbackErrorData): void { this.web3.eth.getAccounts((err, accs) => { if (err) return callback(err,null); if (accs.length === 0) return callback(Error('No accounts found'),null); @@ -175,7 +175,7 @@ export class Web3Single { return this.web3.eth.abi.decodeLog(eventInput, event.raw.data, event.raw.topics.slice(1)); } - public setUpOptions(_options:any) : any + public setUpOptions(_options: any): any { if(!_options) _options = {}; if(!_options.numberOfConfirmation) _options.numberOfConfirmation = 0; @@ -184,7 +184,7 @@ export class Web3Single { return _options; } - public static getNetworkName(networkId:number) : string + public static getNetworkName(networkId: number): string { switch (networkId) { case 1: return 'main'; @@ -196,18 +196,18 @@ export class Web3Single { } } - public async getTransactionReceipt(_hash:string) : Promise + public async getTransactionReceipt(_hash: string): Promise { return this.web3.eth.getTransactionReceipt(_hash); } - public async getTransaction(_hash:string) : Promise + public async getTransaction(_hash: string): Promise { return this.web3.eth.getTransaction(_hash); } - public async getBlockTimestamp(_blockNumber:number) : Promise + public async getBlockTimestamp(_blockNumber: number): Promise { return new Promise(async (resolve, reject) => { try diff --git a/src/types.ts b/src/types.ts index 76080367a0..05d7af02f2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,17 +1,17 @@ export enum State { Created, Accepted, Canceled } export enum EscrowState { Created, Refunded, Released } -export type CallbackTransactionHash = (transactionHash:string) => void; -export type CallbackTransactionReceipt = (receipt:any) => void; -export type CallbackTransactionConfirmation = (confirmationNumber:number, receipt:any) => void; -export type CallbackTransactionError = (error:Error) => void; +export type CallbackTransactionHash = (transactionHash: string) => void; +export type CallbackTransactionReceipt = (receipt: any) => void; +export type CallbackTransactionConfirmation = (confirmationNumber: number, receipt: any) => void; +export type CallbackTransactionError = (error: Error) => void; -export type CallbackGetRequest = (err:Error, request:any) => void; +export type CallbackGetRequest = (err: Error, request: any) => void; -export type CallbackIpfsAddFile = (err:Error, hash:string) => void; -export type CallbackIpfsGetFile = (err:Error, data:string) => void; +export type CallbackIpfsAddFile = (err: Error, hash: string) => void; +export type CallbackIpfsGetFile = (err: Error, data: string) => void; -export type CallbackErrorData = (err:Error, data:string) => void; +export type CallbackErrorData = (err: Error, data: string) => void; export interface Artifact { abi: any; diff --git a/test/unit/accept.ts b/test/unit/accept.ts index 6978ea9aeb..9646f1400c 100644 --- a/test/unit/accept.ts +++ b/test/unit/accept.ts @@ -62,7 +62,7 @@ describe('accept', () => { let result = await rn.requestEthereumService.accept( requestId, {from: payer}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); diff --git a/test/unit/cancel.ts b/test/unit/cancel.ts index 54eb234fad..175f5aa19b 100644 --- a/test/unit/cancel.ts +++ b/test/unit/cancel.ts @@ -63,7 +63,7 @@ describe('cancel', () => { let result = await rn.requestEthereumService.cancel( requestId, {from: payer}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); @@ -145,14 +145,14 @@ describe('cancel', () => { await rn.requestEthereumService.accept( requestId, {from: payer}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); let result = await rn.requestEthereumService.cancel( requestId, {from: payee}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); diff --git a/test/unit/createRequestAsPayee.ts b/test/unit/createRequestAsPayee.ts index 1a64007dff..c1ffd1d949 100644 --- a/test/unit/createRequestAsPayee.ts +++ b/test/unit/createRequestAsPayee.ts @@ -43,7 +43,7 @@ describe('createRequestAsPayee', () => { '', [], {from: payee}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); @@ -66,7 +66,7 @@ describe('createRequestAsPayee', () => { let result = await rn.requestEthereumService.createRequestAsPayee( payer, arbitraryAmount) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); expect(result).to.have.property('transactionHash'); @@ -151,7 +151,7 @@ describe('createRequestAsPayee', () => { '', addressSynchroneExtensionEscrow, [otherGuy]) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); diff --git a/test/unit/paymentAction.ts b/test/unit/paymentAction.ts index 8e4c64548f..ee851c46ae 100644 --- a/test/unit/paymentAction.ts +++ b/test/unit/paymentAction.ts @@ -57,7 +57,7 @@ describe('paymentAction', () => { arbitraryAmount, 0, {from: payer}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); @@ -173,7 +173,7 @@ describe('paymentAction', () => { arbitraryAmount, 0, {from: payer}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); @@ -201,7 +201,7 @@ describe('paymentAction', () => { 1, 2, {from: payer}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); @@ -228,7 +228,7 @@ describe('paymentAction', () => { arbitraryAmount+1, 0, {from: payer}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); diff --git a/test/unit/refundAction.ts b/test/unit/refundAction.ts index fa03bfaa03..1650026929 100644 --- a/test/unit/refundAction.ts +++ b/test/unit/refundAction.ts @@ -63,7 +63,7 @@ describe('refundAction', () => { requestId, arbitraryAmount, {from: payee}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); @@ -96,7 +96,7 @@ describe('refundAction', () => { requestId, 10, {from: payee}) - .on('broadcasted', (data:any) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); diff --git a/test/utils.ts b/test/utils.ts index abf662eded..7fe0ece127 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -6,14 +6,14 @@ var ethUtil = require('ethereumjs-util'); var Web3 = require('web3'); const BN = Web3.utils.BN; -export const getHashRequest = function(coreVersion,num) : string { +export const getHashRequest = function(coreVersion,num): string { return ethUtil.bufferToHex(ethABI.soliditySHA3(["uint256","uint32"], [num,coreVersion])); } -export const expectEqualsObject = function(obj1:any,obj2:any,msg:string) : void { +export const expectEqualsObject = function(obj1: any,obj2: any,msg: string): void { expect(JSON.stringify(obj1),msg).to.be.equal(JSON.stringify(obj2)); } -export const expectEqualsBN = function(obj1:any,obj2:any,msg:string) : void { +export const expectEqualsBN = function(obj1: any,obj2: any,msg: string): void { expect(new BN(obj1).eq(new BN(obj2)), msg).to.be.true; } \ No newline at end of file diff --git a/tslint.json b/tslint.json index 0aced966c6..c672a38975 100644 --- a/tslint.json +++ b/tslint.json @@ -34,7 +34,6 @@ "space-before-function-paren": false, "trailing-comma": false, "triple-equals": false, - "typedef-whitespace": false, "variable-name": false, "whitespace": false }, From 86a85f092c14afbd6e299a83e2521da3df237354 Mon Sep 17 00:00:00 2001 From: quentin Date: Tue, 19 Dec 2017 18:13:01 +0100 Subject: [PATCH 4/4] feat(lint): enable eofline rule --- src/artifacts.ts | 2 +- src/config.ts | 2 +- src/requestNetwork.ts | 2 +- src/servicesContracts.ts | 2 +- src/servicesContracts/requestEthereum-service.ts | 2 +- src/servicesExtensions.ts | 2 +- .../requestSynchroneExtensionEscrow-service.ts | 2 +- src/servicesExternal/ipfs-service.ts | 2 +- src/servicesExternal/web3-single.ts | 2 +- test/utils.ts | 2 +- tslint.json | 1 - 11 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/artifacts.ts b/src/artifacts.ts index ca441e4f35..02a19414f0 100644 --- a/src/artifacts.ts +++ b/src/artifacts.ts @@ -8,4 +8,4 @@ export default { RequestCoreArtifact: RequestCoreArtifact as any as Artifact, RequestEthereumArtifact: RequestEthereumArtifact as any as Artifact, RequestSynchroneExtensionEscrowArtifact: RequestSynchroneExtensionEscrowArtifact as any as Artifact, -}; \ No newline at end of file +}; diff --git a/src/config.ts b/src/config.ts index 2ef4d07b67..9e5d971d2f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,3 +1,3 @@ // import * as Config from './config.json'; const Config = require('./config.json'); -export default Config; \ No newline at end of file +export default Config; diff --git a/src/requestNetwork.ts b/src/requestNetwork.ts index 41a7fcef61..41fbaac4ac 100644 --- a/src/requestNetwork.ts +++ b/src/requestNetwork.ts @@ -26,4 +26,4 @@ export default class RequestNetwork { this.requestEthereumService = new RequestEthereumService(); this.requestSynchroneExtensionEscrowService = new RequestSynchroneExtensionEscrowService(); } -} \ No newline at end of file +} diff --git a/src/servicesContracts.ts b/src/servicesContracts.ts index 0262445ab2..3dd87c630d 100644 --- a/src/servicesContracts.ts +++ b/src/servicesContracts.ts @@ -19,4 +19,4 @@ const isThisArtifact = function(artifact: any,address: string): boolean { found = found || (artifact.networks[k].address && artifact.networks[k].address.toLowerCase() == address.toLowerCase()); }) return found; -} \ No newline at end of file +} diff --git a/src/servicesContracts/requestEthereum-service.ts b/src/servicesContracts/requestEthereum-service.ts index ae5e693261..bce35e9743 100644 --- a/src/servicesContracts/requestEthereum-service.ts +++ b/src/servicesContracts/requestEthereum-service.ts @@ -515,4 +515,4 @@ export default class RequestEthereumService { }))); }); } -} \ No newline at end of file +} diff --git a/src/servicesExtensions.ts b/src/servicesExtensions.ts index 4cf101754f..ab6d7144f5 100644 --- a/src/servicesExtensions.ts +++ b/src/servicesExtensions.ts @@ -19,4 +19,4 @@ const isThisArtifact = function(artifact: any,address: string): boolean { found = found || (artifact.networks[k].address && artifact.networks[k].address.toLowerCase() == address.toLowerCase()); }) return found; -} \ No newline at end of file +} diff --git a/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts b/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts index 806a41488d..08b308e2ad 100644 --- a/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts +++ b/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts @@ -237,4 +237,4 @@ export default class RequestSynchroneExtensionEscrowService { }))); }); } -} \ No newline at end of file +} diff --git a/src/servicesExternal/ipfs-service.ts b/src/servicesExternal/ipfs-service.ts index a5831c42cc..6fb152cf72 100644 --- a/src/servicesExternal/ipfs-service.ts +++ b/src/servicesExternal/ipfs-service.ts @@ -63,4 +63,4 @@ export default class Ipfs { }); }); } -} \ No newline at end of file +} diff --git a/src/servicesExternal/web3-single.ts b/src/servicesExternal/web3-single.ts index 0c62a115fa..d5169656e9 100644 --- a/src/servicesExternal/web3-single.ts +++ b/src/servicesExternal/web3-single.ts @@ -228,4 +228,4 @@ export class Web3Single { } -} \ No newline at end of file +} diff --git a/test/utils.ts b/test/utils.ts index 7fe0ece127..0f38454139 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -16,4 +16,4 @@ export const expectEqualsObject = function(obj1: any,obj2: any,msg: string): voi export const expectEqualsBN = function(obj1: any,obj2: any,msg: string): void { expect(new BN(obj1).eq(new BN(obj2)), msg).to.be.true; -} \ No newline at end of file +} diff --git a/tslint.json b/tslint.json index c672a38975..b5ad1b76b7 100644 --- a/tslint.json +++ b/tslint.json @@ -11,7 +11,6 @@ "arrow-return-shorthand": false, "comment-format": false, "curly": false, - "eofline": false, "indent": false, "interface-name": false, "max-line-length": false,