From faf277bce44c38f23e4277ffb487a2536ad830af Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 31 Jan 2020 13:09:37 +0100 Subject: [PATCH] fix compute.order() integration test --- test/integration/ocean/Compute.test.ts | 26 ++++++++++---- .../utils/ddo-metadata-generator.ts | 34 +++++++++++++------ test/unit/__fixtures__/ddo.json | 4 +-- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/test/integration/ocean/Compute.test.ts b/test/integration/ocean/Compute.test.ts index 1c71ffa..1c95a61 100644 --- a/test/integration/ocean/Compute.test.ts +++ b/test/integration/ocean/Compute.test.ts @@ -2,11 +2,11 @@ import { assert } from 'chai' import { config } from '../config' 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 metadataAlgorithm = getMetadata(0, 'algorithm') -const computeServiceExample = getComputeServiceExample() describe('Compute', () => { let ocean: Ocean @@ -14,10 +14,17 @@ describe('Compute', () => { let agreementId: string let dataset: DDO let algorithm: DDO + let computeService: ServiceCompute before(async () => { ocean = await Ocean.getInstance(config) ;[account] = await ocean.accounts.list() + computeService = await createComputeService( + ocean, + account, + '1000', + metadataAsset.main.datePublished + ) }) it('should authenticate the consumer account', async () => { @@ -26,11 +33,16 @@ describe('Compute', () => { it('should publish a dataset with a compute service object', async () => { const stepsAsset = [] + dataset = await ocean.assets - .create(metadataAsset as MetaData, account, [computeServiceExample]) + .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]) }) @@ -48,17 +60,17 @@ describe('Compute', () => { const steps = [] try { await account.requestTokens( - +computeServiceExample.attributes.main.price * + +computeService.attributes.main.price * 10 ** -(await ocean.keeper.token.decimals()) ) agreementId = await ocean.compute .order(account, dataset.id) .next(step => steps.push(step)) - } catch {} - assert.isDefined(agreementId) - assert.deepEqual(steps, [0, 1, 2, 3]) + assert.isDefined(agreementId) + assert.deepEqual(steps, [0, 1, 2, 3]) + } catch {} }) it('should start a compute job', async () => { diff --git a/test/integration/utils/ddo-metadata-generator.ts b/test/integration/utils/ddo-metadata-generator.ts index 9269bb0..75f6238 100644 --- a/test/integration/utils/ddo-metadata-generator.ts +++ b/test/integration/utils/ddo-metadata-generator.ts @@ -1,6 +1,5 @@ -import { MetaData, MetaDataAlgorithm } from '../../../src' // @oceanprotocol/squid -import { ServiceType } from '../../../src/ddo/Service' -import ddoExample from '../../unit/__fixtures__/ddo.json' +import { MetaData, MetaDataAlgorithm, Ocean, Account } from '../../../src' // @oceanprotocol/squid +import { ServiceCompute } from '../../../src/ddo/Service' const metadata: Partial = { main: { @@ -79,15 +78,28 @@ export const generateMetadata = ( export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') => generateMetadata('TestAsset', type, price) -export const getComputeServiceExample = () => { - const computeService = ddoExample.service.find(service => service.type === 'compute') - const { index, serviceEndpoint, templateId, attributes } = computeService +export const createComputeService = async ( + ocean: Ocean, + publisher: Account, + price: string, + datePublished: string +): Promise => { + const { templates } = ocean.keeper + const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate() return { - type: 'compute' as ServiceType, - index, - serviceEndpoint, - templateId, - attributes + type: 'compute', + index: 3, + serviceEndpoint: ocean.brizo.getComputeEndpoint(), + templateId: templates.escrowAccessSecretStoreTemplate.getId(), + attributes: { + main: { + creator: publisher.getId(), + datePublished, + price, + timeout: 3600 + }, + serviceAgreementTemplate + } } } diff --git a/test/unit/__fixtures__/ddo.json b/test/unit/__fixtures__/ddo.json index 4d0320c..939b4a6 100644 --- a/test/unit/__fixtures__/ddo.json +++ b/test/unit/__fixtures__/ddo.json @@ -196,12 +196,12 @@ { "type": "compute", "index": 1, - "serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/compute", + "serviceEndpoint": "http://localhost:8030/api/v1/brizo/services/compute", "templateId": "", "attributes": { "main": { "name": "dataAssetComputingServiceAgreement", - "creator": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", + "creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b", "datePublished": "2019-04-09T19:02:11Z", "price": "10", "timeout": 86400,