mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
97 lines
3.0 KiB
TypeScript
97 lines
3.0 KiB
TypeScript
import { assert } from 'chai'
|
|
|
|
import { config } from '../config'
|
|
import { Ocean, Account, DDO, MetaData, ComputeJobStatus, Config } from '../../../src'
|
|
import { getMetadata, createComputeService } from '../utils'
|
|
import { ServiceCompute } from '../../../src/ddo/Service'
|
|
|
|
const metadataAsset = getMetadata()
|
|
const metadataAlgorithm = getMetadata(0, 'algorithm')
|
|
|
|
const customConfig: Config = {
|
|
...config,
|
|
// nodeUri: 'https://nile.dev-ocean.com',
|
|
// aquariusUri: 'https://aquarius.nile.dev-ocean.com',
|
|
// brizoUri: 'http://89.46.156.10:8030',
|
|
// secretStoreUri: 'https://secret-store.nile.dev-ocean.com',
|
|
// brizoAddress: '0x413c9ba0a05b8a600899b41b0c62dd661e689354',
|
|
verbose: true
|
|
}
|
|
|
|
describe('Compute', () => {
|
|
let ocean: Ocean
|
|
let account: Account
|
|
let agreementId: string
|
|
let dataset: DDO
|
|
let algorithm: DDO
|
|
let computeService: ServiceCompute
|
|
|
|
before(async () => {
|
|
ocean = await Ocean.getInstance(customConfig)
|
|
;[account] = await ocean.accounts.list()
|
|
computeService = await createComputeService(
|
|
ocean,
|
|
account,
|
|
'1000',
|
|
metadataAsset.main.datePublished
|
|
)
|
|
})
|
|
|
|
it('should authenticate the consumer account', async () => {
|
|
await account.authenticate()
|
|
})
|
|
|
|
it('should publish a dataset with a compute service object', async () => {
|
|
const stepsAsset = []
|
|
|
|
dataset = await ocean.assets
|
|
.create(metadataAsset as MetaData, account, [computeService])
|
|
.next(step => stepsAsset.push(step))
|
|
|
|
assert.instanceOf(dataset, DDO)
|
|
assert.isDefined(
|
|
dataset.findServiceByType('compute'),
|
|
`DDO compute service doesn't exist`
|
|
)
|
|
assert.deepEqual(stepsAsset, [0, 1, 2, 3, 4, 5, 6, 7])
|
|
})
|
|
|
|
it('should publish an algorithm', async () => {
|
|
const stepsAlgorithm = []
|
|
algorithm = await ocean.assets
|
|
.create(metadataAlgorithm as MetaData, account)
|
|
.next(step => stepsAlgorithm.push(step))
|
|
|
|
assert.instanceOf(algorithm, DDO)
|
|
assert.deepEqual(stepsAlgorithm, [0, 1, 2, 3, 4, 5, 6, 7])
|
|
})
|
|
|
|
it('should order the compute service of the dataset', async () => {
|
|
const steps = []
|
|
try {
|
|
await account.requestTokens(
|
|
parseInt(
|
|
(
|
|
+computeService.attributes.main.price *
|
|
10 ** -(await ocean.keeper.token.decimals())
|
|
).toString()
|
|
)
|
|
)
|
|
|
|
agreementId = await ocean.compute
|
|
.order(account, dataset.id)
|
|
.next(step => steps.push(step))
|
|
|
|
console.log(agreementId)
|
|
assert.isDefined(agreementId)
|
|
assert.deepEqual(steps, [0, 1, 2, 3])
|
|
} catch {}
|
|
})
|
|
|
|
it('should start a compute job', async () => {
|
|
const response = await ocean.compute.start(account, agreementId, algorithm.id)
|
|
|
|
assert.equal(response.status, ComputeJobStatus.Started)
|
|
})
|
|
})
|