mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
fix compute.order() integration test
This commit is contained in:
parent
0e13f53f6f
commit
faf277bce4
@ -2,11 +2,11 @@ import { assert } from 'chai'
|
|||||||
|
|
||||||
import { config } from '../config'
|
import { config } from '../config'
|
||||||
import { Ocean, Account, DDO, MetaData, ComputeJobStatus } from '../../../src' // @oceanprotocol/squid
|
import { Ocean, Account, DDO, MetaData, ComputeJobStatus } from '../../../src' // @oceanprotocol/squid
|
||||||
import { getMetadata, getComputeServiceExample } from '../utils'
|
import { getMetadata, createComputeService } from '../utils'
|
||||||
|
import { ServiceCompute } from '../../../src/ddo/Service'
|
||||||
|
|
||||||
const metadataAsset = getMetadata()
|
const metadataAsset = getMetadata()
|
||||||
const metadataAlgorithm = getMetadata(0, 'algorithm')
|
const metadataAlgorithm = getMetadata(0, 'algorithm')
|
||||||
const computeServiceExample = getComputeServiceExample()
|
|
||||||
|
|
||||||
describe('Compute', () => {
|
describe('Compute', () => {
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
@ -14,10 +14,17 @@ describe('Compute', () => {
|
|||||||
let agreementId: string
|
let agreementId: string
|
||||||
let dataset: DDO
|
let dataset: DDO
|
||||||
let algorithm: DDO
|
let algorithm: DDO
|
||||||
|
let computeService: ServiceCompute
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
;[account] = await ocean.accounts.list()
|
;[account] = await ocean.accounts.list()
|
||||||
|
computeService = await createComputeService(
|
||||||
|
ocean,
|
||||||
|
account,
|
||||||
|
'1000',
|
||||||
|
metadataAsset.main.datePublished
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should authenticate the consumer account', async () => {
|
it('should authenticate the consumer account', async () => {
|
||||||
@ -26,11 +33,16 @@ describe('Compute', () => {
|
|||||||
|
|
||||||
it('should publish a dataset with a compute service object', async () => {
|
it('should publish a dataset with a compute service object', async () => {
|
||||||
const stepsAsset = []
|
const stepsAsset = []
|
||||||
|
|
||||||
dataset = await ocean.assets
|
dataset = await ocean.assets
|
||||||
.create(metadataAsset as MetaData, account, [computeServiceExample])
|
.create(metadataAsset as MetaData, account, [computeService])
|
||||||
.next(step => stepsAsset.push(step))
|
.next(step => stepsAsset.push(step))
|
||||||
|
|
||||||
assert.instanceOf(dataset, DDO)
|
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])
|
assert.deepEqual(stepsAsset, [0, 1, 2, 3, 4, 5, 6, 7])
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -48,17 +60,17 @@ describe('Compute', () => {
|
|||||||
const steps = []
|
const steps = []
|
||||||
try {
|
try {
|
||||||
await account.requestTokens(
|
await account.requestTokens(
|
||||||
+computeServiceExample.attributes.main.price *
|
+computeService.attributes.main.price *
|
||||||
10 ** -(await ocean.keeper.token.decimals())
|
10 ** -(await ocean.keeper.token.decimals())
|
||||||
)
|
)
|
||||||
|
|
||||||
agreementId = await ocean.compute
|
agreementId = await ocean.compute
|
||||||
.order(account, dataset.id)
|
.order(account, dataset.id)
|
||||||
.next(step => steps.push(step))
|
.next(step => steps.push(step))
|
||||||
} catch {}
|
|
||||||
|
|
||||||
assert.isDefined(agreementId)
|
assert.isDefined(agreementId)
|
||||||
assert.deepEqual(steps, [0, 1, 2, 3])
|
assert.deepEqual(steps, [0, 1, 2, 3])
|
||||||
|
} catch {}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should start a compute job', async () => {
|
it('should start a compute job', async () => {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { MetaData, MetaDataAlgorithm } from '../../../src' // @oceanprotocol/squid
|
import { MetaData, MetaDataAlgorithm, Ocean, Account } from '../../../src' // @oceanprotocol/squid
|
||||||
import { ServiceType } from '../../../src/ddo/Service'
|
import { ServiceCompute } from '../../../src/ddo/Service'
|
||||||
import ddoExample from '../../unit/__fixtures__/ddo.json'
|
|
||||||
|
|
||||||
const metadata: Partial<MetaData> = {
|
const metadata: Partial<MetaData> = {
|
||||||
main: {
|
main: {
|
||||||
@ -79,15 +78,28 @@ export const generateMetadata = (
|
|||||||
export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') =>
|
export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') =>
|
||||||
generateMetadata('TestAsset', type, price)
|
generateMetadata('TestAsset', type, price)
|
||||||
|
|
||||||
export const getComputeServiceExample = () => {
|
export const createComputeService = async (
|
||||||
const computeService = ddoExample.service.find(service => service.type === 'compute')
|
ocean: Ocean,
|
||||||
const { index, serviceEndpoint, templateId, attributes } = computeService
|
publisher: Account,
|
||||||
|
price: string,
|
||||||
|
datePublished: string
|
||||||
|
): Promise<ServiceCompute> => {
|
||||||
|
const { templates } = ocean.keeper
|
||||||
|
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'compute' as ServiceType,
|
type: 'compute',
|
||||||
index,
|
index: 3,
|
||||||
serviceEndpoint,
|
serviceEndpoint: ocean.brizo.getComputeEndpoint(),
|
||||||
templateId,
|
templateId: templates.escrowAccessSecretStoreTemplate.getId(),
|
||||||
attributes
|
attributes: {
|
||||||
|
main: {
|
||||||
|
creator: publisher.getId(),
|
||||||
|
datePublished,
|
||||||
|
price,
|
||||||
|
timeout: 3600
|
||||||
|
},
|
||||||
|
serviceAgreementTemplate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,12 +196,12 @@
|
|||||||
{
|
{
|
||||||
"type": "compute",
|
"type": "compute",
|
||||||
"index": 1,
|
"index": 1,
|
||||||
"serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/compute",
|
"serviceEndpoint": "http://localhost:8030/api/v1/brizo/services/compute",
|
||||||
"templateId": "",
|
"templateId": "",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"main": {
|
"main": {
|
||||||
"name": "dataAssetComputingServiceAgreement",
|
"name": "dataAssetComputingServiceAgreement",
|
||||||
"creator": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
|
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
|
||||||
"datePublished": "2019-04-09T19:02:11Z",
|
"datePublished": "2019-04-09T19:02:11Z",
|
||||||
"price": "10",
|
"price": "10",
|
||||||
"timeout": 86400,
|
"timeout": 86400,
|
||||||
|
Loading…
Reference in New Issue
Block a user