mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
fix compute unit tests
* completely mock ocean.brizo.compute
This commit is contained in:
parent
09c2f9f818
commit
e37420dabf
111
package-lock.json
generated
111
package-lock.json
generated
@ -385,6 +385,42 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
|
||||||
"integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ=="
|
"integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ=="
|
||||||
},
|
},
|
||||||
|
"@sinonjs/commons": {
|
||||||
|
"version": "1.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.0.tgz",
|
||||||
|
"integrity": "sha512-qbk9AP+cZUsKdW1GJsBpxPKFmCJ0T8swwzVje3qFd+AkQb74Q/tiuzrdfFg8AD2g5HH/XbE/I8Uc1KYHVYWfhg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"type-detect": "4.0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@sinonjs/formatio": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-asIdlLFrla/WZybhm0C8eEzaDNNrzymiTqHMeJl6zPW2881l3uuVRpm0QlRQEjqYWv6CcKMGYME3LbrLJsORBw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@sinonjs/commons": "^1",
|
||||||
|
"@sinonjs/samsam": "^4.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@sinonjs/samsam": {
|
||||||
|
"version": "4.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-4.2.2.tgz",
|
||||||
|
"integrity": "sha512-z9o4LZUzSD9Hl22zV38aXNykgFeVj8acqfFabCY6FY83n/6s/XwNJyYYldz6/9lBJanpno9h+oL6HTISkviweA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@sinonjs/commons": "^1.6.0",
|
||||||
|
"lodash.get": "^4.4.2",
|
||||||
|
"type-detect": "^4.0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@sinonjs/text-encoding": {
|
||||||
|
"version": "0.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz",
|
||||||
|
"integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@szmarczak/http-timer": {
|
"@szmarczak/http-timer": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz",
|
||||||
@ -858,6 +894,12 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/sinon": {
|
||||||
|
"version": "7.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-7.5.1.tgz",
|
||||||
|
"integrity": "sha512-EZQUP3hSZQyTQRfiLqelC9NMWd1kqLcmQE0dMiklxBkgi84T+cHOhnKpgk4NnOWpGX863yE6+IaGnOXUNFqDnQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@typescript-eslint/eslint-plugin": {
|
"@typescript-eslint/eslint-plugin": {
|
||||||
"version": "2.12.0",
|
"version": "2.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.12.0.tgz",
|
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.12.0.tgz",
|
||||||
@ -8192,6 +8234,12 @@
|
|||||||
"object.assign": "^4.1.0"
|
"object.assign": "^4.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"just-extend": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"keccak": {
|
"keccak": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/keccak/-/keccak-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/keccak/-/keccak-2.0.0.tgz",
|
||||||
@ -8544,6 +8592,15 @@
|
|||||||
"chalk": "^2.4.2"
|
"chalk": "^2.4.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lolex": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/lolex/-/lolex-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-h4hmjAvHTmd+25JSwrtTIuwbKdwg5NzZVRMLn9saij4SZaepCrTCxPr35H/3bjwfMJtN+t3CX8672UIkglz28A==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@sinonjs/commons": "^1.7.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"loose-envify": {
|
"loose-envify": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
||||||
@ -9263,6 +9320,37 @@
|
|||||||
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
|
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"nise": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/nise/-/nise-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-fYcH9y0drBGSoi88kvhpbZEsenX58Yr+wOJ4/Mi1K4cy+iGP/a73gNoyNhu5E9QxPdgTlVChfIaAlnyOy/gHUA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@sinonjs/commons": "^1.7.0",
|
||||||
|
"@sinonjs/formatio": "^4.0.1",
|
||||||
|
"@sinonjs/text-encoding": "^0.7.1",
|
||||||
|
"just-extend": "^4.0.2",
|
||||||
|
"lolex": "^5.0.1",
|
||||||
|
"path-to-regexp": "^1.7.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"isarray": {
|
||||||
|
"version": "0.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||||
|
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"path-to-regexp": {
|
||||||
|
"version": "1.8.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz",
|
||||||
|
"integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"isarray": "0.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node-environment-flags": {
|
"node-environment-flags": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz",
|
||||||
@ -11761,6 +11849,29 @@
|
|||||||
"resolved": "https://registry.npmjs.org/simple-mime/-/simple-mime-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/simple-mime/-/simple-mime-0.1.0.tgz",
|
||||||
"integrity": "sha1-lfUXxPRm18/1YacfydqyWW6p7y4="
|
"integrity": "sha1-lfUXxPRm18/1YacfydqyWW6p7y4="
|
||||||
},
|
},
|
||||||
|
"sinon": {
|
||||||
|
"version": "8.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/sinon/-/sinon-8.1.1.tgz",
|
||||||
|
"integrity": "sha512-E+tWr3acRdoe1nXbHMu86SSqA1WGM7Yw3jZRLvlCMnXwTHP8lgFFVn5BnKnF26uc5SfZ3D7pA9sN7S3Y2jG4Ew==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@sinonjs/commons": "^1.7.0",
|
||||||
|
"@sinonjs/formatio": "^4.0.1",
|
||||||
|
"@sinonjs/samsam": "^4.2.2",
|
||||||
|
"diff": "^4.0.2",
|
||||||
|
"lolex": "^5.1.2",
|
||||||
|
"nise": "^3.0.1",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"diff": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"slash": {
|
"slash": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
"@types/mocha": "^5.2.7",
|
"@types/mocha": "^5.2.7",
|
||||||
"@types/node": "^13.1.0",
|
"@types/node": "^13.1.0",
|
||||||
"@types/node-fetch": "^2.5.4",
|
"@types/node-fetch": "^2.5.4",
|
||||||
|
"@types/sinon": "^7.5.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.12.0",
|
"@typescript-eslint/eslint-plugin": "^2.12.0",
|
||||||
"@typescript-eslint/parser": "^2.12.0",
|
"@typescript-eslint/parser": "^2.12.0",
|
||||||
"auto-changelog": "^1.16.2",
|
"auto-changelog": "^1.16.2",
|
||||||
@ -85,6 +86,7 @@
|
|||||||
"nyc": "^15.0.0",
|
"nyc": "^15.0.0",
|
||||||
"ora": "^4.0.2",
|
"ora": "^4.0.2",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
|
"sinon": "^8.1.1",
|
||||||
"source-map-support": "^0.5.16",
|
"source-map-support": "^0.5.16",
|
||||||
"ts-node": "^8.5.4",
|
"ts-node": "^8.5.4",
|
||||||
"typedoc": "^0.16.8",
|
"typedoc": "^0.16.8",
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import { Brizo } from '../../src/brizo/Brizo'
|
|
||||||
|
|
||||||
export default class BrizoMock extends Brizo {
|
|
||||||
public async initializeServiceAgreement(
|
|
||||||
did: string,
|
|
||||||
serviceAgreementId: string,
|
|
||||||
index: number,
|
|
||||||
signature: string,
|
|
||||||
consumerPublicKey: string
|
|
||||||
): Promise<any> {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +1,102 @@
|
|||||||
import { assert, spy, use } from 'chai'
|
import { assert } from 'chai'
|
||||||
import spies from 'chai-spies'
|
import sinon from 'sinon'
|
||||||
|
|
||||||
import { Ocean } from '../../src/ocean/Ocean'
|
import { Ocean } from '../../src/ocean/Ocean'
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
import { Account } from '../../src/squid'
|
import { Account } from '../../src/squid'
|
||||||
import { OceanCompute, ComputeJobStatus } from '../../src/ocean/OceanCompute'
|
import { OceanCompute, ComputeJobStatus } from '../../src/ocean/OceanCompute'
|
||||||
|
import TestIdGenerator from '../TestIdGenerator'
|
||||||
use(spies)
|
|
||||||
|
|
||||||
const responsify = async data => ({
|
|
||||||
ok: true,
|
|
||||||
json: () => Promise.resolve(data)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('OceanCompute', () => {
|
describe('OceanCompute', () => {
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
let account: Account
|
let account: Account
|
||||||
let compute: OceanCompute
|
let compute: OceanCompute
|
||||||
|
let agreementId: string
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
;[account] = await ocean.accounts.list()
|
;[account] = await ocean.accounts.list()
|
||||||
compute = ocean.compute // eslint-disable-line prefer-destructuring
|
compute = ocean.compute // eslint-disable-line prefer-destructuring
|
||||||
|
agreementId = TestIdGenerator.generatePrefixedId()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
spy.restore()
|
sinon.reset()
|
||||||
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#start()', () => {
|
describe('#start()', () => {
|
||||||
it('should start a new job', async () => {
|
it('should start a new job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'post', () => responsify({ jobId: 'my-job-id' }))
|
sinon.stub(ocean.brizo, 'compute').returns({ jobId: 'my-job-id' } as any)
|
||||||
|
const response = await compute.start(account, agreementId, 'did:op:0xxx')
|
||||||
const response = await compute.start(account, 'xxx', 'xxx')
|
|
||||||
assert(response.jobId === 'my-job-id')
|
assert(response.jobId === 'my-job-id')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#stop()', () => {
|
describe('#stop()', () => {
|
||||||
it('should stop a job', async () => {
|
it('should stop a job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'put', () =>
|
sinon
|
||||||
responsify({ status: ComputeJobStatus.Completed })
|
.stub(ocean.brizo, 'compute')
|
||||||
)
|
.returns({ status: ComputeJobStatus.Completed } as any)
|
||||||
|
|
||||||
const response = await compute.stop(account, 'xxx', 'xxx')
|
const response = await compute.stop(account, agreementId, 'xxx')
|
||||||
assert(response.status === ComputeJobStatus.Completed)
|
assert(response.status === ComputeJobStatus.Completed)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#restart()', () => {
|
describe('#restart()', () => {
|
||||||
it('should restart a job', async () => {
|
it('should restart a job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'put', () => responsify({ status: 6 }))
|
sinon
|
||||||
spy.on(ocean.utils.fetch, 'post', () => responsify({ jobId: 'my-job-id' }))
|
.stub(ocean.brizo, 'compute')
|
||||||
|
.returns({ status: ComputeJobStatus.Started, jobId: 'my-job-id' } as any)
|
||||||
|
|
||||||
const response = await compute.restart(account, 'xxx', 'xxx')
|
const response = await compute.restart(account, agreementId, 'xxx')
|
||||||
assert(response.jobId === 'my-job-id')
|
assert(response.jobId === 'my-job-id')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#delete()', () => {
|
describe('#delete()', () => {
|
||||||
it('should delete a job', async () => {
|
it('should delete a job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'delete', () =>
|
sinon
|
||||||
responsify({ status: ComputeJobStatus.Deleted })
|
.stub(ocean.brizo, 'compute')
|
||||||
)
|
.returns({ status: ComputeJobStatus.Deleted } as any)
|
||||||
|
|
||||||
const response = await compute.delete(account, 'xxx', 'xxx')
|
const response = await compute.delete(account, agreementId, 'xxx')
|
||||||
assert(response.status === ComputeJobStatus.Deleted)
|
assert(response.status === ComputeJobStatus.Deleted)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#status()', () => {
|
describe('#status()', () => {
|
||||||
it('should get the status of one job', async () => {
|
it('should get the status of one job', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'get', () =>
|
sinon
|
||||||
responsify([{ status: ComputeJobStatus.Started }])
|
.stub(ocean.brizo, 'compute')
|
||||||
)
|
.returns([{ status: ComputeJobStatus.Started }] as any)
|
||||||
|
|
||||||
const response = await compute.status(account, 'xxx', 'xxx')
|
const response = await compute.status(account, agreementId, 'xxx')
|
||||||
assert(response.length === 1)
|
assert(response.length === 1)
|
||||||
assert(response[0].status === ComputeJobStatus.Started)
|
assert(response[0].status === ComputeJobStatus.Started)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should get the status of multiple jobs', async () => {
|
it('should get the status of multiple jobs', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'get', () =>
|
sinon
|
||||||
responsify([
|
.stub(ocean.brizo, 'compute')
|
||||||
|
.returns([
|
||||||
{ status: ComputeJobStatus.Started },
|
{ status: ComputeJobStatus.Started },
|
||||||
{ status: ComputeJobStatus.Started }
|
{ status: ComputeJobStatus.Started }
|
||||||
])
|
] as any)
|
||||||
)
|
|
||||||
|
|
||||||
const response = await compute.status(account, 'xxx')
|
const response = await compute.status(account, agreementId)
|
||||||
assert(response.length === 2)
|
assert(response.length === 2)
|
||||||
assert(response[0].status === ComputeJobStatus.Started)
|
assert(response[0].status === ComputeJobStatus.Started)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should get all jobs for one owner', async () => {
|
it('should get all jobs for one owner', async () => {
|
||||||
spy.on(ocean.utils.fetch, 'get', () =>
|
sinon
|
||||||
responsify([
|
.stub(ocean.brizo, 'compute')
|
||||||
|
.returns([
|
||||||
{ status: ComputeJobStatus.Started },
|
{ status: ComputeJobStatus.Started },
|
||||||
{ status: ComputeJobStatus.Started }
|
{ status: ComputeJobStatus.Started }
|
||||||
])
|
] as any)
|
||||||
)
|
|
||||||
|
|
||||||
const response = await compute.status(account)
|
const response = await compute.status(account)
|
||||||
assert(response.length === 2)
|
assert(response.length === 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user