2020-01-21 22:09:32 +01:00
|
|
|
import { assert } from 'chai'
|
|
|
|
|
|
|
|
import { config } from '../config'
|
2020-01-28 18:00:06 +01:00
|
|
|
import { Ocean, Account, DDO, MetaData, ComputeJobStatus } from '../../src' // @oceanprotocol/squid
|
2020-01-27 16:50:33 +01:00
|
|
|
import { getMetadata, getComputeServiceExample } from '../utils'
|
2020-01-21 22:09:32 +01:00
|
|
|
|
|
|
|
describe('Compute', () => {
|
|
|
|
let ocean: Ocean
|
|
|
|
let account: Account
|
|
|
|
let ddoAsset: DDO
|
|
|
|
let ddoAlgorithm: DDO
|
2020-01-27 15:59:26 +01:00
|
|
|
let agreementId: string
|
2020-01-21 22:09:32 +01:00
|
|
|
|
|
|
|
const metadataAsset = getMetadata()
|
|
|
|
const metadataAlgorithm = getMetadata(0, 'algorithm')
|
2020-01-27 16:50:33 +01:00
|
|
|
const computeServiceExample = getComputeServiceExample()
|
2020-01-21 22:09:32 +01:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
;[account] = await ocean.accounts.list()
|
2020-01-27 19:14:12 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
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 {}
|
2020-01-27 15:59:26 +01:00
|
|
|
|
2020-01-27 19:14:12 +01:00
|
|
|
assert.isDefined(agreementId)
|
|
|
|
assert.deepEqual(steps, [0, 1, 2, 3])
|
2020-01-21 22:09:32 +01:00
|
|
|
})
|
|
|
|
|
2020-01-27 15:59:26 +01:00
|
|
|
it('should start a compute job', async () => {
|
2020-01-21 22:09:32 +01:00
|
|
|
const response = await ocean.compute.start(account, agreementId, ddoAlgorithm.id)
|
|
|
|
|
2020-01-28 18:00:06 +01:00
|
|
|
assert.equal(response.status, ComputeJobStatus.Started)
|
2020-01-21 22:09:32 +01:00
|
|
|
})
|
|
|
|
})
|