()
private promise = Object.assign(
new Promise((resolve, reject) => {
setTimeout(() => {
- this.observer
- .subscribe(undefined, resolve, reject)
+ this.observer.subscribe(undefined, resolve, reject)
}, 0)
}),
- this,
+ this
)
- constructor(executor: (observer: SubscribableObserver) => void | Promise) {
+ constructor(
+ executor: (observer: SubscribableObserver) => void | Promise
+ ) {
// Defear
setTimeout(() => this.init(executor), 1)
}
@@ -26,7 +27,10 @@ export class SubscribablePromise {
return this
}
- public then(onfulfilled?: (value: P) => any, onrejected?: (error: any) => any) {
+ public then(
+ onfulfilled?: (value: P) => any,
+ onrejected?: (error: any) => any
+ ) {
return Object.assign(this.promise.then(onfulfilled, onrejected), this)
}
@@ -38,17 +42,19 @@ export class SubscribablePromise {
return Object.assign(this.promise.finally(onfinally), this)
}
- private init(executor: (observer: SubscribableObserver) => void | Promise) {
+ private init(
+ executor: (observer: SubscribableObserver) => void | Promise
+ ) {
const execution = executor(this.observer)
Promise.resolve(execution as any)
- .then((result) => {
- if (typeof (execution as any).then === "function") {
+ .then(result => {
+ if (typeof (execution as any).then === 'function') {
this.observer.complete(result)
}
})
- .catch((result) => {
- if (typeof (execution as any).then === "function") {
+ .catch(result => {
+ if (typeof (execution as any).then === 'function') {
this.observer.error(result)
}
})
diff --git a/src/utils/index.ts b/src/utils/index.ts
index d8cf9bb..358a38f 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -1,7 +1,7 @@
-export * from "./PromiseResolver"
-export * from "./Logger"
-export * from "./ConversionTypeHelpers"
-export * from "./GeneratorHelpers"
-export * from "./DDOHelpers"
-export * from "./SubscribablePromise"
-export * from "./SubscribableObserver"
+export * from './PromiseResolver'
+export * from './Logger'
+export * from './ConversionTypeHelpers'
+export * from './GeneratorHelpers'
+export * from './DDOHelpers'
+export * from './SubscribablePromise'
+export * from './SubscribableObserver'
diff --git a/test/Squid.test.ts b/test/Squid.test.ts
index 2be7eb4..cb8ac0d 100644
--- a/test/Squid.test.ts
+++ b/test/Squid.test.ts
@@ -1,11 +1,9 @@
-import * as assert from "assert"
-import * as squid from "../src/squid"
+import * as assert from 'assert'
+import * as squid from '../src/squid'
-describe("Squid", () => {
-
- describe("interface", () => {
-
- it("should expose Ocean", async () => {
+describe('Squid', () => {
+ describe('interface', () => {
+ it('should expose Ocean', async () => {
assert(squid.Ocean)
})
})
diff --git a/test/TestIdGenerator.ts b/test/TestIdGenerator.ts
index a8ac3a7..d6b85ad 100644
--- a/test/TestIdGenerator.ts
+++ b/test/TestIdGenerator.ts
@@ -1,7 +1,7 @@
-import { generateId } from "../src/utils/GeneratorHelpers"
+import { generateId } from '../src/utils/GeneratorHelpers'
export default class TestIdGenerator {
public static generatePrefixedId() {
- return "0x" + generateId()
+ return '0x' + generateId()
}
}
diff --git a/test/aquarius/Aquarius.test.ts b/test/aquarius/Aquarius.test.ts
index 271b0f2..948a363 100644
--- a/test/aquarius/Aquarius.test.ts
+++ b/test/aquarius/Aquarius.test.ts
@@ -1,118 +1,124 @@
-import { assert, spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import { Ocean } from "../../src/ocean/Ocean"
-import { Aquarius } from "../../src/aquarius/Aquarius"
-import { SearchQuery } from "../../src/aquarius/Aquarius"
-import { DDO } from "../../src/ddo/DDO"
-import DID from "../../src/ocean/DID"
-import config from "../config"
+import { Ocean } from '../../src/ocean/Ocean'
+import { Aquarius, SearchQuery } from '../../src/aquarius/Aquarius'
+import { DDO } from '../../src/ddo/DDO'
+import DID from '../../src/ocean/DID'
+import config from '../config'
use(spies)
-const reponsify = async (data) => ({ok: true, json: () => Promise.resolve(data)})
-
-describe("Aquarius", () => {
+const reponsify = async data => ({
+ ok: true,
+ json: () => Promise.resolve(data)
+})
+describe('Aquarius', () => {
let ocean: Ocean
let aquarius: Aquarius
- // tslint:disable-next-line
- const getResults = (results: DDO[], page = 0, total_pages = 1, total_results = 1) =>
- ({results, page, total_pages, total_results})
+ /* eslint-disable @typescript-eslint/camelcase */
+ const getResults = (
+ results: DDO[],
+ page = 0,
+ total_pages = 1,
+ total_results = 1
+ ) => ({ results, page, total_pages, total_results })
+ /* eslint-enable @typescript-eslint/camelcase */
beforeEach(async () => {
ocean = await Ocean.getInstance(config)
- aquarius = ocean.aquarius
+ aquarius = ocean.aquarius // eslint-disable-line prefer-destructuring
})
afterEach(() => {
spy.restore()
})
- describe("#queryMetadata()", () => {
-
+ describe('#queryMetadata()', () => {
const query = {
offset: 100,
page: 1,
query: {
- value: 1,
+ value: 1
},
sort: {
- value: 1,
+ value: 1
},
- text: "Office",
+ text: 'Office'
} as SearchQuery
- it("should query metadata", async () => {
- spy.on(ocean.utils.fetch, "post", () => reponsify(getResults([new DDO()])))
+ it('should query metadata', async () => {
+ spy.on(ocean.utils.fetch, 'post', () =>
+ reponsify(getResults([new DDO()]))
+ )
const result = await aquarius.queryMetadata(query)
- assert.typeOf(result.results, "array")
+ assert.typeOf(result.results, 'array')
assert.lengthOf(result.results, 1)
assert.equal(result.page, 0)
assert.equal(result.totalPages, 1)
assert.equal(result.totalResults, 1)
})
- it("should query metadata and return real ddo", async () => {
-
- spy.on(ocean.utils.fetch, "post", () => reponsify(getResults([new DDO()])))
+ it('should query metadata and return real ddo', async () => {
+ spy.on(ocean.utils.fetch, 'post', () =>
+ reponsify(getResults([new DDO()]))
+ )
const result = await aquarius.queryMetadata(query)
- assert.typeOf(result.results, "array")
+ assert.typeOf(result.results, 'array')
assert.lengthOf(result.results, 1)
assert.isDefined(result.results[0].findServiceById)
})
})
- describe("#queryMetadataByText()", () => {
-
+ describe('#queryMetadataByText()', () => {
const query = {
offset: 100,
page: 1,
query: {
- value: 1,
+ value: 1
},
sort: {
- value: 1,
+ value: 1
},
- text: "Office",
+ text: 'Office'
} as SearchQuery
- it("should query metadata by text", async () => {
-
- spy.on(ocean.utils.fetch, "get", () => reponsify(getResults([new DDO()])))
+ it('should query metadata by text', async () => {
+ spy.on(ocean.utils.fetch, 'get', () =>
+ reponsify(getResults([new DDO()]))
+ )
const result = await aquarius.queryMetadataByText(query)
- assert.typeOf(result.results, "array")
+ assert.typeOf(result.results, 'array')
assert.lengthOf(result.results, 1)
assert.equal(result.page, 0)
assert.equal(result.totalPages, 1)
assert.equal(result.totalResults, 1)
})
- it("should query metadata and return real ddo", async () => {
-
- spy.on(ocean.utils.fetch, "get", () => reponsify(getResults([new DDO()])))
+ it('should query metadata and return real ddo', async () => {
+ spy.on(ocean.utils.fetch, 'get', () =>
+ reponsify(getResults([new DDO()]))
+ )
const result = await aquarius.queryMetadataByText(query)
- assert.typeOf(result.results, "array")
+ assert.typeOf(result.results, 'array')
assert.lengthOf(result.results, 1)
assert.isDefined(result.results[0].findServiceById)
})
-
})
- describe("#storeDDO()", () => {
-
- it("should store a ddo", async () => {
-
+ describe('#storeDDO()', () => {
+ it('should store a ddo', async () => {
const did: DID = DID.generate()
const ddo: DDO = new DDO({
- id: did.getId(),
+ id: did.getId()
})
- spy.on(ocean.utils.fetch, "post", () => reponsify(ddo))
+ spy.on(ocean.utils.fetch, 'post', () => reponsify(ddo))
const result: DDO = await aquarius.storeDDO(ddo)
assert(result)
@@ -120,17 +126,15 @@ describe("Aquarius", () => {
})
})
- describe("#retrieveDDO()", () => {
-
- it("should store a ddo", async () => {
-
+ describe('#retrieveDDO()', () => {
+ it('should store a ddo', async () => {
const did: DID = DID.generate()
const ddo: DDO = new DDO({
- id: did.getId(),
+ id: did.getId()
})
- spy.on(ocean.utils.fetch, "post", () => reponsify(ddo))
- spy.on(ocean.utils.fetch, "get", () => reponsify(ddo))
+ spy.on(ocean.utils.fetch, 'post', () => reponsify(ddo))
+ spy.on(ocean.utils.fetch, 'get', () => reponsify(ddo))
const storageResult: DDO = await aquarius.storeDDO(ddo)
assert(storageResult)
diff --git a/test/config.ts b/test/config.ts
index f6d1cc3..37f1459 100644
--- a/test/config.ts
+++ b/test/config.ts
@@ -1,13 +1,13 @@
-import { Config, LogLevel } from "../src/models/Config"
-import { LoggerInstance } from "../src/utils"
+import { Config, LogLevel } from '../src/models/Config'
+import { LoggerInstance } from '../src/utils'
LoggerInstance.setLevel(LogLevel.Error)
export default {
- aquariusUri: "http://localhost:5000",
- brizoUri: "http://localhost:3000",
+ aquariusUri: 'http://localhost:5000',
+ brizoUri: 'http://localhost:3000',
nodeUri: `http://localhost:${process.env.ETH_PORT || 8545}`,
- parityUri: "http://localhost:9545",
- secretStoreUri: "http://localhost:12001",
- verbose: LogLevel.Error,
+ parityUri: 'http://localhost:9545',
+ secretStoreUri: 'http://localhost:12001',
+ verbose: LogLevel.Error
} as Config
diff --git a/test/ddo/DDO.test.ts b/test/ddo/DDO.test.ts
index 6afdef6..905ce90 100644
--- a/test/ddo/DDO.test.ts
+++ b/test/ddo/DDO.test.ts
@@ -1,157 +1,175 @@
-import { assert, expect, spy, use } from "chai"
-import * as spies from "chai-spies"
-import * as Web3 from "web3"
+import { assert, expect, spy, use } from 'chai'
+import * as spies from 'chai-spies'
+import * as Web3 from 'web3'
-import { DDO } from "../../src/ddo/DDO"
-import { Service } from "../../src/ddo/Service"
-import { Ocean } from "../../src/ocean/Ocean"
-import config from "../config"
-import TestContractHandler from "../keeper/TestContractHandler"
+import { DDO } from '../../src/ddo/DDO'
+import { Service } from '../../src/ddo/Service'
+import { Ocean } from '../../src/ocean/Ocean'
+import config from '../config'
+import TestContractHandler from '../keeper/TestContractHandler'
-import * as jsonDDO from "../testdata/ddo.json"
+import * as jsonDDO from '../testdata/ddo.json'
use(spies)
-describe("DDO", () => {
-
+describe('DDO', () => {
const testDDO: DDO = new DDO({
- id: `did:op:${"a".repeat(64)}`,
+ id: `did:op:${'a'.repeat(64)}`,
publicKey: [
{
- id: "did:op:123456789abcdefghi#keys-1",
- type: "RsaVerificationKey2018",
- owner: "did:op:123456789abcdefghi",
- publicKeyPem: "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n",
+ id: 'did:op:123456789abcdefghi#keys-1',
+ type: 'RsaVerificationKey2018',
+ owner: 'did:op:123456789abcdefghi',
+ publicKeyPem: '-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n'
},
{
- id: "did:op:123456789abcdefghi#keys-2",
- type: "Ed25519VerificationKey2018",
- owner: "did:op:123456789abcdefghi",
- publicKeyBase58: "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
- },
+ id: 'did:op:123456789abcdefghi#keys-2',
+ type: 'Ed25519VerificationKey2018',
+ owner: 'did:op:123456789abcdefghi',
+ publicKeyBase58: 'H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV'
+ }
],
authentication: [
{
- type: "RsaSignatureAuthentication2018",
- publicKey: "did:op:123456789abcdefghi#keys-1",
+ type: 'RsaSignatureAuthentication2018',
+ publicKey: 'did:op:123456789abcdefghi#keys-1'
},
{
- type: "ieee2410Authentication2018",
- publicKey: "did:op:123456789abcdefghi#keys-2",
- },
+ type: 'ieee2410Authentication2018',
+ publicKey: 'did:op:123456789abcdefghi#keys-2'
+ }
],
service: [
{
- type: "OpenIdConnectVersion1.0Service",
- serviceEndpoint: "https://openid.example.com/",
+ type: 'OpenIdConnectVersion1.0Service',
+ serviceEndpoint: 'https://openid.example.com/'
},
{
- type: "CredentialRepositoryService",
- serviceEndpoint: "https://repository.example.com/service/8377464",
+ type: 'CredentialRepositoryService',
+ serviceEndpoint:
+ 'https://repository.example.com/service/8377464'
},
{
- type: "XdiService",
- serviceEndpoint: "https://xdi.example.com/8377464",
+ type: 'XdiService',
+ serviceEndpoint: 'https://xdi.example.com/8377464'
},
{
- type: "HubService",
- serviceEndpoint: "https://hub.example.com/.identity/did:op:0123456789abcdef/",
+ type: 'HubService',
+ serviceEndpoint:
+ 'https://hub.example.com/.identity/did:op:0123456789abcdef/'
},
{
- type: "MessagingService",
- serviceEndpoint: "https://example.com/messages/8377464",
+ type: 'MessagingService',
+ serviceEndpoint: 'https://example.com/messages/8377464'
},
{
- type: "SocialWebInboxService",
- serviceEndpoint: "https://social.example.com/83hfh37dj",
- description: "My public social inbox",
+ type: 'SocialWebInboxService',
+ serviceEndpoint: 'https://social.example.com/83hfh37dj',
+ description: 'My public social inbox',
spamCost: {
- amount: "0.50",
- currency: "USD",
- },
+ amount: '0.50',
+ currency: 'USD'
+ }
} as any,
{
- id: "did:op:123456789abcdefghi;bops",
- type: "BopsService",
- serviceEndpoint: "https://bops.example.com/enterprise/",
+ id: 'did:op:123456789abcdefghi;bops',
+ type: 'BopsService',
+ serviceEndpoint: 'https://bops.example.com/enterprise/'
},
{
- type: "Consume",
- serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}",
+ type: 'Consume',
+ serviceEndpoint:
+ 'http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}'
},
{
- type: "Compute",
+ type: 'Compute',
// tslint:disable-next-line
- serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/compute?pubKey=${pubKey}&serviceId={serviceId}&algo={algo}&container={container}",
+ serviceEndpoint:
+ 'http://mybrizo.org/api/v1/brizo/services/compute?pubKey=${pubKey}&serviceId={serviceId}&algo={algo}&container={container}'
},
{
- type: "Metadata",
- serviceEndpoint: "http://myaquarius.org/api/v1/provider/assets/metadata/{did}",
+ type: 'Metadata',
+ serviceEndpoint:
+ 'http://myaquarius.org/api/v1/provider/assets/metadata/{did}',
metadata: {
base: {
- name: "UK Weather information 2011",
- type: "dataset",
- description: "Weather information of UK including temperature and humidity",
- dateCreated: "2012-10-10T17:00:000Z",
- datePublished: "2012-10-10T17:00:000Z",
- author: "Met Office",
- license: "CC-BY",
- copyrightHolder: "Met Office",
- workExample: "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
+ name: 'UK Weather information 2011',
+ type: 'dataset',
+ description:
+ 'Weather information of UK including temperature and humidity',
+ dateCreated: '2012-10-10T17:00:000Z',
+ datePublished: '2012-10-10T17:00:000Z',
+ author: 'Met Office',
+ license: 'CC-BY',
+ copyrightHolder: 'Met Office',
+ workExample:
+ '423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68',
links: [
{
- sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/",
+ sample1:
+ 'http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/'
},
{
- sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/",
+ sample2:
+ 'http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/'
},
{
- fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/",
- },
+ fieldsDescription:
+ 'http://data.ceda.ac.uk/badc/ukcp09/'
+ }
+ ],
+ inLanguage: 'en',
+ categories: ['Economy', 'Data Science'],
+ tags: [
+ 'weather',
+ 'uk',
+ '2011',
+ 'temperature',
+ 'humidity'
],
- inLanguage: "en",
- categories: ["Economy", "Data Science"],
- tags: ["weather", "uk", "2011", "temperature", "humidity"],
price: 10,
files: [
{
index: 0,
- checksum: "efb2c764274b745f5fc37f97c6b0e761",
+ checksum: 'efb2c764274b745f5fc37f97c6b0e761',
contentLength: 4535431,
- resourceId: "access-log2018-02-13-15-17-29-18386C502CAEA932",
+ resourceId:
+ 'access-log2018-02-13-15-17-29-18386C502CAEA932'
},
{
index: 1,
- checksum: "085340abffh21495345af97c6b0e761",
- contentLength: 12324,
+ checksum: '085340abffh21495345af97c6b0e761',
+ contentLength: 12324
},
{
- index: 2,
- },
+ index: 2
+ }
],
- checksum: "",
+ checksum: ''
},
curation: {
rating: 0.93,
numVotes: 123,
- schema: "Binary Voting",
+ schema: 'Binary Voting'
},
additionalInformation: {
- updateFrecuency: "yearly",
+ updateFrecuency: 'yearly',
structuredMarkup: [
{
- uri: "http://skos.um.es/unescothes/C01194/jsonld",
- mediaType: "application/ld+json",
+ uri:
+ 'http://skos.um.es/unescothes/C01194/jsonld',
+ mediaType: 'application/ld+json'
},
{
- uri: "http://skos.um.es/unescothes/C01194/turtle",
- mediaType: "text/turtle",
- },
- ],
- },
- },
- },
- ],
+ uri:
+ 'http://skos.um.es/unescothes/C01194/turtle',
+ mediaType: 'text/turtle'
+ }
+ ]
+ }
+ }
+ }
+ ]
})
let web3: Web3
@@ -167,20 +185,16 @@ describe("DDO", () => {
spy.restore()
})
- describe("#serialize()", () => {
-
- it("should properly serialize", async () => {
-
+ describe('#serialize()', () => {
+ it('should properly serialize', async () => {
const ddoString = DDO.serialize(testDDO)
assert(ddoString)
- assert(ddoString.startsWith("{"))
+ assert(ddoString.startsWith('{'))
})
})
- describe("#constructor()", () => {
-
- it("should create an empty ddo", async () => {
-
+ describe('#constructor()', () => {
+ it('should create an empty ddo', async () => {
const ddo = new DDO()
assert(ddo)
@@ -189,15 +203,14 @@ describe("DDO", () => {
assert(ddo.publicKey.length === 0)
})
- it("should create an predefined ddo", async () => {
-
+ it('should create an predefined ddo', async () => {
const service: Partial & any = {
- serviceEndpoint: "http://",
- description: "nice service",
+ serviceEndpoint: 'http://',
+ description: 'nice service'
}
const ddo = new DDO({
- service: [service as any],
+ service: [service as any]
})
assert(ddo)
@@ -209,72 +222,84 @@ describe("DDO", () => {
})
})
- describe("#deserialize()", () => {
-
- it("should properly deserialize from serialized object", async () => {
-
+ describe('#deserialize()', () => {
+ it('should properly deserialize from serialized object', async () => {
const ddoString = DDO.serialize(testDDO)
- assert.typeOf(ddoString, "string")
+ assert.typeOf(ddoString, 'string')
const ddo: DDO = DDO.deserialize(ddoString)
assert.instanceOf(ddo, DDO)
assert.equal(ddo.id, testDDO.id)
- assert.equal(ddo.publicKey[0].publicKeyPem, testDDO.publicKey[0].publicKeyPem)
+ assert.equal(
+ ddo.publicKey[0].publicKeyPem,
+ testDDO.publicKey[0].publicKeyPem
+ )
})
- it("should properly deserialize from json file", async () => {
-
+ it('should properly deserialize from json file', async () => {
const ddo: DDO = DDO.deserialize(JSON.stringify(jsonDDO))
assert(ddo)
assert.equal(ddo.id, jsonDDO.id)
- assert.equal(ddo.publicKey[0].publicKeyPem, jsonDDO.publicKey[0].publicKeyPem)
+ assert.equal(
+ ddo.publicKey[0].publicKeyPem,
+ jsonDDO.publicKey[0].publicKeyPem
+ )
})
})
- describe("#getChecksum()", () => {
- it("should properly generate a the checksum DDO", async () => {
+ describe('#getChecksum()', () => {
+ it('should properly generate a the checksum DDO', async () => {
const ddo = new DDO(testDDO)
const checksum = ddo.getChecksum()
- assert.equal(checksum, "0x15f27a7a3c7b15d2b06dec7347c6b8da168adddd7df51a8ebbbe87b59b80049b")
+ assert.equal(
+ checksum,
+ '0x15f27a7a3c7b15d2b06dec7347c6b8da168adddd7df51a8ebbbe87b59b80049b'
+ )
})
})
- describe("#generateProof()", () => {
+ describe('#generateProof()', () => {
+ const publicKey = `0x${'a'.repeat(40)}`
+ const signature = `0x${'a'.repeat(130)}`
- const publicKey = `0x${"a".repeat(40)}`
- const signature = `0x${"a".repeat(130)}`
-
- it("should properly generate the proof", async () => {
- const signTextSpy = spy.on(ocean.utils.signature, "signText", () => signature)
+ it('should properly generate the proof', async () => {
+ const signTextSpy = spy.on(
+ ocean.utils.signature,
+ 'signText',
+ () => signature
+ )
const ddo = new DDO(testDDO)
const checksum = ddo.getChecksum()
const proof = await ddo.generateProof(ocean, publicKey)
assert.include(proof as any, {
creator: publicKey,
- type: "DDOIntegritySignature",
- signatureValue: signature,
+ type: 'DDOIntegritySignature',
+ signatureValue: signature
})
expect(signTextSpy).to.have.been.called.with(checksum, publicKey)
})
})
- describe("#addProof()", () => {
+ describe('#addProof()', () => {
+ const publicKey = `0x${'a'.repeat(40)}`
- const publicKey = `0x${"a".repeat(40)}`
-
- it("should properly add the proof on the DDO", async () => {
+ it('should properly add the proof on the DDO', async () => {
const fakeProof = {
creation: Date.now(),
- creator: "test",
- type: "test",
- signaturValue: "test",
+ creator: 'test',
+ type: 'test',
+ signaturValue: 'test'
} as any
const ddo = new DDO(testDDO)
- const generateProofSpy = spy.on(ddo, "generateProof", () => fakeProof)
+ const generateProofSpy = spy.on(
+ ddo,
+ 'generateProof',
+ () => fakeProof
+ )
await ddo.addProof(web3, publicKey)
assert.equal(ddo.proof, fakeProof)
diff --git a/test/keeper/ContractBase.test.ts b/test/keeper/ContractBase.test.ts
index 84f4251..f1c7dc6 100644
--- a/test/keeper/ContractBase.test.ts
+++ b/test/keeper/ContractBase.test.ts
@@ -1,15 +1,14 @@
-import {assert} from "chai"
-import Account from "../../src/ocean/Account"
-import { Ocean } from "../../src/ocean/Ocean"
-import config from "../config"
-import ContractBaseMock from "../mocks/ContractBase.Mock"
-import TestContractHandler from "./TestContractHandler"
+import { assert } from 'chai'
+import Account from '../../src/ocean/Account'
+import { Ocean } from '../../src/ocean/Ocean'
+import config from '../config'
+import ContractBaseMock from '../mocks/ContractBase.Mock'
+import TestContractHandler from './TestContractHandler'
-const wrappedContract = new ContractBaseMock("OceanToken")
+const wrappedContract = new ContractBaseMock('OceanToken')
let accounts: Account[]
-describe("ContractWrapperBase", () => {
-
+describe('ContractWrapperBase', () => {
before(async () => {
await TestContractHandler.prepareContracts()
const ocean: Ocean = await Ocean.getInstance(config)
@@ -17,79 +16,58 @@ describe("ContractWrapperBase", () => {
await wrappedContract.initMock((ocean as any).instanceConfig)
})
- describe("#call()", () => {
+ describe('#call()', () => {
+ it('should fail to call on an unknown contract function', done => {
+ wrappedContract.callMock('balanceOfxxx', []).catch(() => {
+ done()
+ })
+ })
- it("should fail to call on an unknown contract function", (done) => {
+ it('should fail to call on an contract function with wrong set of parameters', done => {
+ wrappedContract.callMock('balanceOf', []).catch(() => {
+ done()
+ })
+ })
- wrappedContract.callMock("balanceOfxxx", [])
+ it('should fail to call on an unknown contract function', done => {
+ wrappedContract
+ .sendMock('balanceOfxxx', '0x00', ['0x00'])
.catch(() => {
-
done()
})
})
- it("should fail to call on an contract function with wrong set of parameters", (done) => {
-
- wrappedContract.callMock("balanceOf", [])
- .catch(() => {
-
- done()
- })
+ it('should fail to call on an contract function with wrong set of parameters', done => {
+ wrappedContract.sendMock('approve', '0x000', []).catch(() => {
+ done()
+ })
})
+ })
- it("should fail to call on an unknown contract function", (done) => {
-
- wrappedContract.sendMock("balanceOfxxx", "0x00", ["0x00"])
+ describe('#send()', () => {
+ it('should fail to call on an unknown contract function', done => {
+ wrappedContract
+ .sendMock('transferxxx', accounts[0].getId(), [])
.catch(() => {
-
- done()
- })
- })
-
- it("should fail to call on an contract function with wrong set of parameters", (done) => {
-
- wrappedContract.sendMock("approve", "0x000", [])
- .catch(() => {
-
done()
})
})
})
- describe("#send()", () => {
-
- it("should fail to call on an unknown contract function", (done) => {
-
- wrappedContract.sendMock("transferxxx", accounts[0].getId(), [])
- .catch(() => {
-
- done()
- })
- })
- })
-
- describe("#getSignatureOfMethod()", () => {
-
- it("should a signature of the function", async () => {
-
- const sig = wrappedContract.getSignatureOfMethod("name")
+ describe('#getSignatureOfMethod()', () => {
+ it('should a signature of the function', async () => {
+ const sig = wrappedContract.getSignatureOfMethod('name')
assert(sig)
- assert(typeof sig === "string")
- assert(sig.startsWith("0x"))
+ assert(typeof sig === 'string')
+ assert(sig.startsWith('0x'))
})
})
- describe("#getEventData()", () => {
-
- it("should fail on unknown event", (done) => {
-
- wrappedContract.getEventData("crazyevent", {})
- .catch(() => {
-
- done()
- })
+ describe('#getEventData()', () => {
+ it('should fail on unknown event', done => {
+ wrappedContract.getEventData('crazyevent', {}).catch(() => {
+ done()
+ })
})
-
})
-
})
diff --git a/test/keeper/ContractEvent.test.ts b/test/keeper/ContractEvent.test.ts
index 40b5a06..c6384b9 100644
--- a/test/keeper/ContractEvent.test.ts
+++ b/test/keeper/ContractEvent.test.ts
@@ -1,12 +1,11 @@
-import { assert } from "chai"
-import { EventHandler } from "../../src/keeper/EventHandler"
-import { ContractEventSubscription } from "../../src/keeper/ContractEvent"
-import { Ocean } from "../../src/ocean/Ocean"
-import config from "../config"
-import TestContractHandler from "./TestContractHandler"
-
-describe("ContractEvent", () => {
+import { assert } from 'chai'
+import { EventHandler } from '../../src/keeper/EventHandler'
+import { ContractEventSubscription } from '../../src/keeper/ContractEvent'
+import { Ocean } from '../../src/ocean/Ocean'
+import config from '../config'
+import TestContractHandler from './TestContractHandler'
+describe('ContractEvent', () => {
let ocean: Ocean
let account: string
let eventHandler: EventHandler
@@ -18,17 +17,22 @@ describe("ContractEvent", () => {
eventHandler = new EventHandler((ocean as any).instanceConfig)
account = (await ocean.accounts.list())[0].getId()
- executeTransaction = () => ocean.keeper.dispenser.requestTokens(10, account)
+ executeTransaction = () =>
+ ocean.keeper.dispenser.requestTokens(10, account)
})
- describe("#subscribe()", () => {
- it("should listen the events", async () => {
- const event = eventHandler.getEvent(ocean.keeper.token, "Transfer", {to: account})
+ describe('#subscribe()', () => {
+ it('should listen the events', async () => {
+ const event = eventHandler.getEvent(
+ ocean.keeper.token,
+ 'Transfer',
+ { to: account }
+ )
let validResolve = false
let subscription: ContractEventSubscription
- const waitUntilEvent = new Promise((resolve) => {
- subscription = event.subscribe((events) => {
+ const waitUntilEvent = new Promise(resolve => {
+ subscription = event.subscribe(events => {
assert.isDefined(events)
assert.lengthOf(events, 2)
if (validResolve) {
@@ -37,18 +41,12 @@ describe("ContractEvent", () => {
})
})
- await Promise.all([
- executeTransaction(),
- executeTransaction(),
- ])
+ await Promise.all([executeTransaction(), executeTransaction()])
- await new Promise((_) => setTimeout(_, 2000))
+ await new Promise(_ => setTimeout(_, 2000))
validResolve = true
- await Promise.all([
- executeTransaction(),
- executeTransaction(),
- ])
+ await Promise.all([executeTransaction(), executeTransaction()])
await waitUntilEvent
@@ -56,14 +54,18 @@ describe("ContractEvent", () => {
})
})
- describe("#once()", () => {
- it("should listen only once", async () => {
+ describe('#once()', () => {
+ it('should listen only once', async () => {
const to = account
- const event = eventHandler.getEvent(ocean.keeper.token, "Transfer", {to})
+ const event = eventHandler.getEvent(
+ ocean.keeper.token,
+ 'Transfer',
+ { to }
+ )
let canBeRejected = false
const waitUntilEvent = new Promise((resolve, reject) => {
- event.once((events) => {
+ event.once(events => {
if (canBeRejected) {
reject()
}
@@ -73,7 +75,7 @@ describe("ContractEvent", () => {
await executeTransaction()
- await new Promise((_) => setTimeout(_, 2000))
+ await new Promise(_ => setTimeout(_, 2000))
canBeRejected = true
await executeTransaction()
@@ -81,13 +83,17 @@ describe("ContractEvent", () => {
await waitUntilEvent
})
- it("should get the event like a promise", async () => {
+ it('should get the event like a promise', async () => {
const to = account
- const event = eventHandler.getEvent(ocean.keeper.token, "Transfer", {to})
+ const event = eventHandler.getEvent(
+ ocean.keeper.token,
+ 'Transfer',
+ { to }
+ )
const waitUntilEvent = event.once()
- await new Promise((_) => setTimeout(_, 400))
+ await new Promise(_ => setTimeout(_, 400))
await executeTransaction()
diff --git a/test/keeper/ContractHandler.test.ts b/test/keeper/ContractHandler.test.ts
index 0d0b4c4..802903d 100644
--- a/test/keeper/ContractHandler.test.ts
+++ b/test/keeper/ContractHandler.test.ts
@@ -1,29 +1,27 @@
-import {assert} from "chai"
-import ContractHandler from "../../src/keeper/ContractHandler"
-import { Ocean } from "../../src/ocean/Ocean"
-import config from "../config"
+import { assert } from 'chai'
+import ContractHandler from '../../src/keeper/ContractHandler'
+import { Ocean } from '../../src/ocean/Ocean'
+import config from '../config'
-describe("ContractHandler", () => {
+describe('ContractHandler', () => {
let contractHandler: ContractHandler
before(async () => {
- const instanceConfig = (await Ocean.getInstance(config) as any).instanceConfig
+ const instanceConfig = ((await Ocean.getInstance(config)) as any)
+ .instanceConfig
contractHandler = new ContractHandler(instanceConfig)
})
- describe("#get()", () => {
-
- it("should load and get OceanToken correctly", async () => {
- assert(await contractHandler.get("OceanToken"))
+ describe('#get()', () => {
+ it('should load and get OceanToken correctly', async () => {
+ assert(await contractHandler.get('OceanToken'))
})
- it("should fail to load an unknown contract", (done) => {
-
- contractHandler.get("OceanXXX")
- .catch(() => {
- done()
- })
+ it('should fail to load an unknown contract', done => {
+ contractHandler.get('OceanXXX').catch(() => {
+ done()
+ })
})
})
})
diff --git a/test/keeper/DIDRegistry.test.ts b/test/keeper/DIDRegistry.test.ts
index 14204eb..cbfa7b0 100644
--- a/test/keeper/DIDRegistry.test.ts
+++ b/test/keeper/DIDRegistry.test.ts
@@ -1,67 +1,92 @@
-import {assert} from "chai"
-import DIDRegistry from "../../src/keeper/contracts/DIDRegistry"
-import Account from "../../src/ocean/Account"
-import { Ocean } from "../../src/ocean/Ocean"
-import { generateId } from "../../src/utils/GeneratorHelpers"
-import config from "../config"
-import TestContractHandler from "./TestContractHandler"
+import { assert } from 'chai'
+import DIDRegistry from '../../src/keeper/contracts/DIDRegistry'
+import Account from '../../src/ocean/Account'
+import { Ocean } from '../../src/ocean/Ocean'
+import { generateId } from '../../src/utils/GeneratorHelpers'
+import config from '../config'
+import TestContractHandler from './TestContractHandler'
let ocean: Ocean
let didRegistry: DIDRegistry
-describe("DIDRegistry", () => {
-
+describe('DIDRegistry', () => {
before(async () => {
await TestContractHandler.prepareContracts()
ocean = await Ocean.getInstance(config)
didRegistry = ocean.keeper.didRegistry
})
- describe("#registerAttribute()", () => {
-
- it("should register an attribute in a new did", async () => {
+ describe('#registerAttribute()', () => {
+ it('should register an attribute in a new did', async () => {
const ownerAccount: Account = (await ocean.accounts.list())[0]
const did = generateId()
- const data = "my nice provider, is nice"
- const receipt = await didRegistry.registerAttribute(did, `0123456789abcdef`, [], data, ownerAccount.getId())
+ const data = 'my nice provider, is nice'
+ const receipt = await didRegistry.registerAttribute(
+ did,
+ `0123456789abcdef`,
+ [],
+ data,
+ ownerAccount.getId()
+ )
assert(receipt.status)
assert(receipt.events.DIDAttributeRegistered)
})
- it("should register another attribute in the same did", async () => {
+ it('should register another attribute in the same did', async () => {
const ownerAccount: Account = (await ocean.accounts.list())[0]
const did = generateId()
{
// register the first attribute
- const data = "my nice provider, is nice"
- await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId())
+ const data = 'my nice provider, is nice'
+ await didRegistry.registerAttribute(
+ did,
+ '0123456789abcdef',
+ [],
+ data,
+ ownerAccount.getId()
+ )
}
{
// register the second attribute with the same did
- const data = "asdsad"
- const receipt = await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId())
+ const data = 'asdsad'
+ const receipt = await didRegistry.registerAttribute(
+ did,
+ '0123456789abcdef',
+ [],
+ data,
+ ownerAccount.getId()
+ )
assert.isTrue(receipt.status)
assert.isDefined(receipt.events.DIDAttributeRegistered)
}
})
-
})
- describe("#getDIDOwner()", () => {
- it("should get the owner of a did properly", async () => {
+ describe('#getDIDOwner()', () => {
+ it('should get the owner of a did properly', async () => {
const ownerAccount: Account = (await ocean.accounts.list())[0]
const did = generateId()
- const data = "my nice provider, is nice"
- await didRegistry.registerAttribute(did, "0123456789abcdef", [], data, ownerAccount.getId())
+ const data = 'my nice provider, is nice'
+ await didRegistry.registerAttribute(
+ did,
+ '0123456789abcdef',
+ [],
+ data,
+ ownerAccount.getId()
+ )
const owner = await didRegistry.getDIDOwner(did)
- assert.equal(owner, ownerAccount.getId(), `Got ${owner} but expected ${ownerAccount.getId()}`)
+ assert.equal(
+ owner,
+ ownerAccount.getId(),
+ `Got ${owner} but expected ${ownerAccount.getId()}`
+ )
})
- it("should get 0x0 for a not registered did", async () => {
- const owner = await didRegistry.getDIDOwner("1234")
- assert.equal(owner, `0x${"0".repeat(40)}`)
+ it('should get 0x0 for a not registered did', async () => {
+ const owner = await didRegistry.getDIDOwner('1234')
+ assert.equal(owner, `0x${'0'.repeat(40)}`)
})
})
})
diff --git a/test/keeper/EventHandler.test.ts b/test/keeper/EventHandler.test.ts
index 5535d43..6230f78 100644
--- a/test/keeper/EventHandler.test.ts
+++ b/test/keeper/EventHandler.test.ts
@@ -1,13 +1,12 @@
-import { assert, expect, spy, use } from "chai"
-import * as spies from "chai-spies"
-import { EventHandler } from "../../src/keeper/EventHandler"
-import { Ocean } from "../../src/ocean/Ocean"
-import config from "../config"
+import { assert, expect, spy, use } from 'chai'
+import * as spies from 'chai-spies'
+import { EventHandler } from '../../src/keeper/EventHandler'
+import { Ocean } from '../../src/ocean/Ocean'
+import config from '../config'
use(spies)
-describe("EventHandler", () => {
-
+describe('EventHandler', () => {
let ocean: Ocean
let eventHandler: EventHandler
@@ -20,20 +19,24 @@ describe("EventHandler", () => {
spy.restore()
})
- describe("#subscribe()", () => {
- it("should subscribe to an event", async () => {
+ describe('#subscribe()', () => {
+ it('should subscribe to an event', async () => {
const countBefore = eventHandler.count
const subscription = eventHandler.subscribe(() => null)
assert.isDefined(subscription)
const countAfter = eventHandler.count
- assert.equal(countBefore + 1, countAfter, "The event seems not added.")
+ assert.equal(
+ countBefore + 1,
+ countAfter,
+ 'The event seems not added.'
+ )
subscription.unsubscribe()
})
- it("should unsubscribe using the subscription", async () => {
+ it('should unsubscribe using the subscription', async () => {
const countBefore = eventHandler.count
const subscription = eventHandler.subscribe(() => null)
@@ -42,12 +45,12 @@ describe("EventHandler", () => {
subscription.unsubscribe()
const countAfter = eventHandler.count
- assert.equal(countBefore, countAfter, "The event seems not added.")
+ assert.equal(countBefore, countAfter, 'The event seems not added.')
})
})
- describe("#unsubscribe()", () => {
- it("should unsubscribe from an event", async () => {
+ describe('#unsubscribe()', () => {
+ it('should unsubscribe from an event', async () => {
const countBefore = eventHandler.count
const callback = () => null
@@ -55,25 +58,29 @@ describe("EventHandler", () => {
eventHandler.unsubscribe(callback)
const countAfter = eventHandler.count
- assert.equal(countBefore, countAfter, "The event seems not removed.")
+ assert.equal(
+ countBefore,
+ countAfter,
+ 'The event seems not removed.'
+ )
})
})
- describe("#checkBlock()", () => {
- it("should call the callback on each new block", async () => {
+ describe('#checkBlock()', () => {
+ it('should call the callback on each new block', async () => {
let blockNumber = 100000000000
const callbackSpy = spy()
- spy.on((ocean as any).web3.eth, "getBlockNumber", () => blockNumber)
+ spy.on((ocean as any).web3.eth, 'getBlockNumber', () => blockNumber)
const subscription = eventHandler.subscribe(callbackSpy)
- await new Promise((_) => setTimeout(_, 300))
+ await new Promise(_ => setTimeout(_, 300))
expect(callbackSpy).not.to.has.been.called()
blockNumber++
- await new Promise((_) => setTimeout(_, 300))
+ await new Promise(_ => setTimeout(_, 300))
expect(callbackSpy).to.has.been.called.with(blockNumber)
diff --git a/test/keeper/Keeper.test.ts b/test/keeper/Keeper.test.ts
index af16b39..52f1d6d 100644
--- a/test/keeper/Keeper.test.ts
+++ b/test/keeper/Keeper.test.ts
@@ -1,36 +1,32 @@
-import {assert} from "chai"
-import config from "../config"
-import TestContractHandler from "./TestContractHandler"
-import Keeper from "../../src/keeper/Keeper"
-import { Ocean } from "../../src/ocean/Ocean"
+import { assert } from 'chai'
+import config from '../config'
+import TestContractHandler from './TestContractHandler'
+import Keeper from '../../src/keeper/Keeper'
+import { Ocean } from '../../src/ocean/Ocean'
let keeper: Keeper
-describe("Keeper", () => {
-
+describe('Keeper', () => {
before(async () => {
await TestContractHandler.prepareContracts()
const ocean = await Ocean.getInstance(config)
keeper = ocean.keeper
})
- describe("public interface", () => {
-
- it("should have dispenser", () => {
+ describe('public interface', () => {
+ it('should have dispenser', () => {
assert(keeper.dispenser !== null)
})
- it("should have token", () => {
+ it('should have token', () => {
assert(keeper.token !== null)
})
})
- describe("#getNetworkName()", () => {
-
- it("should get development as default", async () => {
+ describe('#getNetworkName()', () => {
+ it('should get development as default', async () => {
const networkName: string = await keeper.getNetworkName()
- assert(networkName === "Development")
+ assert(networkName === 'Development')
})
-
})
})
diff --git a/test/keeper/TestContractHandler.ts b/test/keeper/TestContractHandler.ts
index 0acc6f7..46ded50 100644
--- a/test/keeper/TestContractHandler.ts
+++ b/test/keeper/TestContractHandler.ts
@@ -1,11 +1,10 @@
-import Contract from "web3-eth-contract"
-import ContractHandler from "../../src/keeper/ContractHandler"
-import Web3Provider from "../../src/keeper/Web3Provider"
-import Logger from "../../src/utils/Logger"
-import config from "../config"
+import Contract from 'web3-eth-contract'
+import ContractHandler from '../../src/keeper/ContractHandler'
+import Web3Provider from '../../src/keeper/Web3Provider'
+import Logger from '../../src/utils/Logger'
+import config from '../config'
export default class TestContractHandler extends ContractHandler {
-
public static async prepareContracts() {
const web3 = Web3Provider.getWeb3(config)
const deployerAddress = (await web3.eth.getAccounts())[0]
@@ -18,77 +17,131 @@ export default class TestContractHandler extends ContractHandler {
private static networkId: number
private static async deployContracts(deployerAddress: string) {
- Logger.log("Trying to deploy contracts")
+ Logger.log('Trying to deploy contracts')
// Libraries
- const epochLibrary = await TestContractHandler.deployContract("EpochLibrary", deployerAddress)
- const didRegistryLibrary = await TestContractHandler.deployContract("DIDRegistryLibrary", deployerAddress)
+ const epochLibrary = await TestContractHandler.deployContract(
+ 'EpochLibrary',
+ deployerAddress
+ )
+ const didRegistryLibrary = await TestContractHandler.deployContract(
+ 'DIDRegistryLibrary',
+ deployerAddress
+ )
// Contracts
- const token = await TestContractHandler.deployContract("OceanToken", deployerAddress, [deployerAddress, deployerAddress])
+ const token = await TestContractHandler.deployContract(
+ 'OceanToken',
+ deployerAddress,
+ [deployerAddress, deployerAddress]
+ )
- const dispenser = await TestContractHandler.deployContract("Dispenser", deployerAddress, [token.options.address, deployerAddress])
+ const dispenser = await TestContractHandler.deployContract(
+ 'Dispenser',
+ deployerAddress,
+ [token.options.address, deployerAddress]
+ )
// Add dispenser as Token minter
if (!token.$initialized) {
- await token.methods.addMinter(dispenser.options.address)
- .send({from: deployerAddress})
+ await token.methods
+ .addMinter(dispenser.options.address)
+ .send({ from: deployerAddress })
}
- const didRegistry = await TestContractHandler.deployContract("DIDRegistry", deployerAddress, [deployerAddress], {
- DIDRegistryLibrary: didRegistryLibrary.options.address,
- })
+ const didRegistry = await TestContractHandler.deployContract(
+ 'DIDRegistry',
+ deployerAddress,
+ [deployerAddress],
+ {
+ DIDRegistryLibrary: didRegistryLibrary.options.address
+ }
+ )
// Managers
- const templateStoreManager = await TestContractHandler.deployContract("TemplateStoreManager", deployerAddress, [
+ const templateStoreManager = await TestContractHandler.deployContract(
+ 'TemplateStoreManager',
deployerAddress,
- ])
- const conditionStoreManager = await TestContractHandler.deployContract("ConditionStoreManager", deployerAddress, [
+ [deployerAddress]
+ )
+ const conditionStoreManager = await TestContractHandler.deployContract(
+ 'ConditionStoreManager',
deployerAddress,
- ], {
- EpochLibrary: epochLibrary.options.address,
- })
- const agreementStoreManager = await TestContractHandler.deployContract("AgreementStoreManager", deployerAddress, [
- deployerAddress, conditionStoreManager.options.address, templateStoreManager.options.address, didRegistry.options.address,
- ])
+ [deployerAddress],
+ {
+ EpochLibrary: epochLibrary.options.address
+ }
+ )
+ const agreementStoreManager = await TestContractHandler.deployContract(
+ 'AgreementStoreManager',
+ deployerAddress,
+ [
+ deployerAddress,
+ conditionStoreManager.options.address,
+ templateStoreManager.options.address,
+ didRegistry.options.address
+ ]
+ )
// Conditions
- const lockRewardCondition = await TestContractHandler.deployContract("LockRewardCondition", deployerAddress, [
- deployerAddress, conditionStoreManager.options.address, token.options.address,
- ])
- const accessSecretStoreCondition = await TestContractHandler.deployContract("AccessSecretStoreCondition", deployerAddress, [
- deployerAddress, conditionStoreManager.options.address, agreementStoreManager.options.address,
- ])
+ const lockRewardCondition = await TestContractHandler.deployContract(
+ 'LockRewardCondition',
+ deployerAddress,
+ [
+ deployerAddress,
+ conditionStoreManager.options.address,
+ token.options.address
+ ]
+ )
+ const accessSecretStoreCondition = await TestContractHandler.deployContract(
+ 'AccessSecretStoreCondition',
+ deployerAddress,
+ [
+ deployerAddress,
+ conditionStoreManager.options.address,
+ agreementStoreManager.options.address
+ ]
+ )
// Conditions rewards
- const escrowReward = await TestContractHandler.deployContract("EscrowReward", deployerAddress, [
- deployerAddress, conditionStoreManager.options.address, token.options.address,
- ])
+ const escrowReward = await TestContractHandler.deployContract(
+ 'EscrowReward',
+ deployerAddress,
+ [
+ deployerAddress,
+ conditionStoreManager.options.address,
+ token.options.address
+ ]
+ )
// Templates
- await TestContractHandler.deployContract("EscrowAccessSecretStoreTemplate", deployerAddress, [
+ await TestContractHandler.deployContract(
+ 'EscrowAccessSecretStoreTemplate',
deployerAddress,
- agreementStoreManager.options.address,
- didRegistry.options.address,
- accessSecretStoreCondition.options.address,
- lockRewardCondition.options.address,
- escrowReward.options.address,
- ])
+ [
+ deployerAddress,
+ agreementStoreManager.options.address,
+ didRegistry.options.address,
+ accessSecretStoreCondition.options.address,
+ lockRewardCondition.options.address,
+ escrowReward.options.address
+ ]
+ )
}
private static async deployContract(
name: string,
from: string,
args: any[] = [],
- tokens: {[name: string]: string} = {},
- ): Promise {
+ tokens: { [name: string]: string } = {}
+ ): Promise {
const where = this.networkId
// dont redeploy if there is already something loaded
if (TestContractHandler.hasContract(name, where)) {
const contract = await ContractHandler.getContract(name, where)
if (contract.testContract) {
- return {...contract, $initialized: true}
+ return { ...contract, $initialized: true }
}
}
@@ -96,50 +149,70 @@ export default class TestContractHandler extends ContractHandler {
let contractInstance: Contract
try {
- Logger.log("Deploying", name)
+ Logger.log('Deploying', name)
const sendConfig = {
from,
gas: 3000000,
- gasPrice: 10000000000,
+ gasPrice: 10000000000
}
const artifact = require(`@oceanprotocol/keeper-contracts/artifacts/${name}.development.json`)
- const tempContract = new web3.eth.Contract(artifact.abi, artifact.address)
+ const tempContract = new web3.eth.Contract(
+ artifact.abi,
+ artifact.address
+ )
const isZos = !!tempContract.methods.initialize
Logger.debug({
- name, from, isZos, args,
+ name,
+ from,
+ isZos,
+ args,
libraries: artifact.bytecode
- .replace(/(0x)?[a-f0-9]{8}/gi, "")
- .replace(/__([^_]+)_*[0-9a-f]{2}/g, "|$1")
- .split("|")
- .splice(1),
+ .replace(/(0x)?[a-f0-9]{8}/gi, '')
+ .replace(/__([^_]+)_*[0-9a-f]{2}/g, '|$1')
+ .split('|')
+ .splice(1)
})
contractInstance = await tempContract
.deploy({
- data: TestContractHandler.replaceTokens(artifact.bytecode.toString(), tokens),
- arguments: isZos ? undefined : args,
+ data: TestContractHandler.replaceTokens(
+ artifact.bytecode.toString(),
+ tokens
+ ),
+ arguments: isZos ? undefined : args
})
.send(sendConfig)
if (isZos) {
- await contractInstance.methods.initialize(...args).send(sendConfig)
+ await contractInstance.methods
+ .initialize(...args)
+ .send(sendConfig)
}
contractInstance.testContract = true
ContractHandler.setContract(name, where, contractInstance)
// Logger.log("Deployed", name, "at", contractInstance.options.address);
} catch (err) {
- Logger.error("Deployment failed for", name, "with args", JSON.stringify(args, null, 2), err.message)
+ Logger.error(
+ 'Deployment failed for',
+ name,
+ 'with args',
+ JSON.stringify(args, null, 2),
+ err.message
+ )
throw err
}
return contractInstance
}
- private static replaceTokens(bytecode: string, tokens: {[name: string]: string}): string {
- return Object.entries(tokens)
- .reduce(
- (acc, [token, address]) => acc.replace(new RegExp(`_+${token}_+`, "g"), address.substr(2)),
- bytecode,
- )
+ private static replaceTokens(
+ bytecode: string,
+ tokens: { [name: string]: string }
+ ): string {
+ return Object.entries(tokens).reduce(
+ (acc, [token, address]) =>
+ acc.replace(new RegExp(`_+${token}_+`, 'g'), address.substr(2)),
+ bytecode
+ )
}
}
diff --git a/test/keeper/conditions/AccessSecretStoreCondition.test.ts b/test/keeper/conditions/AccessSecretStoreCondition.test.ts
index 2af214c..47040ab 100644
--- a/test/keeper/conditions/AccessSecretStoreCondition.test.ts
+++ b/test/keeper/conditions/AccessSecretStoreCondition.test.ts
@@ -1,33 +1,37 @@
-import {assert} from "chai"
-import { AccessSecretStoreCondition } from "../../../src/keeper/contracts/conditions"
-import { Ocean } from "../../../src/ocean/Ocean"
-import config from "../../config"
-import TestContractHandler from "../TestContractHandler"
+import { assert } from 'chai'
+import { AccessSecretStoreCondition } from '../../../src/keeper/contracts/conditions'
+import { Ocean } from '../../../src/ocean/Ocean'
+import config from '../../config'
+import TestContractHandler from '../TestContractHandler'
let condition: AccessSecretStoreCondition
-describe("AccessSecretStoreCondition", () => {
-
- const agreementId = `0x${"a".repeat(64)}`
- const did = `did:op:${"a".repeat(64)}`
- const address = `0x${"a".repeat(40)}`
+describe('AccessSecretStoreCondition', () => {
+ const agreementId = `0x${'a'.repeat(64)}`
+ const did = `did:op:${'a'.repeat(64)}`
+ const address = `0x${'a'.repeat(40)}`
before(async () => {
await TestContractHandler.prepareContracts()
- condition = (await Ocean.getInstance(config)).keeper.conditions.accessSecretStoreCondition
+ condition = (await Ocean.getInstance(config)).keeper.conditions
+ .accessSecretStoreCondition
})
- describe("#hashValues()", () => {
- it("should hash the values", async () => {
+ describe('#hashValues()', () => {
+ it('should hash the values', async () => {
const hash = await condition.hashValues(did, address)
assert.match(hash, /^0x[a-f0-9]{64}$/i)
- assert.equal(hash, "0x1abbd7e58bc32bff739ee1e756a4108882322f2ec939d5e2f251e6b8424947fb", "The hash is not the expected.")
+ assert.equal(
+ hash,
+ '0x1abbd7e58bc32bff739ee1e756a4108882322f2ec939d5e2f251e6b8424947fb',
+ 'The hash is not the expected.'
+ )
})
})
- describe("#generateId()", () => {
- it("should generate an ID", async () => {
+ describe('#generateId()', () => {
+ it('should generate an ID', async () => {
const hash = await condition.hashValues(did, address)
const id = await condition.generateId(agreementId, hash)
diff --git a/test/keeper/conditions/EscrowReward.test.ts b/test/keeper/conditions/EscrowReward.test.ts
index e883131..57bcac1 100644
--- a/test/keeper/conditions/EscrowReward.test.ts
+++ b/test/keeper/conditions/EscrowReward.test.ts
@@ -1,18 +1,17 @@
-import {assert} from "chai"
-import { EscrowReward } from "../../../src/keeper/contracts/conditions"
-import { Ocean } from "../../../src/ocean/Ocean"
-import config from "../../config"
-import TestContractHandler from "../TestContractHandler"
+import { assert } from 'chai'
+import { EscrowReward } from '../../../src/keeper/contracts/conditions'
+import { Ocean } from '../../../src/ocean/Ocean'
+import config from '../../config'
+import TestContractHandler from '../TestContractHandler'
let condition: EscrowReward
-describe("EscrowReward", () => {
-
- const agreementId = `0x${"a".repeat(64)}`
- const did = `0x${"a".repeat(64)}`
+describe('EscrowReward', () => {
+ const agreementId = `0x${'a'.repeat(64)}`
+ const did = `0x${'a'.repeat(64)}`
const amount = 15
- const publisher = `0x${"a".repeat(40)}`
- const consumer = `0x${"b".repeat(40)}`
+ const publisher = `0x${'a'.repeat(40)}`
+ const consumer = `0x${'b'.repeat(40)}`
let lockCondition
let releaseCondition
@@ -22,21 +21,41 @@ describe("EscrowReward", () => {
await TestContractHandler.prepareContracts()
condition = keeper.conditions.escrowReward
- lockCondition = await keeper.conditions.lockRewardCondition.generateIdHash(agreementId, publisher, amount)
- releaseCondition = await keeper.conditions.accessSecretStoreCondition.generateIdHash(agreementId, did, consumer)
+ lockCondition = await keeper.conditions.lockRewardCondition.generateIdHash(
+ agreementId,
+ publisher,
+ amount
+ )
+ releaseCondition = await keeper.conditions.accessSecretStoreCondition.generateIdHash(
+ agreementId,
+ did,
+ consumer
+ )
})
- describe("#hashValues()", () => {
- it("should hash the values", async () => {
- const hash = await condition.hashValues(amount, consumer, publisher, lockCondition, releaseCondition)
+ describe('#hashValues()', () => {
+ it('should hash the values', async () => {
+ const hash = await condition.hashValues(
+ amount,
+ consumer,
+ publisher,
+ lockCondition,
+ releaseCondition
+ )
assert.match(hash, /^0x[a-f0-9]{64}$/i)
})
})
- describe("#generateId()", () => {
- it("should generate an ID", async () => {
- const hash = await condition.hashValues(amount, consumer, publisher, lockCondition, releaseCondition)
+ describe('#generateId()', () => {
+ it('should generate an ID', async () => {
+ const hash = await condition.hashValues(
+ amount,
+ consumer,
+ publisher,
+ lockCondition,
+ releaseCondition
+ )
const id = await condition.generateId(agreementId, hash)
assert.match(id, /^0x[a-f0-9]{64}$/i)
diff --git a/test/keeper/conditions/LockRewardCondition.test.ts b/test/keeper/conditions/LockRewardCondition.test.ts
index 32b7639..6b70668 100644
--- a/test/keeper/conditions/LockRewardCondition.test.ts
+++ b/test/keeper/conditions/LockRewardCondition.test.ts
@@ -1,33 +1,37 @@
-import {assert} from "chai"
-import { LockRewardCondition } from "../../../src/keeper/contracts/conditions"
-import { Ocean } from "../../../src/ocean/Ocean"
-import config from "../../config"
-import TestContractHandler from "../TestContractHandler"
+import { assert } from 'chai'
+import { LockRewardCondition } from '../../../src/keeper/contracts/conditions'
+import { Ocean } from '../../../src/ocean/Ocean'
+import config from '../../config'
+import TestContractHandler from '../TestContractHandler'
let condition: LockRewardCondition
-describe("LockRewardCondition", () => {
-
- const agreementId = `0x${"a".repeat(64)}`
- const address = `0x${"a".repeat(40)}`
+describe('LockRewardCondition', () => {
+ const agreementId = `0x${'a'.repeat(64)}`
+ const address = `0x${'a'.repeat(40)}`
const amount = 15
before(async () => {
await TestContractHandler.prepareContracts()
- condition = (await Ocean.getInstance(config)).keeper.conditions.lockRewardCondition
+ condition = (await Ocean.getInstance(config)).keeper.conditions
+ .lockRewardCondition
})
- describe("#hashValues()", () => {
- it("should hash the values", async () => {
+ describe('#hashValues()', () => {
+ it('should hash the values', async () => {
const hash = await condition.hashValues(address, amount)
assert.match(hash, /^0x[a-f0-9]{64}$/i)
- assert.equal(hash, "0x2543c2ea4b9403bb3e5df1145c70731454748e72a37acc80d025f85e03267973", "The hash is not the expected.")
+ assert.equal(
+ hash,
+ '0x2543c2ea4b9403bb3e5df1145c70731454748e72a37acc80d025f85e03267973',
+ 'The hash is not the expected.'
+ )
})
})
- describe("#generateId()", () => {
- it("should generate an ID", async () => {
+ describe('#generateId()', () => {
+ it('should generate an ID', async () => {
const hash = await condition.hashValues(address, amount)
const id = await condition.generateId(agreementId, hash)
diff --git a/test/keeper/templates/EscrowAccessSecretStoreTemplate.test.ts b/test/keeper/templates/EscrowAccessSecretStoreTemplate.test.ts
index 90baaed..1518423 100644
--- a/test/keeper/templates/EscrowAccessSecretStoreTemplate.test.ts
+++ b/test/keeper/templates/EscrowAccessSecretStoreTemplate.test.ts
@@ -1,18 +1,16 @@
-import {assert} from "chai"
-import { EscrowAccessSecretStoreTemplate } from "../../../src/keeper/contracts/templates"
-import config from "../../config"
-import TestContractHandler from "../TestContractHandler"
-import { Ocean } from "../../../src/ocean/Ocean"
+import { assert } from 'chai'
+import { EscrowAccessSecretStoreTemplate } from '../../../src/keeper/contracts/templates'
+import config from '../../config'
+import TestContractHandler from '../TestContractHandler'
+import { Ocean } from '../../../src/ocean/Ocean'
let condition: EscrowAccessSecretStoreTemplate
-describe("EscrowAccessSecretStoreTemplate", () => {
-
+describe('EscrowAccessSecretStoreTemplate', () => {
before(async () => {
const ocean: Ocean = await Ocean.getInstance(config)
await TestContractHandler.prepareContracts()
condition = ocean.keeper.templates.escrowAccessSecretStoreTemplate
-
})
// describe("#hashValues()", () => {
@@ -23,5 +21,4 @@ describe("EscrowAccessSecretStoreTemplate", () => {
// assert.match(hash, /^0x[a-f0-9]{64}$/i)
// })
// })
-
})
diff --git a/test/mocks/Aquarius.mock.ts b/test/mocks/Aquarius.mock.ts
index 0dc9e2d..5fcead6 100644
--- a/test/mocks/Aquarius.mock.ts
+++ b/test/mocks/Aquarius.mock.ts
@@ -1,13 +1,12 @@
-import { Aquarius } from "../../src/aquarius/Aquarius"
-import { DDO } from "../../src/ddo/DDO"
-import DID from "../../src/ocean/DID"
+import { Aquarius } from '../../src/aquarius/Aquarius'
+import { DDO } from '../../src/ddo/DDO'
+import DID from '../../src/ocean/DID'
const ddoStore: Map = new Map()
export default class AquariusMock extends Aquarius {
-
public async getAccessUrl(accessToken: any, payload: any): Promise {
- return "http://test/test"
+ return 'http://test/test'
}
public async storeDDO(ddo: DDO): Promise {
diff --git a/test/mocks/Brizo.mock.ts b/test/mocks/Brizo.mock.ts
index fd58dbd..da8f96e 100644
--- a/test/mocks/Brizo.mock.ts
+++ b/test/mocks/Brizo.mock.ts
@@ -1,10 +1,13 @@
-import { Brizo } from "../../src/brizo/Brizo"
+import { Brizo } from '../../src/brizo/Brizo'
export default class BrizoMock extends Brizo {
-
- public async initializeServiceAgreement(did: string, serviceAgreementId: string, serviceDefinitionId: string,
- signature: string, consumerPublicKey: string): Promise {
-
+ public async initializeServiceAgreement(
+ did: string,
+ serviceAgreementId: string,
+ serviceDefinitionId: string,
+ signature: string,
+ consumerPublicKey: string
+ ): Promise {
return true
}
}
diff --git a/test/mocks/ContractBase.Mock.ts b/test/mocks/ContractBase.Mock.ts
index 00a7b65..21bc9b3 100644
--- a/test/mocks/ContractBase.Mock.ts
+++ b/test/mocks/ContractBase.Mock.ts
@@ -1,4 +1,4 @@
-import ContractBase from "../../src/keeper/contracts/ContractBase"
+import ContractBase from '../../src/keeper/contracts/ContractBase'
export default class ContractBaseMock extends ContractBase {
public async initMock(config: any) {
diff --git a/test/mocks/SecretStore.mock.ts b/test/mocks/SecretStore.mock.ts
index 8b6ca6e..b96577d 100644
--- a/test/mocks/SecretStore.mock.ts
+++ b/test/mocks/SecretStore.mock.ts
@@ -1,16 +1,13 @@
-import SecretStore from "@oceanprotocol/secret-store-client"
+import SecretStore from '@oceanprotocol/secret-store-client'
export default class SecretStoreMock extends SecretStore {
-
public async encryptDocument(documentId, document: any) {
-
- return "0x283asdgahd1t371t23h"
+ return '0x283asdgahd1t371t23h'
}
public async decryptDocument(documentId, encryptedDocument: any) {
-
return {
- doc: "test",
+ doc: 'test'
}
}
}
diff --git a/test/mocks/WebServiceConnector.mock.ts b/test/mocks/WebServiceConnector.mock.ts
index f5f57fb..1a7ac55 100644
--- a/test/mocks/WebServiceConnector.mock.ts
+++ b/test/mocks/WebServiceConnector.mock.ts
@@ -1,15 +1,13 @@
-import WebServiceConnector from "../../src/utils/WebServiceConnector"
+import WebServiceConnector from '../../src/utils/WebServiceConnector'
// @ts-ignore
export default class WebServiceConnectorMock extends WebServiceConnector {
-
constructor(private returnData: any) {
super()
}
// @ts-ignore
private async fetch(url, opts): Promise {
-
return new Promise((resolve, reject) => {
resolve({
ok: true,
@@ -17,8 +15,10 @@ export default class WebServiceConnectorMock extends WebServiceConnector {
return this.returnData ? this.returnData : {}
},
text: () => {
- return this.returnData ? JSON.stringify(this.returnData.toString()) : ""
- },
+ return this.returnData
+ ? JSON.stringify(this.returnData.toString())
+ : ''
+ }
})
})
}
diff --git a/test/ocean/Account.test.ts b/test/ocean/Account.test.ts
index 7897ab0..031acd0 100644
--- a/test/ocean/Account.test.ts
+++ b/test/ocean/Account.test.ts
@@ -1,32 +1,29 @@
-import {assert} from "chai"
-import Web3Provider from "../../src/keeper/Web3Provider"
-import Account from "../../src/ocean/Account"
-import { Ocean } from "../../src/ocean/Ocean"
-import config from "../config"
-import TestContractHandler from "../keeper/TestContractHandler"
+import { assert } from 'chai'
+import Web3Provider from '../../src/keeper/Web3Provider'
+import Account from '../../src/ocean/Account'
+import { Ocean } from '../../src/ocean/Ocean'
+import config from '../config'
+import TestContractHandler from '../keeper/TestContractHandler'
let ocean: Ocean
let accounts: Account[]
-describe("Account", () => {
-
+describe('Account', () => {
before(async () => {
await TestContractHandler.prepareContracts()
ocean = await Ocean.getInstance(config)
accounts = await ocean.accounts.list()
})
- describe("#getOceanBalance()", () => {
-
- it("should get initial ocean balance", async () => {
-
+ describe('#getOceanBalance()', () => {
+ it('should get initial ocean balance', async () => {
const balance = await accounts[8].getOceanBalance()
assert.equal(0, balance, `Expected 0 got ${balance}`)
})
- it("should get the correct balance", async () => {
- const amount: number = 100
+ it('should get the correct balance', async () => {
+ const amount = 100
const account: Account = accounts[0]
const initialBalance = await account.getOceanBalance()
await account.requestTokens(amount)
@@ -36,43 +33,40 @@ describe("Account", () => {
})
})
- describe("#getEthBalance()", () => {
-
- it("should get initial ether balance", async () => {
-
+ describe('#getEthBalance()', () => {
+ it('should get initial ether balance', async () => {
const account: Account = accounts[9]
const balance = await account.getEtherBalance()
const web3 = Web3Provider.getWeb3()
- assert(Number(web3.utils.toWei("100", "ether")) === balance,
- `ether did not match ${balance}`)
+ assert(
+ Number(web3.utils.toWei('100', 'ether')) === balance,
+ `ether did not match ${balance}`
+ )
})
})
- describe("#getBalance()", () => {
-
- it("should get initial balance", async () => {
-
+ describe('#getBalance()', () => {
+ it('should get initial balance', async () => {
const account: Account = accounts[9]
const balance = await account.getBalance()
const web3 = Web3Provider.getWeb3()
- assert(Number(web3.utils.toWei("100", "ether")) === balance.eth,
- `ether did not match ${balance.eth}`)
- assert(0 === balance.ocn, `tokens did not match ${balance.ocn}`)
+ assert(
+ Number(web3.utils.toWei('100', 'ether')) === balance.eth,
+ `ether did not match ${balance.eth}`
+ )
+ assert(balance.ocn === 0, `tokens did not match ${balance.ocn}`)
})
})
- describe("#requestTokens()", () => {
-
- it("should return the amount of tokens granted", async () => {
-
- const tokens = "500"
+ describe('#requestTokens()', () => {
+ it('should return the amount of tokens granted', async () => {
+ const tokens = '500'
const account: Account = accounts[0]
const tokensGranted: string = await account.requestTokens(tokens)
assert.equal(tokensGranted, tokens)
})
})
-
})
diff --git a/test/ocean/DID.test.ts b/test/ocean/DID.test.ts
index 75d98b1..c391973 100644
--- a/test/ocean/DID.test.ts
+++ b/test/ocean/DID.test.ts
@@ -1,28 +1,25 @@
-import * as assert from "assert"
-import DID from "../../src/ocean/DID"
+import * as assert from 'assert'
+import DID from '../../src/ocean/DID'
-describe("DID", () => {
-
- describe("#generate()", () => {
- it("should generate a new did", () => {
+describe('DID', () => {
+ describe('#generate()', () => {
+ it('should generate a new did', () => {
const did: DID = DID.generate()
assert(did)
})
})
- describe("#parse()", () => {
- it("should parse a valid did", () => {
-
- const id = "a".repeat(64)
+ describe('#parse()', () => {
+ it('should parse a valid did', () => {
+ const id = 'a'.repeat(64)
const did: DID = DID.parse(`did:op:${id}`)
assert(did)
assert(did.getId() === id, did.getId())
})
- it("should throw if prefix does not match", (done) => {
-
- const id = "1234"
+ it('should throw if prefix does not match', done => {
+ const id = '1234'
try {
const did: DID = DID.parse(`did:xxx:${id}`)
assert(!did)
@@ -31,9 +28,8 @@ describe("DID", () => {
}
})
- it("should throw if id does not match", (done) => {
-
- const id = "xyz"
+ it('should throw if id does not match', done => {
+ const id = 'xyz'
try {
const did: DID = DID.parse(`did:op:${id}`)
assert(!did)
@@ -43,20 +39,18 @@ describe("DID", () => {
})
})
- describe("#getDid()", () => {
- it("should return the full did", () => {
-
+ describe('#getDid()', () => {
+ it('should return the full did', () => {
const did: DID = DID.generate()
assert(did)
- assert(did.getDid().startsWith("did:op:"))
+ assert(did.getDid().startsWith('did:op:'))
})
})
- describe("#getDid()", () => {
- it("should return only the id part of the did", () => {
-
- const id = "a".repeat(64)
+ describe('#getDid()', () => {
+ it('should return only the id part of the did', () => {
+ const id = 'a'.repeat(64)
const did: DID = DID.parse(`did:op:${id}`)
assert(did)
diff --git a/test/ocean/Ocean.test.ts b/test/ocean/Ocean.test.ts
index 283b99d..a022c42 100644
--- a/test/ocean/Ocean.test.ts
+++ b/test/ocean/Ocean.test.ts
@@ -1,62 +1,59 @@
-import { assert, spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import { SearchQuery } from "../../src/aquarius/Aquarius"
-import Account from "../../src/ocean/Account"
-import { Ocean } from "../../src/ocean/Ocean"
-import config from "../config"
-import TestContractHandler from "../keeper/TestContractHandler"
+import { SearchQuery } from '../../src/aquarius/Aquarius'
+import Account from '../../src/ocean/Account'
+import { Ocean } from '../../src/ocean/Ocean'
+import config from '../config'
+import TestContractHandler from '../keeper/TestContractHandler'
use(spies)
let ocean: Ocean
-describe("Ocean", () => {
-
+describe('Ocean', () => {
before(async () => {
await TestContractHandler.prepareContracts()
ocean = await Ocean.getInstance(config)
})
beforeEach(async () => {
- spy.on(ocean.utils.signature, "signText", () => `0x${"a".repeat(130)}`)
+ spy.on(ocean.utils.signature, 'signText', () => `0x${'a'.repeat(130)}`)
})
afterEach(() => {
spy.restore()
})
- describe("#getInstance()", () => {
- it("should get an instance of cean", async () => {
-
+ describe('#getInstance()', () => {
+ it('should get an instance of cean', async () => {
const oceanInstance: Ocean = await Ocean.getInstance(config)
assert(oceanInstance)
})
})
- describe("#getAccounts()", () => {
- it("should list accounts", async () => {
-
+ describe('#getAccounts()', () => {
+ it('should list accounts', async () => {
const accs: Account[] = await ocean.accounts.list()
- assert(10 === accs.length)
- assert(0 === (await accs[5].getBalance()).ocn)
- assert("string" === typeof accs[0].getId())
+ assert(accs.length === 10)
+ assert((await accs[5].getBalance()).ocn === 0)
+ assert(typeof accs[0].getId() === 'string')
})
})
- describe("#searchAssets()", () => {
- it("should search for assets", async () => {
+ describe('#searchAssets()', () => {
+ it('should search for assets', async () => {
const query = {
offset: 100,
page: 1,
query: {
- value: 1,
+ value: 1
},
sort: {
- value: 1,
+ value: 1
},
- text: "Office",
+ text: 'Office'
} as SearchQuery
const assets = await ocean.assets.query(query)
@@ -65,9 +62,9 @@ describe("Ocean", () => {
})
})
- describe("#searchAssetsByText()", () => {
- it("should search for assets", async () => {
- const text = "office"
+ describe('#searchAssetsByText()', () => {
+ it('should search for assets', async () => {
+ const text = 'office'
const assets = await ocean.assets.search(text)
assert(assets)
diff --git a/test/ocean/OceanAccounts.test.ts b/test/ocean/OceanAccounts.test.ts
index 7cad14b..f403286 100644
--- a/test/ocean/OceanAccounts.test.ts
+++ b/test/ocean/OceanAccounts.test.ts
@@ -1,15 +1,14 @@
-import { assert, /*expect,*/ spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import config from "../config"
-import Account from "../../src/ocean/Account"
-import { Ocean } from "../../src/ocean/Ocean"
-import { OceanAccounts } from "../../src/ocean/OceanAccounts"
+import config from '../config'
+import Account from '../../src/ocean/Account'
+import { Ocean } from '../../src/ocean/Ocean'
+import { OceanAccounts } from '../../src/ocean/OceanAccounts'
use(spies)
-describe("OceanAccounts", () => {
-
+describe('OceanAccounts', () => {
let oceanAccounts: OceanAccounts
before(async () => {
@@ -20,28 +19,28 @@ describe("OceanAccounts", () => {
spy.restore()
})
- describe("#list()", () => {
- it("should return the list of accounts", async () => {
+ describe('#list()', () => {
+ it('should return the list of accounts', async () => {
const accounts = await oceanAccounts.list()
- accounts.map((account) => assert.instanceOf(account, Account))
+ accounts.map(account => assert.instanceOf(account, Account))
})
})
- describe("#balance()", () => {
- it("should return the balance of an account", async () => {
+ describe('#balance()', () => {
+ it('should return the balance of an account', async () => {
const [account] = await oceanAccounts.list()
- spy.on(account, "getBalance", () => ({eth: 1, ocn: 5}))
+ spy.on(account, 'getBalance', () => ({ eth: 1, ocn: 5 }))
const balance = await oceanAccounts.balance(account)
- assert.deepEqual(balance, {eth: 1, ocn: 5})
+ assert.deepEqual(balance, { eth: 1, ocn: 5 })
})
})
- describe("#requestTokens()", () => {
- it("should return the balance of an account", async () => {
+ describe('#requestTokens()', () => {
+ it('should return the balance of an account', async () => {
const [account] = await oceanAccounts.list()
- spy.on(account, "requestTokens", () => 10)
+ spy.on(account, 'requestTokens', () => 10)
const success = await oceanAccounts.requestTokens(account, 10)
assert.isTrue(success)
diff --git a/test/ocean/OceanAuth.test.ts b/test/ocean/OceanAuth.test.ts
index bf53feb..5f07e78 100644
--- a/test/ocean/OceanAuth.test.ts
+++ b/test/ocean/OceanAuth.test.ts
@@ -1,15 +1,14 @@
-import { assert, expect, spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, expect, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import config from "../config"
-import Account from "../../src/ocean/Account"
-import { Ocean } from "../../src/ocean/Ocean"
-import { OceanAuth } from "../../src/ocean/OceanAuth"
+import config from '../config'
+import Account from '../../src/ocean/Account'
+import { Ocean } from '../../src/ocean/Ocean'
+import { OceanAuth } from '../../src/ocean/OceanAuth'
use(spies)
-describe("OceanAuth", () => {
-
+describe('OceanAuth', () => {
let oceanAuth: OceanAuth
let account: Account
@@ -23,8 +22,8 @@ describe("OceanAuth", () => {
spy.restore()
})
- describe("#get()", () => {
- it("should return the token for a account", async () => {
+ describe('#get()', () => {
+ it('should return the token for a account', async () => {
const token = await oceanAuth.get(account)
assert.match(token, /^0x[a-f0-9]{130}-[0-9]{0,14}/i)
@@ -32,8 +31,8 @@ describe("OceanAuth", () => {
})
// Not valid using providers without support for `personal_ecRecover`
- xdescribe("#check()", () => {
- it("should return the account of a signature", async () => {
+ xdescribe('#check()', () => {
+ it('should return the account of a signature', async () => {
const token = await oceanAuth.get(account)
const address = await oceanAuth.check(token)
@@ -41,21 +40,25 @@ describe("OceanAuth", () => {
assert.equal(address, account.getId())
})
- it("should return empty address if the token is expired", async () => {
+ it('should return empty address if the token is expired', async () => {
const token = [
- "0x0cfe59ce5c35461728b4126431096e4e021a842ca1f679532c537be5f895a3607e498",
- "f2cc22f787f9c7c8a967c346d717ef50ccb9f0af418d87a86dad899e6d61b-1234567890",
- ].join("")
+ '0x0cfe59ce5c35461728b4126431096e4e021a842ca1f679532c537be5f895a3607e498',
+ 'f2cc22f787f9c7c8a967c346d717ef50ccb9f0af418d87a86dad899e6d61b-1234567890'
+ ].join('')
const address = await oceanAuth.check(token)
- assert.equal(address, `0x${"0".repeat(40)}`)
+ assert.equal(address, `0x${'0'.repeat(40)}`)
})
})
- describe("#store()", () => {
- it("should sign and store the token", async () => {
- const writeTokenSpy = spy.on(oceanAuth as any, "writeToken", () => {})
+ describe('#store()', () => {
+ it('should sign and store the token', async () => {
+ const writeTokenSpy = spy.on(
+ oceanAuth as any,
+ 'writeToken',
+ () => {}
+ )
await oceanAuth.store(account)
@@ -63,19 +66,19 @@ describe("OceanAuth", () => {
})
})
- describe("#restore()", () => {
- it("should return a stored token", async () => {
- spy.on(oceanAuth as any, "readToken", () => "token")
- spy.on(oceanAuth as any, "check", () => account.getId())
+ describe('#restore()', () => {
+ it('should return a stored token', async () => {
+ spy.on(oceanAuth as any, 'readToken', () => 'token')
+ spy.on(oceanAuth as any, 'check', () => account.getId())
const token = await oceanAuth.restore(account)
- assert.equal(token, "token")
+ assert.equal(token, 'token')
})
- it("should not return values if there is any error", async () => {
- spy.on(oceanAuth as any, "readToken", () => "token")
- spy.on(oceanAuth as any, "check", () => "0x...")
+ it('should not return values if there is any error', async () => {
+ spy.on(oceanAuth as any, 'readToken', () => 'token')
+ spy.on(oceanAuth as any, 'check', () => '0x...')
const token = await oceanAuth.restore(account)
@@ -83,17 +86,17 @@ describe("OceanAuth", () => {
})
})
- describe("#isStored()", () => {
- it("should know if the token is stored", async () => {
- spy.on(oceanAuth as any, "restore", () => account.getId())
+ describe('#isStored()', () => {
+ it('should know if the token is stored', async () => {
+ spy.on(oceanAuth as any, 'restore', () => account.getId())
const isStored = await oceanAuth.isStored(account)
assert.isTrue(isStored)
})
- it("should know if the token is not stored", async () => {
- spy.on(oceanAuth as any, "restore", () => undefined)
+ it('should know if the token is not stored', async () => {
+ spy.on(oceanAuth as any, 'restore', () => undefined)
const isStored = await oceanAuth.isStored(account)
diff --git a/test/ocean/OceanSecretStore.test.ts b/test/ocean/OceanSecretStore.test.ts
index 00204aa..b6d02d7 100644
--- a/test/ocean/OceanSecretStore.test.ts
+++ b/test/ocean/OceanSecretStore.test.ts
@@ -1,20 +1,19 @@
-import { assert, expect, spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, expect, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import Account from "../../src/ocean/Account"
-import { Ocean } from "../../src/ocean/Ocean"
-import { OceanSecretStore } from "../../src/ocean/OceanSecretStore"
-import config from "../config"
+import Account from '../../src/ocean/Account'
+import { Ocean } from '../../src/ocean/Ocean'
+import { OceanSecretStore } from '../../src/ocean/OceanSecretStore'
+import config from '../config'
use(spies)
-describe("OceanSecretStore", () => {
-
+describe('OceanSecretStore', () => {
let oceanSecretStore: OceanSecretStore
let accounts: Account[]
let ocean: Ocean
- const did = "a".repeat(64)
+ const did = 'a'.repeat(64)
before(async () => {
ocean = await Ocean.getInstance(config)
@@ -26,15 +25,23 @@ describe("OceanSecretStore", () => {
spy.restore()
})
- describe("#encrypt()", () => {
- it("should encrypt a content", async () => {
- const secretStoreEncryptSpy = spy.on(ocean.brizo, "encrypt", () => "encryptedResult")
+ describe('#encrypt()', () => {
+ it('should encrypt a content', async () => {
+ const secretStoreEncryptSpy = spy.on(
+ ocean.brizo,
+ 'encrypt',
+ () => 'encryptedResult'
+ )
- const result = await oceanSecretStore.encrypt(did, "test", accounts[0])
+ const result = await oceanSecretStore.encrypt(
+ did,
+ 'test',
+ accounts[0]
+ )
- expect(secretStoreEncryptSpy).to.have.been.called.with(did, "test")
+ expect(secretStoreEncryptSpy).to.have.been.called.with(did, 'test')
- assert.equal(result, "encryptedResult", "Result doesn't match")
+ assert.equal(result, 'encryptedResult', "Result doesn't match")
})
})
})
diff --git a/test/ocean/utils/SignatureUtils.test.ts b/test/ocean/utils/SignatureUtils.test.ts
index 8891ed3..3751e36 100644
--- a/test/ocean/utils/SignatureUtils.test.ts
+++ b/test/ocean/utils/SignatureUtils.test.ts
@@ -1,17 +1,16 @@
-import { assert, expect, spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, expect, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import config from "../../config"
+import config from '../../config'
-import { Ocean } from "../../../src/ocean/Ocean"
+import { Ocean } from '../../../src/ocean/Ocean'
use(spies)
-describe("SignatureUtils", () => {
-
- const publicKey = `0x${"a".repeat(40)}`
- const text = "0123456789abcde"
- const signature = `0x${"a".repeat(130)}`
+describe('SignatureUtils', () => {
+ const publicKey = `0x${'a'.repeat(40)}`
+ const text = '0123456789abcde'
+ const signature = `0x${'a'.repeat(130)}`
let web3
let ocean: Ocean
@@ -24,33 +23,48 @@ describe("SignatureUtils", () => {
spy.restore()
})
- describe("#signText", () => {
+ describe('#signText', () => {
let personalSignSpy
beforeEach(() => {
- personalSignSpy = spy.on(web3.eth.personal, "sign", () => signature)
+ personalSignSpy = spy.on(web3.eth.personal, 'sign', () => signature)
})
- it("should sign a text as expected", async () => {
+ it('should sign a text as expected', async () => {
const signed = await ocean.utils.signature.signText(text, publicKey)
assert.equal(signed, signature)
expect(personalSignSpy).to.have.been.called.with(text, publicKey)
})
- it("should sign a text as expected using password", async () => {
- const signed = await ocean.utils.signature.signText(text, publicKey, "test")
+ it('should sign a text as expected using password', async () => {
+ const signed = await ocean.utils.signature.signText(
+ text,
+ publicKey,
+ 'test'
+ )
assert.equal(signed, signature)
- expect(personalSignSpy).to.have.been.called.with(text, publicKey, "test")
+ expect(personalSignSpy).to.have.been.called.with(
+ text,
+ publicKey,
+ 'test'
+ )
})
})
- describe("#verifyText", () => {
- it("should recover the privateKey of a signed message", async () => {
- const personalRecoverSpy = spy.on(web3.eth.personal, "ecRecover", () => publicKey)
+ describe('#verifyText', () => {
+ it('should recover the privateKey of a signed message', async () => {
+ const personalRecoverSpy = spy.on(
+ web3.eth.personal,
+ 'ecRecover',
+ () => publicKey
+ )
- const verifiedPublicKey = await ocean.utils.signature.verifyText(text, signature)
+ const verifiedPublicKey = await ocean.utils.signature.verifyText(
+ text,
+ signature
+ )
assert.equal(publicKey, verifiedPublicKey)
expect(personalRecoverSpy).to.have.been.called.with(text, signature)
diff --git a/test/utils/ConversionTypeHelpers.test.ts b/test/utils/ConversionTypeHelpers.test.ts
index 8ef7a35..3fbf19b 100644
--- a/test/utils/ConversionTypeHelpers.test.ts
+++ b/test/utils/ConversionTypeHelpers.test.ts
@@ -1,43 +1,48 @@
-import { assert } from "chai"
-import { zeroX, noZeroX, didPrefixed, noDidPrefixed } from "../../src/utils/ConversionTypeHelpers"
+import { assert } from 'chai'
+import {
+ zeroX,
+ noZeroX,
+ didPrefixed,
+ noDidPrefixed
+} from '../../src/utils/ConversionTypeHelpers'
-describe("ConversionTypeHelpers", () => {
- describe("#zeroXTransformer()", () => {
+describe('ConversionTypeHelpers', () => {
+ describe('#zeroXTransformer()', () => {
it("should return the input if it's not hex value", async () => {
- const result1 = zeroX("Test 1")
- const result2 = noZeroX("Test 2")
- assert.equal(result1, "Test 1")
- assert.equal(result2, "Test 2")
+ const result1 = zeroX('Test 1')
+ const result2 = noZeroX('Test 2')
+ assert.equal(result1, 'Test 1')
+ assert.equal(result2, 'Test 2')
})
- it("should return the value with 0x prefix", async () => {
- const result1 = zeroX("0x1234")
- const result2 = zeroX("1234")
- assert.equal(result1, "0x1234")
- assert.equal(result2, "0x1234")
+ it('should return the value with 0x prefix', async () => {
+ const result1 = zeroX('0x1234')
+ const result2 = zeroX('1234')
+ assert.equal(result1, '0x1234')
+ assert.equal(result2, '0x1234')
})
- it("should return the value without 0x prefix", async () => {
- const result1 = noZeroX("0x1234")
- const result2 = noZeroX("1234")
- assert.equal(result1, "1234")
- assert.equal(result2, "1234")
+ it('should return the value without 0x prefix', async () => {
+ const result1 = noZeroX('0x1234')
+ const result2 = noZeroX('1234')
+ assert.equal(result1, '1234')
+ assert.equal(result2, '1234')
})
})
- describe("#didTransformer()", () => {
- const did = "a".repeat(64)
+ describe('#didTransformer()', () => {
+ const did = 'a'.repeat(64)
it("should return the input if it's not valid", async () => {
- const result1 = didPrefixed("Test 1")
- const result2 = noDidPrefixed("Test 2")
- const result3 = noDidPrefixed("Test 3")
- assert.equal(result1, "Test 1")
- assert.equal(result2, "Test 2")
- assert.equal(result3, "Test 3")
+ const result1 = didPrefixed('Test 1')
+ const result2 = noDidPrefixed('Test 2')
+ const result3 = noDidPrefixed('Test 3')
+ assert.equal(result1, 'Test 1')
+ assert.equal(result2, 'Test 2')
+ assert.equal(result3, 'Test 3')
})
- it("should return the value with did:op: prefix", async () => {
+ it('should return the value with did:op: prefix', async () => {
const result1 = didPrefixed(`0x${did}`)
const result2 = didPrefixed(did)
const result3 = didPrefixed(`did:op:${did}`)
@@ -46,7 +51,7 @@ describe("ConversionTypeHelpers", () => {
assert.equal(result3, `did:op:${did}`)
})
- it("should return the value without did:op: prefix", async () => {
+ it('should return the value without did:op: prefix', async () => {
const result1 = noDidPrefixed(`0x${did}`)
const result2 = noDidPrefixed(did)
const result3 = noDidPrefixed(`did:op:${did}`)
diff --git a/test/utils/GeneratorHelpers.test.ts b/test/utils/GeneratorHelpers.test.ts
index 71cf934..a822a34 100644
--- a/test/utils/GeneratorHelpers.test.ts
+++ b/test/utils/GeneratorHelpers.test.ts
@@ -1,30 +1,24 @@
-import { assert } from "chai"
-import { generateId } from "../../src/utils/GeneratorHelpers"
-
-describe("GeneratorHelpers", () => {
-
- describe("#generateId()", () => {
-
- it("should generate an ID", async () => {
+import { assert } from 'chai'
+import { generateId } from '../../src/utils/GeneratorHelpers'
+describe('GeneratorHelpers', () => {
+ describe('#generateId()', () => {
+ it('should generate an ID', async () => {
const id = generateId()
assert(id)
})
- it("should generate an ID that is 64 chars long", async () => {
-
+ it('should generate an ID that is 64 chars long', async () => {
const id: string = generateId()
assert.equal(id.length, 64)
})
- it("should not contain -", async () => {
-
+ it('should not contain -', async () => {
const id: string = generateId()
assert.match(id, /^[a-f0-9]+$/i)
})
- it("should generate an ID that is 130 chars long", async () => {
-
+ it('should generate an ID that is 130 chars long', async () => {
const id: string = generateId(130)
assert.equal(id.length, 130)
})
diff --git a/test/utils/SubscribableObserver.test.ts b/test/utils/SubscribableObserver.test.ts
index 2681f05..97c52f4 100644
--- a/test/utils/SubscribableObserver.test.ts
+++ b/test/utils/SubscribableObserver.test.ts
@@ -1,23 +1,21 @@
-import { assert, expect, spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, expect, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import { SubscribableObserver} from "../../src/utils/SubscribableObserver"
+import { SubscribableObserver } from '../../src/utils/SubscribableObserver'
use(spies)
-describe("SubscribableObserver", () => {
-
- describe("#subscribe()", () => {
-
- it("should be able to add a subcription", async () => {
+describe('SubscribableObserver', () => {
+ describe('#subscribe()', () => {
+ it('should be able to add a subcription', async () => {
const observer = new SubscribableObserver()
const subscription = observer.subscribe()
assert.isDefined(subscription.unsubscribe)
- assert.typeOf(subscription.unsubscribe, "function")
+ assert.typeOf(subscription.unsubscribe, 'function')
})
- it("should be able to unsubscribe", async () => {
+ it('should be able to unsubscribe', async () => {
const observer = new SubscribableObserver()
const subscription = observer.subscribe()
@@ -25,49 +23,46 @@ describe("SubscribableObserver", () => {
})
})
- describe("#next()", () => {
-
- it("should be able to emit next value", async () => {
+ describe('#next()', () => {
+ it('should be able to emit next value', async () => {
const onNextSpy = spy()
const observer = new SubscribableObserver()
observer.subscribe(onNextSpy)
- observer.next("test")
- expect(onNextSpy).to.has.been.called.with("test")
+ observer.next('test')
+ expect(onNextSpy).to.has.been.called.with('test')
- observer.next("test")
+ observer.next('test')
expect(onNextSpy).to.has.been.called.exactly(2)
})
})
- describe("#complete()", () => {
-
- it("should be able to complete", async () => {
+ describe('#complete()', () => {
+ it('should be able to complete', async () => {
const onCompleteSpy = spy()
const observer = new SubscribableObserver()
observer.subscribe(undefined, onCompleteSpy)
- observer.complete("test")
- expect(onCompleteSpy).to.has.been.called.with("test")
+ observer.complete('test')
+ expect(onCompleteSpy).to.has.been.called.with('test')
- observer.complete("test")
+ observer.complete('test')
expect(onCompleteSpy).to.has.been.called.exactly(1)
assert.isTrue(observer.completed)
})
})
- describe("#error()", () => {
-
- it("should be able to emit a error", async () => {
+ describe('#error()', () => {
+ it('should be able to emit a error', async () => {
const onErrorSpy = spy()
const observer = new SubscribableObserver()
observer.subscribe(undefined, undefined, onErrorSpy)
- observer.error("test")
- expect(onErrorSpy).to.has.been.called.with("test")
+ observer.error('test')
+ expect(onErrorSpy).to.has.been.called.with('test')
- observer.error("test")
+ observer.error('test')
expect(onErrorSpy).to.has.been.called.exactly(1)
assert.isTrue(observer.completed)
diff --git a/test/utils/SubscribablePromise.test.ts b/test/utils/SubscribablePromise.test.ts
index 5948a2f..82778d6 100644
--- a/test/utils/SubscribablePromise.test.ts
+++ b/test/utils/SubscribablePromise.test.ts
@@ -1,61 +1,56 @@
-import { assert, expect, spy, use } from "chai"
-import * as spies from "chai-spies"
+import { assert, expect, spy, use } from 'chai'
+import * as spies from 'chai-spies'
-import { SubscribablePromise } from "../../src/utils/SubscribablePromise"
+import { SubscribablePromise } from '../../src/utils/SubscribablePromise'
use(spies)
-describe("SubscribablePromise", () => {
-
- it("should work", async () => {
+describe('SubscribablePromise', () => {
+ it('should work', async () => {
const subscribible = new SubscribablePromise(() => {})
assert.isDefined(subscribible)
})
- describe("#subscribe()", () => {
-
- it("should return a subscription", async () => {
+ describe('#subscribe()', () => {
+ it('should return a subscription', async () => {
const subscribible = new SubscribablePromise(() => {})
const subscription = subscribible.subscribe(() => {})
assert.isDefined(subscription)
assert.isDefined(subscription.unsubscribe)
- 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 subscribible = new SubscribablePromise((observer) => {
- setTimeout(() => observer.next("test"), 10)
- setTimeout(() => observer.next("test"), 20)
+ const subscribible = new SubscribablePromise(observer => {
+ setTimeout(() => observer.next('test'), 10)
+ setTimeout(() => observer.next('test'), 20)
})
subscribible.subscribe(onNextSpy)
setTimeout(() => {
- expect(onNextSpy).to.has.been.called.with("test")
+ expect(onNextSpy).to.has.been.called.with('test')
expect(onNextSpy).to.has.been.called.exactly(2)
done()
}, 100)
})
})
- describe("#then()", () => {
-
- it("should resolve", (done) => {
+ describe('#then()', () => {
+ it('should resolve', done => {
const onCompleteSpy = spy()
const onFinallySpy = spy()
- const subscribible = new SubscribablePromise((observer) => {
- setTimeout(() => observer.next("test"), 10)
- setTimeout(() => observer.complete("test"), 20)
+ const subscribible = new SubscribablePromise(observer => {
+ setTimeout(() => observer.next('test'), 10)
+ setTimeout(() => observer.complete('test'), 20)
})
- subscribible
- .then(onCompleteSpy)
- .finally(onFinallySpy)
+ subscribible.then(onCompleteSpy).finally(onFinallySpy)
setTimeout(() => {
- expect(onCompleteSpy).to.has.been.called.with("test")
+ expect(onCompleteSpy).to.has.been.called.with('test')
expect(onCompleteSpy).to.has.been.called.exactly(1)
expect(onFinallySpy).to.has.been.called.exactly(1)
done()
@@ -63,22 +58,19 @@ describe("SubscribablePromise", () => {
})
})
- describe("#error()", () => {
-
- it("should catch the error", (done) => {
+ describe('#error()', () => {
+ it('should catch the error', done => {
const onErrorSpy = spy()
const onFinallySpy = spy()
- const subscribible = new SubscribablePromise((observer) => {
- setTimeout(() => observer.next("test"), 10)
- setTimeout(() => observer.error("test"), 20)
+ const subscribible = new SubscribablePromise(observer => {
+ setTimeout(() => observer.next('test'), 10)
+ setTimeout(() => observer.error('test'), 20)
})
- subscribible
- .catch(onErrorSpy)
- .finally(onFinallySpy)
+ subscribible.catch(onErrorSpy).finally(onFinallySpy)
setTimeout(() => {
- expect(onErrorSpy).to.has.been.called.with("test")
+ expect(onErrorSpy).to.has.been.called.with('test')
expect(onErrorSpy).to.has.been.called.exactly(1)
expect(onFinallySpy).to.has.been.called.exactly(1)
done()
@@ -86,40 +78,38 @@ 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 subscribible = new SubscribablePromise((observer) => {
- setTimeout(() => observer.next("test"), 10)
- setTimeout(() => observer.next("test"), 20)
- setTimeout(() => observer.complete("completed"), 30)
+ const subscribible = new SubscribablePromise(observer => {
+ setTimeout(() => observer.next('test'), 10)
+ setTimeout(() => observer.next('test'), 20)
+ setTimeout(() => observer.complete('completed'), 30)
})
- const result = await subscribible
- .next(onNextSpy)
+ const result = await subscribible.next(onNextSpy)
- expect(onNextSpy).to.has.been.called.with("test")
+ expect(onNextSpy).to.has.been.called.with('test')
expect(onNextSpy).to.has.been.called.exactly(2)
- assert.equal(result, "completed")
+ assert.equal(result, 'completed')
})
- 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 subscribible = new SubscribablePromise(async (observer) => {
- await new Promise((resolve) => setTimeout(resolve, 10))
- observer.next("test")
- await new Promise((resolve) => setTimeout(resolve, 10))
- observer.next("test")
- await new Promise((resolve) => setTimeout(resolve, 10))
- return "completed"
+ const subscribible = new SubscribablePromise(async observer => {
+ await new Promise(resolve => setTimeout(resolve, 10))
+ observer.next('test')
+ await new Promise(resolve => setTimeout(resolve, 10))
+ observer.next('test')
+ await new Promise(resolve => setTimeout(resolve, 10))
+ return 'completed'
})
- const result = await subscribible
- .next(onNextSpy)
+ const result = await subscribible.next(onNextSpy)
- expect(onNextSpy).to.has.been.called.with("test")
+ expect(onNextSpy).to.has.been.called.with('test')
expect(onNextSpy).to.has.been.called.exactly(2)
- assert.equal(result, "completed")
+ assert.equal(result, 'completed')
})
})
diff --git a/tsconfig.json b/tsconfig.json
index 1bdc8b5..e81d391 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,12 +2,7 @@
"compilerOptions": {
"resolveJsonModule": true,
"moduleResolution": "node",
- "lib": [
- "es2017",
- "es6",
- "es7",
- "dom"
- ],
+ "lib": ["es2017", "es6", "es7", "dom"],
"declaration": true,
"module": "commonjs",
"target": "es5",
@@ -18,15 +13,8 @@
"outDir": "./dist/node/",
"rootDir": "./src/",
"sourceMap": true,
- "typeRoots": [
- "node_modules/@types"
- ]
+ "typeRoots": ["node_modules/@types"]
},
- "include": [
- "src/**/*"
- ],
- "exclude": [
- "node_modules",
- "**/*.test.ts"
- ]
+ "include": ["src/**/*"],
+ "exclude": ["node_modules", "**/*.test.ts"]
}
diff --git a/webpack.common.js b/webpack.common.js
index c75d3a3..278f5b0 100644
--- a/webpack.common.js
+++ b/webpack.common.js
@@ -10,10 +10,10 @@ module.exports = {
noEmitOnErrors: true
},
node: {
- fs: 'empty',
+ fs: 'empty'
},
resolve: {
extensions: ['.js'],
- modules: ['node_modules'],
- },
+ modules: ['node_modules']
+ }
}
diff --git a/webpack.config.js b/webpack.config.js
index 935a7af..623eb92 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -8,11 +8,11 @@ const { outputs } = require('./webpack.parts.js')
// '[libraryTarget]': [file extension]
const OUTPUT_MAPPING = {
- 'amd': 'amd',
- 'commonjs': 'cjs',
- 'commonjs2': 'cjs2',
- 'umd': 'umd',
- 'window': 'window',
+ amd: 'amd',
+ commonjs: 'cjs',
+ commonjs2: 'cjs2',
+ umd: 'umd',
+ window: 'window'
}
const OVERRIDES = {
diff --git a/webpack.development.js b/webpack.development.js
index d4beb8b..319c222 100644
--- a/webpack.development.js
+++ b/webpack.development.js
@@ -8,11 +8,11 @@ module.exports = {
minimizer: [
new UglifyJsPlugin({
test: /vendor/,
- sourceMap: false,
+ sourceMap: false
}),
new UglifyJsPlugin({
test: /^((?!(vendor)).)*.js$/,
- sourceMap: true,
+ sourceMap: true
})
],
splitChunks: {
@@ -23,6 +23,6 @@ module.exports = {
chunks: 'all'
}
}
- },
- },
+ }
+ }
}
diff --git a/webpack.parts.js b/webpack.parts.js
index 796a5e0..31977a6 100644
--- a/webpack.parts.js
+++ b/webpack.parts.js
@@ -10,7 +10,7 @@ const AddVendorsPlugin = require('./plugins/add-vendors-plugin')
const paths = {
entry: path.resolve(__dirname, './dist/node/squid.js'),
- bundle: path.resolve(__dirname, 'dist/browser'),
+ bundle: path.resolve(__dirname, 'dist/browser')
}
const outputs = (base, env, mapping, overrides) => {
@@ -36,9 +36,7 @@ const outputs = (base, env, mapping, overrides) => {
libraryTarget: target,
path: paths.bundle
},
- plugins: [
- new AddVendorsPlugin(`${library}.${extension}.${ext}`)
- ]
+ plugins: [new AddVendorsPlugin(`${library}.${extension}.${ext}`)]
}
collection.push(merge(base, environment, compiled, overrides))
diff --git a/webpack.production.js b/webpack.production.js
index 4b82041..0a1ef3d 100644
--- a/webpack.production.js
+++ b/webpack.production.js
@@ -1,5 +1,5 @@
'use strict'
module.exports = {
- devtool: 'source-map',
+ devtool: 'source-map'
}