1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

add more tests

This commit is contained in:
alexcos20 2020-07-13 00:08:27 -07:00
parent 52962cc54d
commit 3071dc1de7
4 changed files with 146 additions and 36 deletions

View File

@ -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
@ -39,4 +39,4 @@ deploy:
api_key: ${NPM_TOKEN}
skip_cleanup: true
on:
tags: true
tags: true

View File

@ -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) {
@ -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

View File

@ -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()
@ -187,6 +186,7 @@ export class Provider extends Instantiable {
// 'algorithmDataToken': alg_data_token
// switch fetch method
let fetch
switch (method) {

View File

@ -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')
@ -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
@ -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(
@ -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
)
@ -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://raw.githubusercontent.com/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)
})
@ -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 () => {})