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:
parent
52962cc54d
commit
3071dc1de7
@ -19,7 +19,7 @@ before_script:
|
|||||||
- git clone https://github.com/oceanprotocol/barge
|
- git clone https://github.com/oceanprotocol/barge
|
||||||
- cd barge
|
- cd barge
|
||||||
- git checkout v3
|
- git checkout v3
|
||||||
- export PROVIDER_VERSION=alex
|
- export PROVIDER_VERSION=phase2
|
||||||
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
|
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
|
||||||
- cd ..
|
- cd ..
|
||||||
- sleep 300
|
- sleep 300
|
||||||
@ -39,4 +39,4 @@ deploy:
|
|||||||
api_key: ${NPM_TOKEN}
|
api_key: ${NPM_TOKEN}
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
|
@ -70,7 +70,9 @@ export class Compute extends Instantiable {
|
|||||||
algorithmDid?: string,
|
algorithmDid?: string,
|
||||||
algorithmTokenAddress?: string,
|
algorithmTokenAddress?: string,
|
||||||
algorithmMeta?: MetadataAlgorithm,
|
algorithmMeta?: MetadataAlgorithm,
|
||||||
output?: Output
|
output?: Output,
|
||||||
|
serviceIndex?: string,
|
||||||
|
serviceType?: string
|
||||||
): Promise<ComputeJob> {
|
): Promise<ComputeJob> {
|
||||||
output = this.checkOutput(consumerAccount, output)
|
output = this.checkOutput(consumerAccount, output)
|
||||||
if (did) {
|
if (did) {
|
||||||
@ -81,7 +83,12 @@ export class Compute extends Instantiable {
|
|||||||
algorithmDid,
|
algorithmDid,
|
||||||
algorithmMeta,
|
algorithmMeta,
|
||||||
undefined,
|
undefined,
|
||||||
output
|
output,
|
||||||
|
txId,
|
||||||
|
serviceIndex,
|
||||||
|
serviceType,
|
||||||
|
tokenAddress
|
||||||
|
|
||||||
)
|
)
|
||||||
return computeJobsList[0] as ComputeJob
|
return computeJobsList[0] as ComputeJob
|
||||||
} else return null
|
} else return null
|
||||||
|
@ -87,7 +87,6 @@ export class Provider extends Instantiable {
|
|||||||
initializeUrl += `&serviceType=${serviceType}`
|
initializeUrl += `&serviceType=${serviceType}`
|
||||||
initializeUrl += `&dataToken=${DDO.dataToken}`
|
initializeUrl += `&dataToken=${DDO.dataToken}`
|
||||||
initializeUrl += `&consumerAddress=${consumerAddress}`
|
initializeUrl += `&consumerAddress=${consumerAddress}`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.ocean.utils.fetch.get(initializeUrl)
|
const response = await this.ocean.utils.fetch.get(initializeUrl)
|
||||||
return await response.text()
|
return await response.text()
|
||||||
@ -187,6 +186,7 @@ export class Provider extends Instantiable {
|
|||||||
// 'algorithmDataToken': alg_data_token
|
// 'algorithmDataToken': alg_data_token
|
||||||
|
|
||||||
// switch fetch method
|
// switch fetch method
|
||||||
|
|
||||||
let fetch
|
let fetch
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
|
@ -3,7 +3,12 @@ import { DataTokens } from '../../src/datatokens/Datatokens'
|
|||||||
import { Ocean } from '../../src/ocean/Ocean'
|
import { Ocean } from '../../src/ocean/Ocean'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { assert } from 'console'
|
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 = require('web3')
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
const factory = require('@oceanprotocol/contracts/artifacts/development/Factory.json')
|
||||||
@ -15,6 +20,9 @@ describe('Marketplace flow', () => {
|
|||||||
let ddo
|
let ddo
|
||||||
let alice
|
let alice
|
||||||
let asset
|
let asset
|
||||||
|
let datasetNoRawAlgo
|
||||||
|
let datasetWithTrustedAlgo
|
||||||
|
let algorithmAsset
|
||||||
let marketplace
|
let marketplace
|
||||||
let contracts
|
let contracts
|
||||||
let datatoken
|
let datatoken
|
||||||
@ -25,11 +33,20 @@ describe('Marketplace flow', () => {
|
|||||||
let computeService
|
let computeService
|
||||||
let data
|
let data
|
||||||
let blob
|
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 dateCreated = new Date(Date.now()).toISOString().split('.')[0] + 'Z' // remove milliseconds
|
||||||
|
|
||||||
const marketplaceAllowance = 20
|
const marketplaceAllowance = 20
|
||||||
const tokenAmount = 100
|
const tokenAmount = 100
|
||||||
|
|
||||||
|
const timeout = 86400
|
||||||
|
|
||||||
describe('#MarketplaceComputeFlow-Test', () => {
|
describe('#MarketplaceComputeFlow-Test', () => {
|
||||||
it('Initialize Ocean contracts v3', async () => {
|
it('Initialize Ocean contracts v3', async () => {
|
||||||
contracts = new TestContractHandler(
|
contracts = new TestContractHandler(
|
||||||
@ -85,25 +102,25 @@ describe('Marketplace flow', () => {
|
|||||||
|
|
||||||
it('Alice publishes dataset with a compute service', async () => {
|
it('Alice publishes dataset with a compute service', async () => {
|
||||||
price = 10 // in datatoken
|
price = 10 // in datatoken
|
||||||
const timeout = 86400
|
cluster = ocean.compute.createClusterAttributes('Kubernetes', 'http://10.0.0.17/xxx')
|
||||||
const cluster = ocean.compute.createClusterAttributes('Kubernetes', 'http://10.0.0.17/xxx')
|
servers = [
|
||||||
const servers = [
|
|
||||||
ocean.compute.createServerAttributes('1', 'xlsize', '50', '16', '0', '128gb', '160gb', timeout)
|
ocean.compute.createServerAttributes('1', 'xlsize', '50', '16', '0', '128gb', '160gb', timeout)
|
||||||
]
|
]
|
||||||
const containers = [
|
containers = [
|
||||||
ocean.compute.createContainerAttributes(
|
ocean.compute.createContainerAttributes(
|
||||||
'tensorflow/tensorflow',
|
'tensorflow/tensorflow',
|
||||||
'latest',
|
'latest',
|
||||||
'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc'
|
'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc'
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
const provider = ocean.compute.createProviderAttributes(
|
provider = ocean.compute.createProviderAttributes(
|
||||||
'Azure',
|
'Azure',
|
||||||
'Compute service with 16gb ram for each node.',
|
'Compute service with 16gb ram for each node.',
|
||||||
cluster,
|
cluster,
|
||||||
containers,
|
containers,
|
||||||
servers
|
servers
|
||||||
)
|
)
|
||||||
|
|
||||||
const computeService = ocean.compute.createComputeService(
|
const computeService = ocean.compute.createComputeService(
|
||||||
alice, price, dateCreated, provider
|
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 () => {
|
it('Alice mints 100 DTs and tranfers them to the compute marketplace', async () => {
|
||||||
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
await datatoken.mint(tokenAddress, alice.getId(), tokenAmount)
|
||||||
})
|
})
|
||||||
@ -147,33 +241,42 @@ describe('Marketplace flow', () => {
|
|||||||
const output = {
|
const output = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
let order = await ocean.assets.order(ddo.id, computeService.type, bob.getId())
|
||||||
await ocean.assets
|
let computeOrder=JSON.parse(order)
|
||||||
.order(ddo.id, computeService.type, bob.getId())
|
let tx=await datatoken.transfer(
|
||||||
.then(async (res: string) => {
|
computeOrder["dataToken"],
|
||||||
res = JSON.parse(res)
|
computeOrder["to"],
|
||||||
return await datatoken.transfer(
|
computeOrder["numTokens"],
|
||||||
res['dataToken'],
|
computeOrder["from"]
|
||||||
res['to'],
|
)
|
||||||
res['numTokens'],
|
const response = await ocean.compute.start(
|
||||||
res['from']
|
ddo.id,
|
||||||
)
|
tx.transactionHash,
|
||||||
})
|
tokenAddress,
|
||||||
.then(async (tx) => {
|
bob,
|
||||||
await ocean.compute.start(
|
undefined,
|
||||||
ddo.id,
|
undefined,
|
||||||
tx.transactionHash,
|
algorithmMeta,
|
||||||
tokenAddress,
|
output,
|
||||||
bob,
|
computeService.index,
|
||||||
algorithmMeta,
|
computeService.type
|
||||||
output
|
)
|
||||||
|
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 () => {})
|
// it('Bob restarts compute job', async () => {})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user