mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
DDO & compute test tweaks
This commit is contained in:
parent
83ea6723e0
commit
e7acadb2fe
@ -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)
|
||||
})
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { MetaData } from '../../src' // @oceanprotocol/squid
|
||||
import { ServiceType } from '../../src/ddo/Service'
|
||||
|
||||
const metadata: Partial<MetaData> = {
|
||||
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'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ export interface ServiceCommon {
|
||||
serviceEndpoint?: string
|
||||
attributes: any & {
|
||||
main: { [key: string]: any }
|
||||
additionalInformation?: { [key: string]: any }
|
||||
}
|
||||
}
|
||||
|
||||
|
248
test/testdata/ddo-compute.json
vendored
Normal file
248
test/testdata/ddo-compute.json
vendored
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user