2020-01-21 22:09:32 +01:00
|
|
|
import { assert } from 'chai'
|
|
|
|
|
|
|
|
import { config } from '../config'
|
2020-01-31 00:15:55 +01:00
|
|
|
import { Ocean, Account, DDO, MetaData, ComputeJobStatus } from '../../../src' // @oceanprotocol/squid
|
2020-01-31 13:09:37 +01:00
|
|
|
import { getMetadata, createComputeService } from '../utils'
|
|
|
|
import { ServiceCompute } from '../../../src/ddo/Service'
|
2020-01-21 22:09:32 +01:00
|
|
|
|
2020-01-29 20:24:28 +01:00
|
|
|
const metadataAsset = getMetadata()
|
|
|
|
const metadataAlgorithm = getMetadata(0, 'algorithm')
|
|
|
|
|
2020-01-21 22:09:32 +01:00
|
|
|
describe('Compute', () => {
|
|
|
|
let ocean: Ocean
|
|
|
|
let account: Account
|
2020-01-27 15:59:26 +01:00
|
|
|
let agreementId: string
|
2020-01-29 20:24:28 +01:00
|
|
|
let dataset: DDO
|
|
|
|
let algorithm: DDO
|
2020-01-31 13:09:37 +01:00
|
|
|
let computeService: ServiceCompute
|
2020-01-21 22:09:32 +01:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
;[account] = await ocean.accounts.list()
|
2020-01-31 13:09:37 +01:00
|
|
|
computeService = await createComputeService(
|
|
|
|
ocean,
|
|
|
|
account,
|
|
|
|
'1000',
|
|
|
|
metadataAsset.main.datePublished
|
|
|
|
)
|
2020-01-27 19:14:12 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should authenticate the consumer account', async () => {
|
|
|
|
await account.authenticate()
|
|
|
|
})
|
|
|
|
|
2020-01-29 20:24:28 +01:00
|
|
|
it('should publish a dataset with a compute service object', async () => {
|
2020-01-27 19:14:12 +01:00
|
|
|
const stepsAsset = []
|
2020-01-31 13:09:37 +01:00
|
|
|
|
2020-01-29 20:24:28 +01:00
|
|
|
dataset = await ocean.assets
|
2020-01-31 13:09:37 +01:00
|
|
|
.create(metadataAsset as MetaData, account, [computeService])
|
2020-01-27 19:14:12 +01:00
|
|
|
.next(step => stepsAsset.push(step))
|
|
|
|
|
2020-01-29 20:24:28 +01:00
|
|
|
assert.instanceOf(dataset, DDO)
|
2020-01-31 13:09:37 +01:00
|
|
|
assert.isDefined(
|
|
|
|
dataset.findServiceByType('compute'),
|
|
|
|
`DDO compute service doesn't exist`
|
|
|
|
)
|
2020-01-27 19:14:12 +01:00
|
|
|
assert.deepEqual(stepsAsset, [0, 1, 2, 3, 4, 5, 6, 7])
|
2020-01-29 20:24:28 +01:00
|
|
|
})
|
2020-01-27 19:14:12 +01:00
|
|
|
|
2020-01-29 20:24:28 +01:00
|
|
|
it('should publish an algorithm', async () => {
|
2020-01-27 19:14:12 +01:00
|
|
|
const stepsAlgorithm = []
|
2020-01-29 20:24:28 +01:00
|
|
|
algorithm = await ocean.assets
|
2020-01-27 19:14:12 +01:00
|
|
|
.create(metadataAlgorithm as MetaData, account)
|
|
|
|
.next(step => stepsAlgorithm.push(step))
|
|
|
|
|
2020-01-29 20:24:28 +01:00
|
|
|
assert.instanceOf(algorithm, DDO)
|
2020-01-27 19:14:12 +01:00
|
|
|
assert.deepEqual(stepsAlgorithm, [0, 1, 2, 3, 4, 5, 6, 7])
|
|
|
|
})
|
|
|
|
|
2020-01-29 20:24:28 +01:00
|
|
|
it('should order the compute service of the dataset', async () => {
|
2020-01-27 19:14:12 +01:00
|
|
|
const steps = []
|
|
|
|
try {
|
|
|
|
await account.requestTokens(
|
2020-01-31 13:09:37 +01:00
|
|
|
+computeService.attributes.main.price *
|
2020-01-27 19:14:12 +01:00
|
|
|
10 ** -(await ocean.keeper.token.decimals())
|
|
|
|
)
|
|
|
|
|
|
|
|
agreementId = await ocean.compute
|
2020-01-29 20:24:28 +01:00
|
|
|
.order(account, dataset.id)
|
2020-01-27 19:14:12 +01:00
|
|
|
.next(step => steps.push(step))
|
2020-01-27 15:59:26 +01:00
|
|
|
|
2020-01-31 13:09:37 +01:00
|
|
|
assert.isDefined(agreementId)
|
|
|
|
assert.deepEqual(steps, [0, 1, 2, 3])
|
|
|
|
} catch {}
|
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-29 20:24:28 +01:00
|
|
|
const response = await ocean.compute.start(account, agreementId, algorithm.id)
|
2020-01-21 22:09:32 +01:00
|
|
|
|
2020-01-28 18:00:06 +01:00
|
|
|
assert.equal(response.status, ComputeJobStatus.Started)
|
2020-01-21 22:09:32 +01:00
|
|
|
})
|
|
|
|
})
|