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/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 b451a900c7..41fbaac4ac 100644 --- a/src/requestNetwork.ts +++ b/src/requestNetwork.ts @@ -14,8 +14,8 @@ export default class RequestNetwork { public requestEthereumService: RequestEthereumService; 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'); @@ -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 86c5a8d0d0..3dd87c630d 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,11 +12,11 @@ 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()); }) return found; -} \ No newline at end of file +} diff --git a/src/servicesContracts/requestEthereum-service.ts b/src/servicesContracts/requestEthereum-service.ts index 83ae4feee5..bce35e9743 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); @@ -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) => { @@ -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); @@ -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')); } @@ -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); @@ -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..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) => { @@ -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.ts b/src/servicesExtensions.ts index 6cd080663d..ab6d7144f5 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,11 +12,11 @@ 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()); }) return found; -} \ No newline at end of file +} diff --git a/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts b/src/servicesExtensions/requestSynchroneExtensionEscrow-service.ts index aeda2a4eec..08b308e2ad 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; @@ -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++) { @@ -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); @@ -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..6fb152cf72 100644 --- a/src/servicesExternal/ipfs-service.ts +++ b/src/servicesExternal/ipfs-service.ts @@ -5,51 +5,51 @@ 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); } - public static getInstance() + public static getInstance() { return this._instance; } - public addFile(_data:string) : Promise + public addFile(_data: string): Promise { return new Promise((resolve, reject) => { if(!_data || _data == '') { return resolve(''); } 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,10 +57,10 @@ export default class Ipfs { return resolve(data); }); - stream.on('error',function(err:Error){ + stream.on('error',function(err: Error){ return reject(err); }); }); }); } -} \ No newline at end of file +} diff --git a/src/servicesExternal/web3-single.ts b/src/servicesExternal/web3-single.ts index 96cc13266a..d5169656e9 100644 --- a/src/servicesExternal/web3-single.ts +++ b/src/servicesExternal/web3-single.ts @@ -15,21 +15,21 @@ 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); } - public static getInstance() + public static getInstance() { return this._instance; } - public static BN() + public static BN() { return Web3.utils.BN; } @@ -38,11 +38,11 @@ export class Web3Single { _callbackTransactionReceipt: Types.CallbackTransactionReceipt, _callbackTransactionConfirmation: Types.CallbackTransactionConfirmation, _callbackTransactionError: Types.CallbackTransactionError, - _options?:any) { + _options?: any) { 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); }); }); } @@ -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); @@ -153,7 +153,7 @@ export class Web3Single { } return false; }); - + if(log.topics[0] != signature) { return null; @@ -174,8 +174,8 @@ 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,31 +196,31 @@ 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 + 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); } @@ -228,4 +228,4 @@ export class Web3Single { } -} \ No newline at end of file +} 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/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..9646f1400c 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'); } @@ -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'); }); @@ -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..175f5aa19b 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'); } @@ -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'); }); @@ -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; @@ -145,19 +145,19 @@ 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'); }); 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..c1ffd1d949 100644 --- a/test/unit/createRequestAsPayee.ts +++ b/test/unit/createRequestAsPayee.ts @@ -36,14 +36,14 @@ 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) => { + .on('broadcasted', (data: any) => { expect(data, 'data.transactionHash is wrong').to.have.property('transactionHash'); }); @@ -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) => { + .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,79 +86,79 @@ 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, '', addressSynchroneExtensionEscrow, [otherGuy]) - .on('broadcasted', (data:any) => { + .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.payee.toLowerCase(), 'payee is wrong').to.equal(defaultAccount); diff --git a/test/unit/paymentAction.ts b/test/unit/paymentAction.ts index 71eb8b59b0..ee851c46ae 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}); @@ -57,12 +57,12 @@ describe('paymentAction', () => { arbitraryAmount, 0, {from: payer}) - .on('broadcasted', (data:any) => { + .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); 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'); } @@ -173,10 +173,10 @@ describe('paymentAction', () => { arbitraryAmount, 0, {from: payer}) - .on('broadcasted', (data:any) => { + .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); @@ -201,10 +201,10 @@ describe('paymentAction', () => { 1, 2, {from: payer}) - .on('broadcasted', (data:any) => { + .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); @@ -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 879f4c2266..1650026929 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}); @@ -63,12 +63,12 @@ describe('refundAction', () => { requestId, arbitraryAmount, {from: payee}) - .on('broadcasted', (data:any) => { + .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,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; @@ -96,12 +96,12 @@ describe('refundAction', () => { requestId, 10, {from: payee}) - .on('broadcasted', (data:any) => { + .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-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..0f38454139 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 { - expect(new BN(obj1).eq(new BN(obj2)), msg).to.be.true; -} \ No newline at end of file +export const expectEqualsBN = function(obj1: any,obj2: any,msg: string): void { + expect(new BN(obj1).eq(new BN(obj2)), msg).to.be.true; +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000000..b5ad1b76b7 --- /dev/null +++ b/tslint.json @@ -0,0 +1,40 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "align": false, + "array-type": false, + "arrow-parens": false, + "arrow-return-shorthand": false, + "comment-format": false, + "curly": 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-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, + "variable-name": false, + "whitespace": false + }, + "rulesDirectory": [] +}