From ac39369543779370b9be6f00b0f2063a7e50c763 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 27 Jan 2020 16:50:33 +0100 Subject: [PATCH] test data consolidation --- integration/ocean/Compute.test.ts | 5 +- integration/utils/ddo-metadata-generator.ts | 210 +------------------- test/testdata/ddo-compute.json | 2 +- 3 files changed, 15 insertions(+), 202 deletions(-) diff --git a/integration/ocean/Compute.test.ts b/integration/ocean/Compute.test.ts index 1396a71..2d36885 100644 --- a/integration/ocean/Compute.test.ts +++ b/integration/ocean/Compute.test.ts @@ -2,7 +2,7 @@ import { assert } from 'chai' import { config } from '../config' import { Ocean, Account, DDO, MetaData } from '../../src' // @oceanprotocol/squid -import { getMetadata, computeService } from '../utils' +import { getMetadata, getComputeServiceExample } from '../utils' describe('Compute', () => { let ocean: Ocean @@ -13,12 +13,13 @@ describe('Compute', () => { const metadataAsset = getMetadata() const metadataAlgorithm = getMetadata(0, 'algorithm') + const computeServiceExample = getComputeServiceExample() before(async () => { ocean = await Ocean.getInstance(config) ;[account] = await ocean.accounts.list() ddoAsset = await ocean.assets.create(metadataAsset as MetaData, account, [ - computeService + computeServiceExample ]) ddoAlgorithm = await ocean.assets.create(metadataAlgorithm as MetaData, account) diff --git a/integration/utils/ddo-metadata-generator.ts b/integration/utils/ddo-metadata-generator.ts index ec66425..2c20efa 100644 --- a/integration/utils/ddo-metadata-generator.ts +++ b/integration/utils/ddo-metadata-generator.ts @@ -1,5 +1,6 @@ import { MetaData } from '../../src' // @oceanprotocol/squid import { ServiceType } from '../../src/ddo/Service' +import ddoCompute from '../../test/testdata/ddo-compute.json' const metadata: Partial = { main: { @@ -81,204 +82,15 @@ export const generateMetadata = ( export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') => generateMetadata('TestAsset', type, price) -export const computeService = { - type: 'compute' as ServiceType, - index: 2, - serviceEndpoint: 'http://mybrizo.org/api/v1/brizo/services/compute', - templateId: '', - attributes: { - main: { - name: 'dataAssetComputingServiceAgreement', - creator: '0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e', - price: '10', - timeout: 86400, - provider: { - type: 'Azure', - description: '', - environment: { - cluster: { - type: 'Kubernetes', - url: 'http://10.0.0.17/xxx' - }, - supportedContainers: [ - { - image: 'tensorflow/tensorflow', - tag: 'latest', - checksum: - 'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc' - }, - { - image: 'tensorflow/tensorflow', - tag: 'latest', - checksum: - 'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc' - } - ], - supportedServers: [ - { - serverId: '1', - serverType: 'xlsize', - price: '50', - cpu: '16', - gpu: '0', - memory: '128gb', - disk: '160gb', - maxExecutionTime: 86400 - }, - { - serverId: '2', - serverType: 'medium', - price: '10', - cpu: '2', - gpu: '0', - memory: '8gb', - disk: '80gb', - maxExecutionTime: 86400 - } - ] - } - } - }, - additionalInformation: {} - }, - serviceAgreementTemplate: { - contractName: 'EscrowComputeExecutionTemplate', - events: [ - { - name: 'AgreementCreated', - actorType: 'consumer', - handler: { - moduleName: 'serviceExecutionTemplate', - functionName: 'fulfillLockRewardCondition', - version: '0.1' - } - } - ], - fulfillmentOrder: [ - 'lockReward.fulfill', - 'serviceExecution.fulfill', - 'escrowReward.fulfill' - ], - conditionDependency: { - lockReward: [], - serviceExecution: [], - releaseReward: ['lockReward', 'serviceExecution'] - }, - conditions: [ - { - name: 'lockReward', - timelock: 0, - timeout: 0, - contractName: 'LockRewardCondition', - functionName: 'fulfill', - parameters: [ - { - name: '_rewardAddress', - type: 'address', - value: '' - }, - { - name: '_amount', - type: 'uint256', - value: '' - } - ], - events: [ - { - name: 'Fulfilled', - actorType: 'publisher', - handler: { - moduleName: 'lockRewardCondition', - functionName: 'fulfillServiceExecutionCondition', - version: '0.1' - } - } - ] - }, - { - name: 'serviceExecution', - timelock: 0, - timeout: 0, - contractName: 'ComputeExecutionCondition', - functionName: 'fulfill', - parameters: [ - { - name: '_documentId', - type: 'bytes32', - value: '' - }, - { - name: '_grantee', - type: 'address', - value: '' - } - ], - events: [ - { - name: 'Fulfilled', - actorType: 'publisher', - handler: { - moduleName: 'serviceExecution', - functionName: 'fulfillServiceExecutionCondition', - version: '0.1' - } - }, - { - name: 'TimedOut', - actorType: 'consumer', - handler: { - moduleName: 'serviceExec', - functionName: 'fulfillServiceExecutionCondition', - version: '0.1' - } - } - ] - }, - { - name: 'escrowReward', - timelock: 0, - timeout: 0, - contractName: 'EscrowReward', - functionName: 'fulfill', - parameters: [ - { - name: '_amount', - type: 'uint256', - value: '' - }, - { - name: '_receiver', - type: 'address', - value: '' - }, - { - name: '_sender', - type: 'address', - value: '' - }, - { - name: '_lockCondition', - type: 'bytes32', - value: '' - }, - { - name: '_releaseCondition', - type: 'bytes32', - value: '' - } - ], - events: [ - { - name: 'Fulfilled', - actorType: 'publisher', - handler: { - moduleName: 'escrowRewardCondition', - functionName: 'verifyRewardTokens', - version: '0.1' - } - } - ] - } - ] +export const getComputeServiceExample = () => { + const computeService = ddoCompute.service.find(service => service.type === 'compute') + const { index, serviceEndpoint, templateId, attributes } = computeService + + return { + type: 'compute' as ServiceType, + index, + serviceEndpoint, + templateId, + attributes } } diff --git a/test/testdata/ddo-compute.json b/test/testdata/ddo-compute.json index 27b196e..1091d1d 100644 --- a/test/testdata/ddo-compute.json +++ b/test/testdata/ddo-compute.json @@ -46,7 +46,7 @@ }, { "type": "compute", - "index": 2, + "index": 1, "serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/compute", "templateId": "", "attributes": {