1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/integration/ocean/Compute.test.ts
Matthias Kretschmann 40754ca46a
new ocean.utils.services
* refactor all .order() methods to use one single method
* remove `index` parameter from ocean.assets.order()
* update compute test flow
2020-01-27 19:14:12 +01:00

68 lines
2.1 KiB
TypeScript

import { assert } from 'chai'
import { config } from '../config'
import { Ocean, Account, DDO, MetaData } from '../../src' // @oceanprotocol/squid
import { getMetadata, getComputeServiceExample } from '../utils'
describe('Compute', () => {
let ocean: Ocean
let account: Account
let ddoAsset: DDO
let ddoAlgorithm: DDO
let agreementId: string
const metadataAsset = getMetadata()
const metadataAlgorithm = getMetadata(0, 'algorithm')
const computeServiceExample = getComputeServiceExample()
before(async () => {
ocean = await Ocean.getInstance(config)
;[account] = await ocean.accounts.list()
})
it('should authenticate the consumer account', async () => {
await account.authenticate()
})
it('should publish a dataset and an algorithm', async () => {
const stepsAsset = []
ddoAsset = await ocean.assets
.create(metadataAsset as MetaData, account, [computeServiceExample])
.next(step => stepsAsset.push(step))
assert.instanceOf(ddoAsset, DDO)
assert.deepEqual(stepsAsset, [0, 1, 2, 3, 4, 5, 6, 7])
const stepsAlgorithm = []
ddoAlgorithm = await ocean.assets
.create(metadataAlgorithm as MetaData, account)
.next(step => stepsAlgorithm.push(step))
assert.instanceOf(ddoAlgorithm, DDO)
assert.deepEqual(stepsAlgorithm, [0, 1, 2, 3, 4, 5, 6, 7])
})
it('should order the compute service', async () => {
const steps = []
try {
await account.requestTokens(
+computeServiceExample.attributes.main.price *
10 ** -(await ocean.keeper.token.decimals())
)
agreementId = await ocean.compute
.order(account, ddoAsset.id)
.next(step => steps.push(step))
} catch {}
assert.isDefined(agreementId)
assert.deepEqual(steps, [0, 1, 2, 3])
})
it('should start a compute job', async () => {
const response = await ocean.compute.start(account, agreementId, ddoAlgorithm.id)
assert.equal(response.status, 1)
})
})