From e7acadb2fe91739eee1bff3589801f12c7ab0b1b Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 27 Jan 2020 15:59:26 +0100 Subject: [PATCH] DDO & compute test tweaks --- integration/ocean/Compute.test.ts | 25 +- ...sterEscrowComputeExecutionTemplate.test.ts | 10 +- integration/ocean/Versions.test.ts | 3 +- integration/utils/ddo-metadata-generator.ts | 213 ++++++++++++++- src/ddo/Service.ts | 1 + test/testdata/ddo-compute.json | 248 ++++++++++++++++++ 6 files changed, 473 insertions(+), 27 deletions(-) create mode 100644 test/testdata/ddo-compute.json diff --git a/integration/ocean/Compute.test.ts b/integration/ocean/Compute.test.ts index 8958dd8..1396a71 100644 --- a/integration/ocean/Compute.test.ts +++ b/integration/ocean/Compute.test.ts @@ -2,42 +2,33 @@ import { assert } from 'chai' import { config } from '../config' import { Ocean, Account, DDO, MetaData } from '../../src' // @oceanprotocol/squid -import { getMetadata } from '../utils' -import { ServiceType } from '../../src/ddo/Service' +import { getMetadata, computeService } from '../utils' describe('Compute', () => { let ocean: Ocean let account: Account let ddoAsset: DDO let ddoAlgorithm: DDO + let agreementId: string const metadataAsset = getMetadata() const metadataAlgorithm = getMetadata(0, 'algorithm') - const assetComputeService = { - type: 'compute' as ServiceType, - index: 2, - attributes: { - main: { - serviceAgreementTemplate: { - contractName: '' - } - } - } - } before(async () => { ocean = await Ocean.getInstance(config) ;[account] = await ocean.accounts.list() ddoAsset = await ocean.assets.create(metadataAsset as MetaData, account, [ - assetComputeService + computeService ]) ddoAlgorithm = await ocean.assets.create(metadataAlgorithm as MetaData, account) + + // order compute service + agreementId = await ocean.compute.order(account, ddoAsset.id) }) - it('should order & start a compute job', async () => { - const agreementId = await ocean.compute.order(account, ddoAsset.id) + it('should start a compute job', async () => { const response = await ocean.compute.start(account, agreementId, ddoAlgorithm.id) - // assert.deepEqual(response) + assert.equal(response.status, 1) }) }) diff --git a/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts b/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts index 7f476fa..cb216b4 100644 --- a/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts +++ b/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts @@ -26,7 +26,7 @@ describe('Register Escrow Compute Execution Template', () => { before(async () => { ocean = await Ocean.getInstance(config) - keeper = ocean.keeper + ;({ keeper } = ocean) template = keeper.templates.escrowComputeExecutionTemplate @@ -36,9 +36,11 @@ describe('Register Escrow Compute Execution Template', () => { consumer = (await ocean.accounts.list())[2] // Conditions - computeExecutionCondition = keeper.conditions.computeExecutionCondition - lockRewardCondition = keeper.conditions.lockRewardCondition - escrowReward = keeper.conditions.escrowReward + ;({ + computeExecutionCondition, + lockRewardCondition, + escrowReward + } = keeper.conditions) if (!ocean.keeper.dispenser) { escrowAmount = 0 diff --git a/integration/ocean/Versions.test.ts b/integration/ocean/Versions.test.ts index 8b64c32..5021171 100644 --- a/integration/ocean/Versions.test.ts +++ b/integration/ocean/Versions.test.ts @@ -11,8 +11,7 @@ describe('Versions', () => { ocean = await Ocean.getInstance(config) }) - // TODO: enable again after new versions of Brizo - xit('should return the versions', async () => { + it('should return the versions', async () => { const versions = await ocean.versions.get() assert.equal(versions.aquarius.status, OceanPlatformTechStatus.Working) diff --git a/integration/utils/ddo-metadata-generator.ts b/integration/utils/ddo-metadata-generator.ts index 6ebc29b..ec66425 100644 --- a/integration/utils/ddo-metadata-generator.ts +++ b/integration/utils/ddo-metadata-generator.ts @@ -1,4 +1,5 @@ import { MetaData } from '../../src' // @oceanprotocol/squid +import { ServiceType } from '../../src/ddo/Service' const metadata: Partial = { main: { @@ -50,10 +51,12 @@ const algorithmMeta = { language: 'scala', format: 'docker-image', version: '0.1', + entrypoint: 'ocean-entrypoint.sh', + requirements: [], container: { - entrypoint: 'ocean-entrypoint.sh', - image: '', - tag: '' + entrypoint: 'node $ALGO', + image: 'node', + tag: '10' } } @@ -68,7 +71,7 @@ export const generateMetadata = ( name, type: type || 'dataset', price: (price || 21) + '0'.repeat(18), - algorithm: type === 'algorithm' && algorithmMeta + algorithm: type === 'algorithm' ? algorithmMeta : undefined }, additionalInformation: { ...metadata.additionalInformation @@ -77,3 +80,205 @@ 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' + } + } + ] + } + ] + } +} diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts index 7b7a0ac..48f36ac 100644 --- a/src/ddo/Service.ts +++ b/src/ddo/Service.ts @@ -9,6 +9,7 @@ export interface ServiceCommon { serviceEndpoint?: string attributes: any & { main: { [key: string]: any } + additionalInformation?: { [key: string]: any } } } diff --git a/test/testdata/ddo-compute.json b/test/testdata/ddo-compute.json new file mode 100644 index 0000000..27b196e --- /dev/null +++ b/test/testdata/ddo-compute.json @@ -0,0 +1,248 @@ +{ + "@context": "https://w3id.org/future-method/v1", + "authentication": [], + "created": "2019-04-09T19:02:11Z", + "id": "did:op:8d1b4d73e7af4634958f071ab8dfe7ab0df14019755e444090fd392c8ec9c3f4", + "proof": { + "created": "2019-04-09T19:02:11Z", + "creator": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", + "signatureValue": "1cd57300733bcbcda0beb59b3e076de6419c0d7674e7befb77820b53c79e3aa8f1776effc64cf088bad8cb694cc4d71ebd74a13b2f75893df5a53f3f318f6cf828", + "type": "DDOIntegritySignature" + }, + "publicKey": [ + { + "id": "did:op:8d1b4d73e7af4634958f071ab8dfe7ab0df14019755e444090fd392c8ec9c3f4", + "owner": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", + "type": "EthereumECDSAKey" + } + ], + "service": [ + { + "type": "metadata", + "index": 0, + "serviceEndpoint": "http://myaquarius.org/api/v1/provider/assets/metadata/{did}", + "attributes": { + "main": { + "author": "Met Office", + "dateCreated": "2019-02-08T08:13:49Z", + "files": [ + { + "url": "https://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt", + "index": 0, + "checksum": "efb2c764274b745f5fc37f97c6b0e764", + "contentLength": "4535431", + "contentType": "text/csv", + "encoding": "UTF-8", + "compression": "zip" + } + ], + "license": "CC-BY", + "name": "UK Weather information 2011", + "price": "1", + "type": "dataset" + }, + "additionalInformation": {} + } + }, + { + "type": "compute", + "index": 2, + "serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/compute", + "templateId": "", + "attributes": { + "main": { + "name": "dataAssetComputingServiceAgreement", + "creator": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", + "datePublished": "2019-04-09T19:02:11Z", + "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" + } + } + ] + } + ] + } + } + ] +}