1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

formatting updates for new prettier rules

This commit is contained in:
Matthias Kretschmann 2020-05-19 16:15:56 +02:00
parent 1c884bcf09
commit 8ece01d9fa
Signed by: m
GPG Key ID: 606EEEF3C479A91F
31 changed files with 104 additions and 106 deletions

View File

@ -9,9 +9,7 @@ process.stdout.write(
JSON.stringify( JSON.stringify(
{ {
version: require('../package.json').version, version: require('../package.json').version,
commit: execSync(`git rev-parse HEAD`) commit: execSync(`git rev-parse HEAD`).toString().trim()
.toString()
.trim()
}, },
null, null,
' ' ' '

View File

@ -64,7 +64,7 @@ export class Aquarius {
this.logger.error('Success accessing consume endpoint: ', consumptionUrl) this.logger.error('Success accessing consume endpoint: ', consumptionUrl)
return consumptionUrl return consumptionUrl
}) })
.catch(error => { .catch((error) => {
this.logger.error( this.logger.error(
'Error fetching the data asset consumption url: ', 'Error fetching the data asset consumption url: ',
error error
@ -94,10 +94,10 @@ export class Aquarius {
) )
return this.transformResult() return this.transformResult()
}) })
.then(results => { .then((results) => {
return this.transformResult(results) return this.transformResult(results)
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error fetching querying metadata: ', error) this.logger.error('Error fetching querying metadata: ', error)
return this.transformResult() return this.transformResult()
}) })
@ -133,10 +133,10 @@ export class Aquarius {
) )
return this.transformResult() return this.transformResult()
}) })
.then(results => { .then((results) => {
return this.transformResult(results) return this.transformResult(results)
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error fetching querying metadata by text: ', error) this.logger.error('Error fetching querying metadata by text: ', error)
return this.transformResult() return this.transformResult()
}) })
@ -168,7 +168,7 @@ export class Aquarius {
.then((response: DDO) => { .then((response: DDO) => {
return new DDO(response) as DDO return new DDO(response) as DDO
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error fetching querying metadata: ', error) this.logger.error('Error fetching querying metadata: ', error)
return null as DDO return null as DDO
}) })
@ -204,7 +204,7 @@ export class Aquarius {
.then((response: DDO) => { .then((response: DDO) => {
return new DDO(response) as DDO return new DDO(response) as DDO
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error fetching querying metadata: ', error) this.logger.error('Error fetching querying metadata: ', error)
return null as DDO return null as DDO
}) })
@ -253,7 +253,7 @@ export class Aquarius {
return null return null
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error transfering ownership metadata: ', error) this.logger.error('Error transfering ownership metadata: ', error)
return null return null
}) })
@ -307,7 +307,7 @@ export class Aquarius {
return null return null
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error updating compute privacy: ', error) this.logger.error('Error updating compute privacy: ', error)
return null return null
}) })
@ -353,7 +353,7 @@ export class Aquarius {
return null return null
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error transfering ownership metadata: ', error) this.logger.error('Error transfering ownership metadata: ', error)
return null return null
}) })
@ -391,7 +391,7 @@ export class Aquarius {
return null return null
}) })
.catch(error => { .catch((error) => {
this.logger.error('Error transfering ownership metadata: ', error) this.logger.error('Error transfering ownership metadata: ', error)
return null return null
}) })
@ -412,7 +412,7 @@ export class Aquarius {
} }
): QueryResult { ): QueryResult {
return { return {
results: (results || []).map(ddo => new DDO(ddo as DDO)), results: (results || []).map((ddo) => new DDO(ddo as DDO)),
page, page,
totalPages, totalPages,
totalResults totalResults

View File

@ -71,7 +71,7 @@ export class DDO {
throw new Error('index is not set') throw new Error('index is not set')
} }
const service = this.service.find(s => s.index === index) const service = this.service.find((s) => s.index === index)
return service as Service<T> return service as Service<T>
} }
@ -86,7 +86,7 @@ export class DDO {
throw new Error('serviceType not set') throw new Error('serviceType not set')
} }
return this.service.find(s => s.type === serviceType) as Service<T> return this.service.find((s) => s.type === serviceType) as Service<T>
} }
/** /**
@ -98,7 +98,7 @@ export class DDO {
const { files, name, author, license } = attributes.main const { files, name, author, license } = attributes.main
const values = [ const values = [
...(files || []).map(({ checksum }) => checksum).filter(_ => !!_), ...(files || []).map(({ checksum }) => checksum).filter((_) => !!_),
name, name,
author, author,
license, license,

View File

@ -36,8 +36,8 @@ export class ContractEvent {
} }
public once(callback?: (events: any[]) => void) { public once(callback?: (events: any[]) => void) {
return new Promise(resolve => { return new Promise((resolve) => {
const subscription = this.subscribe(events => { const subscription = this.subscribe((events) => {
subscription.unsubscribe() subscription.unsubscribe()
if (callback) { if (callback) {
callback(events) callback(events)

View File

@ -62,7 +62,7 @@ export class EventHandler extends Instantiable {
} }
if (this.lastBlock !== blockNumber) { if (this.lastBlock !== blockNumber) {
this.events.forEach(fn => fn(this.lastBlock + 1)) this.events.forEach((fn) => fn(this.lastBlock + 1))
this.lastBlock = blockNumber this.lastBlock = blockNumber
} }
this.lastTimeout = global.setTimeout( this.lastTimeout = global.setTimeout(

View File

@ -192,7 +192,7 @@ export class Keeper extends Instantiable {
*/ */
public getConditionByAddress(address: string): Condition { public getConditionByAddress(address: string): Condition {
return Object.values(this.conditions).find( return Object.values(this.conditions).find(
condition => condition.getAddress() === address (condition) => condition.getAddress() === address
) )
} }
@ -203,7 +203,7 @@ export class Keeper extends Instantiable {
*/ */
public getTemplateByName(name: string): AgreementTemplateBase { public getTemplateByName(name: string): AgreementTemplateBase {
return Object.values(this.templates).find( return Object.values(this.templates).find(
template => template.templateName === name (template) => template.templateName === name
) )
} }
@ -214,7 +214,7 @@ export class Keeper extends Instantiable {
*/ */
public getTemplateById(templateId: string): AgreementTemplateBase { public getTemplateById(templateId: string): AgreementTemplateBase {
return Object.values(this.templates).find( return Object.values(this.templates).find(
template => template.getId() === templateId (template) => template.getId() === templateId
) )
} }

View File

@ -146,7 +146,7 @@ export abstract class ContractBase extends Instantiable {
private searchMethod(methodName: string, args: any[] = []) { private searchMethod(methodName: string, args: any[] = []) {
const methods = this.contract.options.jsonInterface const methods = this.contract.options.jsonInterface
.map(method => ({ .map((method) => ({
...method, ...method,
signature: (method as any).signature signature: (method as any).signature
})) }))

View File

@ -80,7 +80,7 @@ export class TemplateStoreManager extends ContractBase {
} }
public getConditions(conditionTypes: string[]) { public getConditions(conditionTypes: string[]) {
return conditionTypes.map(address => return conditionTypes.map((address) =>
this.ocean.keeper.getConditionByAddress(address) this.ocean.keeper.getConditionByAddress(address)
) )
} }

View File

@ -183,7 +183,7 @@ export class AgreementTemplateBase {
({ name: conditionRef }) => conditionRef === ref ({ name: conditionRef }) => conditionRef === ref
).contractName ).contractName
return (await this.getConditions()).find( return (await this.getConditions()).find(
condition => condition.contractName === name (condition) => condition.contractName === name
) )
} }
@ -237,8 +237,8 @@ export class AgreementTemplateBase {
return states.reduce((acc, { contractName, ref, state }) => { return states.reduce((acc, { contractName, ref, state }) => {
const blockers = dependencies[ref] const blockers = dependencies[ref]
.map(dependency => states.find(_ => _.ref === dependency)) .map((dependency) => states.find((_) => _.ref === dependency))
.filter(condition => condition.state !== ConditionState.Fulfilled) .filter((condition) => condition.state !== ConditionState.Fulfilled)
return { return {
...acc, ...acc,
[ref]: { [ref]: {
@ -246,7 +246,7 @@ export class AgreementTemplateBase {
contractName, contractName,
state, state,
blocked: !!blockers.length, blocked: !!blockers.length,
blockedBy: blockers.map(_ => _.ref) blockedBy: blockers.map((_) => _.ref)
} }
} }
}, {}) }, {})
@ -309,6 +309,8 @@ export class AgreementTemplateBase {
*/ */
public async getActorTypes() { public async getActorTypes() {
const actorTypeIds = await this.getActorTypeIds() const actorTypeIds = await this.getActorTypeIds()
return actorTypeIds.map(typeId => this.templateManager.getActorTypeValue(typeId)) return actorTypeIds.map((typeId) =>
this.templateManager.getActorTypeValue(typeId)
)
} }
} }

View File

@ -26,7 +26,7 @@ export class OceanAccounts extends Instantiable {
const ethAccounts: string[] = await this.web3.eth.getAccounts() const ethAccounts: string[] = await this.web3.eth.getAccounts()
const accountPromises = ethAccounts.map( const accountPromises = ethAccounts.map(
address => new Account(address, this.instanceConfig) (address) => new Account(address, this.instanceConfig)
) )
return Promise.all(accountPromises) return Promise.all(accountPromises)
} }

View File

@ -60,7 +60,7 @@ export class OceanAssets extends Instantiable {
services: Service[] = [] services: Service[] = []
): SubscribablePromise<CreateProgressStep, DDO> { ): SubscribablePromise<CreateProgressStep, DDO> {
this.logger.log('Creating asset') this.logger.log('Creating asset')
return new SubscribablePromise(async observer => { return new SubscribablePromise(async (observer) => {
const { secretStoreUri } = this.config const { secretStoreUri } = this.config
const { didRegistry, templates } = this.ocean.keeper const { didRegistry, templates } = this.ocean.keeper
@ -147,7 +147,7 @@ export class OceanAssets extends Instantiable {
) )
.reverse() .reverse()
// Adding index // Adding index
.map(_ => ({ .map((_) => ({
..._, ..._,
index: indexCount++ index: indexCount++
})) as Service[] })) as Service[]
@ -287,7 +287,7 @@ export class OceanAssets extends Instantiable {
consumerAccount: Account, consumerAccount: Account,
provider?: string provider?: string
): SubscribablePromise<OrderProgressStep, string> { ): SubscribablePromise<OrderProgressStep, string> {
return new SubscribablePromise(async observer => { return new SubscribablePromise(async (observer) => {
const { keeper, utils } = this.ocean const { keeper, utils } = this.ocean
const ddo: DDO = await this.resolve(did) const ddo: DDO = await this.resolve(did)
const condition = keeper.conditions.accessSecretStoreCondition const condition = keeper.conditions.accessSecretStoreCondition

View File

@ -81,7 +81,7 @@ export class OceanCompute extends Instantiable {
algorithmMeta?: MetaDataAlgorithm, algorithmMeta?: MetaDataAlgorithm,
provider?: string provider?: string
): SubscribablePromise<OrderProgressStep, string> { ): SubscribablePromise<OrderProgressStep, string> {
return new SubscribablePromise(async observer => { return new SubscribablePromise(async (observer) => {
const { assets, keeper, utils } = this.ocean const { assets, keeper, utils } = this.ocean
const ddo: DDO = await assets.resolve(datasetDid) const ddo: DDO = await assets.resolve(datasetDid)
const service: Service = ddo.findServiceByType('compute') const service: Service = ddo.findServiceByType('compute')

View File

@ -61,7 +61,7 @@ export class OceanVersions extends Instantiable {
network: (await this.ocean.keeper.getNetworkName()).toLowerCase(), network: (await this.ocean.keeper.getNetworkName()).toLowerCase(),
keeperVersion: keeperPackageJson.version, keeperVersion: keeperPackageJson.version,
contracts: Object.values(await this.ocean.keeper.getAllInstances()) contracts: Object.values(await this.ocean.keeper.getAllInstances())
.filter(_ => !!_) .filter((_) => !!_)
.reduce( .reduce(
(acc, { contractName, address }) => ({ (acc, { contractName, address }) => ({
...acc, ...acc,
@ -115,19 +115,19 @@ export class OceanVersions extends Instantiable {
const networks = techs const networks = techs
.map(({ network }) => network) .map(({ network }) => network)
.filter(_ => !!_) .filter((_) => !!_)
.reduce((acc, network) => ({ ...acc, [network]: true }), {}) .reduce((acc, network) => ({ ...acc, [network]: true }), {})
let contractStatus = true let contractStatus = true
const contractList = techs.map(({ contracts }) => contracts).filter(_ => !!_) const contractList = techs.map(({ contracts }) => contracts).filter((_) => !!_)
Array.from(contractList.map(Object.keys)) Array.from(contractList.map(Object.keys))
.reduce((acc, _) => [...acc, ..._], []) .reduce((acc, _) => [...acc, ..._], [])
.filter((_, i, list) => list.indexOf(_) === i) .filter((_, i, list) => list.indexOf(_) === i)
.forEach(name => { .forEach((name) => {
let address let address
contractList contractList
.map(_ => _[name]) .map((_) => _[name])
.forEach(_ => { .forEach((_) => {
if (!address) { if (!address) {
address = _ address = _
return return

View File

@ -8,7 +8,7 @@ function fillParameterWithDDO(
parameter: ServiceAgreementTemplateParameter, parameter: ServiceAgreementTemplateParameter,
ddo: DDO ddo: DDO
): ServiceAgreementTemplateParameter { ): ServiceAgreementTemplateParameter {
const getValue = name => { const getValue = (name) => {
switch (name) { switch (name) {
case 'amount': case 'amount':
case 'price': case 'price':
@ -38,9 +38,9 @@ export function fillConditionsWithDDO(
conditions: ServiceAgreementTemplateCondition[], conditions: ServiceAgreementTemplateCondition[],
ddo: DDO ddo: DDO
): ServiceAgreementTemplateCondition[] { ): ServiceAgreementTemplateCondition[] {
return conditions.map(condition => ({ return conditions.map((condition) => ({
...condition, ...condition,
parameters: condition.parameters.map(parameter => ({ parameters: condition.parameters.map((parameter) => ({
...fillParameterWithDDO(parameter, ddo) ...fillParameterWithDDO(parameter, ddo)
})) }))
})) }))

View File

@ -39,7 +39,7 @@ export class SubscribableObserver<T, P> {
private emit(type: 'onNext' | 'onComplete' | 'onError', value: any) { private emit(type: 'onNext' | 'onComplete' | 'onError', value: any) {
Array.from(this.subscriptions) Array.from(this.subscriptions)
.map(subscription => subscription[type]) .map((subscription) => subscription[type])
.filter((callback: any) => callback && typeof callback === 'function') .filter((callback: any) => callback && typeof callback === 'function')
.forEach((callback: any) => callback(value)) .forEach((callback: any) => callback(value))
} }

View File

@ -42,12 +42,12 @@ export class SubscribablePromise<T extends any, P extends any> {
const execution = executor(this.observer) const execution = executor(this.observer)
Promise.resolve(execution as any) Promise.resolve(execution as any)
.then(result => { .then((result) => {
if (typeof (execution as any).then === 'function') { if (typeof (execution as any).then === 'function') {
this.observer.complete(result) this.observer.complete(result)
} }
}) })
.catch(result => { .catch((result) => {
if (typeof (execution as any).then === 'function') { if (typeof (execution as any).then === 'function') {
this.observer.error(result) this.observer.error(result)
} }

View File

@ -66,7 +66,7 @@ describe('Compute', () => {
) )
dataset = await ocean.assets dataset = await ocean.assets
.create(metadataAsset as MetaData, account, [computeService]) .create(metadataAsset as MetaData, account, [computeService])
.next(step => stepsAsset.push(step)) .next((step) => stepsAsset.push(step))
assert.instanceOf(dataset, DDO) assert.instanceOf(dataset, DDO)
assert.isDefined( assert.isDefined(
@ -92,7 +92,7 @@ describe('Compute', () => {
) )
datasetNoRawAlgo = await ocean.assets datasetNoRawAlgo = await ocean.assets
.create(metadataAsset as MetaData, account, [computeService]) .create(metadataAsset as MetaData, account, [computeService])
.next(step => stepsAsset.push(step)) .next((step) => stepsAsset.push(step))
assert.instanceOf(datasetNoRawAlgo, DDO) assert.instanceOf(datasetNoRawAlgo, DDO)
assert.isDefined( assert.isDefined(
@ -118,7 +118,7 @@ describe('Compute', () => {
) )
datasetWithTrustedAlgo = await ocean.assets datasetWithTrustedAlgo = await ocean.assets
.create(metadataAsset as MetaData, account, [computeService]) .create(metadataAsset as MetaData, account, [computeService])
.next(step => stepsAsset.push(step)) .next((step) => stepsAsset.push(step))
assert.instanceOf(datasetWithTrustedAlgo, DDO) assert.instanceOf(datasetWithTrustedAlgo, DDO)
assert.isDefined( assert.isDefined(
@ -132,7 +132,7 @@ describe('Compute', () => {
const stepsAlgorithm = [] const stepsAlgorithm = []
algorithm = await ocean.assets algorithm = await ocean.assets
.create(metadataAlgorithm as MetaData, account) .create(metadataAlgorithm as MetaData, account)
.next(step => stepsAlgorithm.push(step)) .next((step) => stepsAlgorithm.push(step))
assert.instanceOf(algorithm, DDO) assert.instanceOf(algorithm, DDO)
assert.deepEqual(stepsAlgorithm, [0, 1, 2, 3, 4, 5, 6, 7]) assert.deepEqual(stepsAlgorithm, [0, 1, 2, 3, 4, 5, 6, 7])
@ -143,7 +143,7 @@ describe('Compute', () => {
agreementId = await ocean.compute agreementId = await ocean.compute
.order(account, datasetNoRawAlgo.id, null, rawAlgoMeta) .order(account, datasetNoRawAlgo.id, null, rawAlgoMeta)
.next(step => steps.push(step)) .next((step) => steps.push(step))
assert.equal(agreementId, null) assert.equal(agreementId, null)
}) })
@ -153,7 +153,7 @@ describe('Compute', () => {
agreementId = await ocean.compute agreementId = await ocean.compute
.order(account, datasetWithTrustedAlgo.id, 'did:op:233454', null) .order(account, datasetWithTrustedAlgo.id, 'did:op:233454', null)
.next(step => steps.push(step)) .next((step) => steps.push(step))
assert.equal(agreementId, null) assert.equal(agreementId, null)
}) })
@ -172,7 +172,7 @@ describe('Compute', () => {
agreementId = await ocean.compute agreementId = await ocean.compute
.order(account, dataset.id) .order(account, dataset.id)
.next(step => steps.push(step)) .next((step) => steps.push(step))
console.log(agreementId) console.log(agreementId)
assert.isDefined(agreementId) assert.isDefined(agreementId)

View File

@ -170,7 +170,7 @@ describe('Consume Asset', () => {
assert.include(path, folder, 'The storage path is not correct.') assert.include(path, folder, 'The storage path is not correct.')
const files = await new Promise<string[]>(resolve => { const files = await new Promise<string[]>((resolve) => {
fs.readdir(path, (e, fileList) => { fs.readdir(path, (e, fileList) => {
resolve(fileList) resolve(fileList)
}) })
@ -195,7 +195,7 @@ describe('Consume Asset', () => {
assert.include(path, folder, 'The storage path is not correct.') assert.include(path, folder, 'The storage path is not correct.')
const files = await new Promise<string[]>(resolve => { const files = await new Promise<string[]>((resolve) => {
fs.readdir(path, (e, fileList) => { fs.readdir(path, (e, fileList) => {
resolve(fileList) resolve(fileList)
}) })

View File

@ -43,7 +43,7 @@ describe('Consume Asset (Brizo)', () => {
const steps = [] const steps = []
ddo = await ocean.assets ddo = await ocean.assets
.create(metadata as any, publisher) .create(metadata as any, publisher)
.next(step => steps.push(step)) .next((step) => steps.push(step))
assert.instanceOf(ddo, DDO) assert.instanceOf(ddo, DDO)
assert.deepEqual(steps, [0, 1, 2, 3, 4, 5, 6, 7]) assert.deepEqual(steps, [0, 1, 2, 3, 4, 5, 6, 7])
@ -64,7 +64,7 @@ describe('Consume Asset (Brizo)', () => {
agreementId = await ocean.assets agreementId = await ocean.assets
.order(ddo.id, consumer) .order(ddo.id, consumer)
.next(step => steps.push(step)) .next((step) => steps.push(step))
} catch {} } catch {}
assert.isDefined(agreementId) assert.isDefined(agreementId)
@ -77,7 +77,7 @@ describe('Consume Asset (Brizo)', () => {
assert.include(path, folder, 'The storage path is not correct.') assert.include(path, folder, 'The storage path is not correct.')
const files = await new Promise<string[]>(resolve => { const files = await new Promise<string[]>((resolve) => {
fs.readdir(path, (e, fileList) => { fs.readdir(path, (e, fileList) => {
resolve(fileList) resolve(fileList)
}) })

View File

@ -72,7 +72,7 @@ xdescribe('Consume Asset (Large size)', () => {
assert.include(path, folder, 'The storage path is not correct.') assert.include(path, folder, 'The storage path is not correct.')
const files = await new Promise<string[]>(resolve => { const files = await new Promise<string[]>((resolve) => {
fs.readdir(path, (e, fileList) => { fs.readdir(path, (e, fileList) => {
resolve(fileList) resolve(fileList)
}) })

View File

@ -53,7 +53,7 @@ describe('Register Escrow Access Secret Store Template', () => {
true true
) )
// TODO: Use a event to detect template mined // TODO: Use a event to detect template mined
await new Promise(resolve => setTimeout(resolve, 2 * 1000)) await new Promise((resolve) => setTimeout(resolve, 2 * 1000))
}) })
it('should approve the template', async () => { it('should approve the template', async () => {
@ -63,7 +63,7 @@ describe('Register Escrow Access Secret Store Template', () => {
true true
) )
// TODO: Use a event to detect template mined // TODO: Use a event to detect template mined
await new Promise(resolve => setTimeout(resolve, 2 * 1000)) await new Promise((resolve) => setTimeout(resolve, 2 * 1000))
}) })
}) })
@ -122,9 +122,9 @@ describe('Register Escrow Access Secret Store Template', () => {
}) })
it('should have condition instances asociated', async () => { it('should have condition instances asociated', async () => {
const conditionInstances = (await template.getConditionTypes()).map(address => const conditionInstances = (
keeper.getConditionByAddress(address) await template.getConditionTypes()
) ).map((address) => keeper.getConditionByAddress(address))
assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.') assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.')
@ -133,10 +133,10 @@ describe('Register Escrow Access Secret Store Template', () => {
EscrowReward, EscrowReward,
LockRewardCondition LockRewardCondition
] ]
conditionClasses.forEach(conditionClass => { conditionClasses.forEach((conditionClass) => {
if ( if (
!conditionInstances.find( !conditionInstances.find(
condition => condition instanceof conditionClass (condition) => condition instanceof conditionClass
) )
) { ) {
throw new Error( throw new Error(

View File

@ -55,7 +55,7 @@ describe('Register Escrow Compute Execution Template', () => {
true true
) )
// TODO: Use a event to detect template mined // TODO: Use a event to detect template mined
await new Promise(resolve => setTimeout(resolve, 2 * 1000)) await new Promise((resolve) => setTimeout(resolve, 2 * 1000))
}) })
it('should approve the template', async () => { it('should approve the template', async () => {
@ -65,7 +65,7 @@ describe('Register Escrow Compute Execution Template', () => {
true true
) )
// TODO: Use a event to detect template mined // TODO: Use a event to detect template mined
await new Promise(resolve => setTimeout(resolve, 2 * 1000)) await new Promise((resolve) => setTimeout(resolve, 2 * 1000))
}) })
}) })
@ -133,10 +133,10 @@ describe('Register Escrow Compute Execution Template', () => {
EscrowReward, EscrowReward,
LockRewardCondition LockRewardCondition
] ]
conditionClasses.forEach(conditionClass => { conditionClasses.forEach((conditionClass) => {
if ( if (
!conditionInstances.find( !conditionInstances.find(
condition => condition instanceof conditionClass (condition) => condition instanceof conditionClass
) )
) { ) {
throw new Error( throw new Error(

View File

@ -11,9 +11,7 @@ describe('Search Asset', () => {
let publisher: Account let publisher: Account
const testHash = Math.random() const testHash = Math.random().toString(36).substr(2)
.toString(36)
.substr(2)
let price let price
const metadataGenerator = (name: string) => const metadataGenerator = (name: string) =>
generateMetadata(`${name}${testHash}`, price) generateMetadata(`${name}${testHash}`, price)
@ -83,7 +81,7 @@ describe('Search Asset', () => {
1, 1,
'Something was wrong searching the assets' 'Something was wrong searching the assets'
) )
ddos.map(ddo => ddos.map((ddo) =>
assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO') assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO')
) )
}) })
@ -101,7 +99,7 @@ describe('Search Asset', () => {
}) })
assert.equal(ddos.length, 1, 'Something was wrong searching the assets') assert.equal(ddos.length, 1, 'Something was wrong searching the assets')
ddos.map(ddo => ddos.map((ddo) =>
assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO') assert.instanceOf(ddo, DDO, 'The DDO is not an instance of a DDO')
) )
}) })

View File

@ -9,7 +9,7 @@ import { LoggerInstance } from '../../../src/utils'
use(spies) use(spies)
const reponsify = async data => ({ const reponsify = async (data) => ({
ok: true, ok: true,
json: () => Promise.resolve(data) json: () => Promise.resolve(data)
}) })

View File

@ -17,25 +17,25 @@ describe('ContractWrapperBase', () => {
}) })
describe('#call()', () => { describe('#call()', () => {
it('should fail to call on an unknown contract function', done => { it('should fail to call on an unknown contract function', (done) => {
wrappedContract.callMock('balanceOfxxx', []).catch(() => { wrappedContract.callMock('balanceOfxxx', []).catch(() => {
done() done()
}) })
}) })
it('should fail to call on an contract function with wrong set of parameters', done => { it('should fail to call on an contract function with wrong set of parameters', (done) => {
wrappedContract.callMock('balanceOf', []).catch(() => { wrappedContract.callMock('balanceOf', []).catch(() => {
done() done()
}) })
}) })
it('should fail to call on an unknown contract function', done => { it('should fail to call on an unknown contract function', (done) => {
wrappedContract.sendMock('balanceOfxxx', '0x00', ['0x00']).catch(() => { wrappedContract.sendMock('balanceOfxxx', '0x00', ['0x00']).catch(() => {
done() done()
}) })
}) })
it('should fail to call on an contract function with wrong set of parameters', done => { it('should fail to call on an contract function with wrong set of parameters', (done) => {
wrappedContract.sendMock('approve', '0x000', []).catch(() => { wrappedContract.sendMock('approve', '0x000', []).catch(() => {
done() done()
}) })
@ -43,7 +43,7 @@ describe('ContractWrapperBase', () => {
}) })
describe('#send()', () => { describe('#send()', () => {
it('should fail to call on an unknown contract function', done => { it('should fail to call on an unknown contract function', (done) => {
wrappedContract.sendMock('transferxxx', accounts[0].getId(), []).catch(() => { wrappedContract.sendMock('transferxxx', accounts[0].getId(), []).catch(() => {
done() done()
}) })
@ -60,7 +60,7 @@ describe('ContractWrapperBase', () => {
}) })
describe('#getEventData()', () => { describe('#getEventData()', () => {
it('should fail on unknown event', done => { it('should fail on unknown event', (done) => {
wrappedContract.getEventData('crazyevent', {}).catch(() => { wrappedContract.getEventData('crazyevent', {}).catch(() => {
done() done()
}) })

View File

@ -28,8 +28,8 @@ describe('ContractEvent', () => {
let validResolve = false let validResolve = false
let subscription: ContractEventSubscription let subscription: ContractEventSubscription
const waitUntilEvent = new Promise(resolve => { const waitUntilEvent = new Promise((resolve) => {
subscription = event.subscribe(events => { subscription = event.subscribe((events) => {
assert.isDefined(events) assert.isDefined(events)
assert.lengthOf(events, 2) assert.lengthOf(events, 2)
if (validResolve) { if (validResolve) {
@ -40,7 +40,7 @@ describe('ContractEvent', () => {
await Promise.all([executeTransaction(), executeTransaction()]) await Promise.all([executeTransaction(), executeTransaction()])
await new Promise(resolve => setTimeout(resolve, 2000)) await new Promise((resolve) => setTimeout(resolve, 2000))
validResolve = true validResolve = true
await Promise.all([executeTransaction(), executeTransaction()]) await Promise.all([executeTransaction(), executeTransaction()])
@ -68,7 +68,7 @@ describe('ContractEvent', () => {
await executeTransaction() await executeTransaction()
await new Promise(resolve => setTimeout(resolve, 2000)) await new Promise((resolve) => setTimeout(resolve, 2000))
canBeRejected = true canBeRejected = true
await executeTransaction() await executeTransaction()
@ -82,7 +82,7 @@ describe('ContractEvent', () => {
const waitUntilEvent = event.once() const waitUntilEvent = event.once()
await new Promise(resolve => setTimeout(resolve, 400)) await new Promise((resolve) => setTimeout(resolve, 400))
await executeTransaction() await executeTransaction()

View File

@ -17,7 +17,7 @@ describe('ContractHandler', () => {
assert(await contractHandler.get('OceanToken')) assert(await contractHandler.get('OceanToken'))
}) })
it('should fail to load an unknown contract', done => { it('should fail to load an unknown contract', (done) => {
contractHandler.get('OceanXXX').catch(() => { contractHandler.get('OceanXXX').catch(() => {
done() done()
}) })

View File

@ -67,12 +67,12 @@ describe('EventHandler', () => {
const subscription = eventHandler.subscribe(callbackSpy) const subscription = eventHandler.subscribe(callbackSpy)
await new Promise(resolve => setTimeout(resolve, 300)) await new Promise((resolve) => setTimeout(resolve, 300))
expect(callbackSpy).not.to.has.been.called() expect(callbackSpy).not.to.has.been.called()
blockNumber++ blockNumber++
await new Promise(resolve => setTimeout(resolve, 300)) await new Promise((resolve) => setTimeout(resolve, 300))
expect(callbackSpy).to.has.been.called.with(blockNumber) expect(callbackSpy).to.has.been.called.with(blockNumber)

View File

@ -18,7 +18,7 @@ describe('DID', () => {
assert(did.getId() === id, did.getId()) assert(did.getId() === id, did.getId())
}) })
it('should throw if prefix does not match', done => { it('should throw if prefix does not match', (done) => {
const id = '1234' const id = '1234'
try { try {
const did: DID = DID.parse(`did:xxx:${id}`) const did: DID = DID.parse(`did:xxx:${id}`)
@ -28,7 +28,7 @@ describe('DID', () => {
} }
}) })
it('should throw if id does not match', done => { it('should throw if id does not match', (done) => {
const id = 'xyz' const id = 'xyz'
try { try {
const did: DID = DID.parse(`did:op:${id}`) const did: DID = DID.parse(`did:op:${id}`)

View File

@ -23,7 +23,7 @@ describe('OceanAccounts', () => {
it('should return the list of accounts', async () => { it('should return the list of accounts', async () => {
const accounts = await oceanAccounts.list() const accounts = await oceanAccounts.list()
accounts.map(account => assert.instanceOf(account, Account)) accounts.map((account) => assert.instanceOf(account, Account))
}) })
}) })

View File

@ -22,9 +22,9 @@ describe('SubscribablePromise', () => {
assert.typeOf(subscription.unsubscribe, 'function') assert.typeOf(subscription.unsubscribe, 'function')
}) })
it('should listen the next values', done => { it('should listen the next values', (done) => {
const onNextSpy = spy() const onNextSpy = spy()
const subscribable = new SubscribablePromise(observer => { const subscribable = new SubscribablePromise((observer) => {
setTimeout(() => observer.next('test'), 10) setTimeout(() => observer.next('test'), 10)
setTimeout(() => observer.next('test'), 20) setTimeout(() => observer.next('test'), 20)
}) })
@ -39,10 +39,10 @@ describe('SubscribablePromise', () => {
}) })
describe('#then()', () => { describe('#then()', () => {
it('should resolve', done => { it('should resolve', (done) => {
const onCompleteSpy = spy() const onCompleteSpy = spy()
const onFinallySpy = spy() const onFinallySpy = spy()
const subscribable = new SubscribablePromise(observer => { const subscribable = new SubscribablePromise((observer) => {
setTimeout(() => observer.next('test'), 10) setTimeout(() => observer.next('test'), 10)
setTimeout(() => observer.complete('test'), 20) setTimeout(() => observer.complete('test'), 20)
}) })
@ -59,10 +59,10 @@ describe('SubscribablePromise', () => {
}) })
describe('#error()', () => { describe('#error()', () => {
it('should catch the error', done => { it('should catch the error', (done) => {
const onErrorSpy = spy() const onErrorSpy = spy()
const onFinallySpy = spy() const onFinallySpy = spy()
const subscribable = new SubscribablePromise(observer => { const subscribable = new SubscribablePromise((observer) => {
setTimeout(() => observer.next('test'), 10) setTimeout(() => observer.next('test'), 10)
setTimeout(() => observer.error('test'), 20) setTimeout(() => observer.error('test'), 20)
}) })
@ -80,7 +80,7 @@ describe('SubscribablePromise', () => {
it('should be able to subscribe and wait for a promise', async () => { it('should be able to subscribe and wait for a promise', async () => {
const onNextSpy = spy() const onNextSpy = spy()
const subscribable = new SubscribablePromise(observer => { const subscribable = new SubscribablePromise((observer) => {
setTimeout(() => observer.next('test'), 10) setTimeout(() => observer.next('test'), 10)
setTimeout(() => observer.next('test'), 20) setTimeout(() => observer.next('test'), 20)
setTimeout(() => observer.complete('completed'), 30) setTimeout(() => observer.complete('completed'), 30)
@ -96,12 +96,12 @@ describe('SubscribablePromise', () => {
it('should use the result of a the promise as executor to complete the observer', async () => { it('should use the result of a the promise as executor to complete the observer', async () => {
const onNextSpy = spy() const onNextSpy = spy()
const subscribable = new SubscribablePromise(async observer => { const subscribable = new SubscribablePromise(async (observer) => {
await new Promise(resolve => setTimeout(resolve, 10)) await new Promise((resolve) => setTimeout(resolve, 10))
observer.next('test') observer.next('test')
await new Promise(resolve => setTimeout(resolve, 10)) await new Promise((resolve) => setTimeout(resolve, 10))
observer.next('test') observer.next('test')
await new Promise(resolve => setTimeout(resolve, 10)) await new Promise((resolve) => setTimeout(resolve, 10))
return 'completed' return 'completed'
}) })