mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
added ddo object param to function that expect did and asset resolve is called
This commit is contained in:
parent
2fb83f97a9
commit
f0404f3204
@ -47,7 +47,10 @@ export class DataTokens {
|
||||
* Generate new datatoken name & symbol from a word list
|
||||
* @return {<{ name: String; symbol: String }>} datatoken name & symbol. Produces e.g. "Endemic Jellyfish Token" & "ENDJEL-45"
|
||||
*/
|
||||
public generateDtName(wordList?: { nouns: string[]; adjectives: string[] }): {
|
||||
public generateDtName(wordList?: {
|
||||
nouns: string[]
|
||||
adjectives: string[]
|
||||
}): {
|
||||
name: string
|
||||
symbol: string
|
||||
} {
|
||||
|
@ -452,11 +452,18 @@ export class Assets extends Instantiable {
|
||||
serviceType: string,
|
||||
consumerAddress: string,
|
||||
serviceIndex = -1,
|
||||
serviceEndpoint: string
|
||||
serviceEndpoint: string,
|
||||
ddo?: DDO
|
||||
): Promise<any> {
|
||||
const provider = await Provider.getInstance(this.instanceConfig)
|
||||
await provider.setBaseUrl(serviceEndpoint)
|
||||
const res = await provider.initialize(did, serviceIndex, serviceType, consumerAddress)
|
||||
const res = await provider.initialize(
|
||||
did,
|
||||
serviceIndex,
|
||||
serviceType,
|
||||
consumerAddress,
|
||||
ddo
|
||||
)
|
||||
if (res === null) return null
|
||||
const providerData = JSON.parse(res)
|
||||
return providerData
|
||||
@ -501,7 +508,8 @@ export class Assets extends Instantiable {
|
||||
serviceType,
|
||||
payerAddress,
|
||||
serviceIndex,
|
||||
service.serviceEndpoint
|
||||
service.serviceEndpoint,
|
||||
ddo
|
||||
)
|
||||
if (!providerData)
|
||||
throw new Error(
|
||||
|
@ -105,6 +105,7 @@ export class Compute extends Instantiable {
|
||||
* @param {string} algorithmDid The DID of the algorithm asset (of type `algorithm`) to run on the asset.
|
||||
* @param {MetaData} algorithmMeta Metadata about the algorithm being run if `algorithm` is being used. This is ignored when `algorithmDid` is specified.
|
||||
* @param {Output} output Define algorithm output publishing. Publishing the result of a compute job is turned off by default.
|
||||
* @param {DDO} ddo If undefined then the ddo will be fetched by did
|
||||
* @return {Promise<ComputeJob>} Returns compute job ID under status.jobId
|
||||
*/
|
||||
public async start(
|
||||
@ -116,10 +117,14 @@ export class Compute extends Instantiable {
|
||||
output?: ComputeOutput,
|
||||
serviceIndex?: string,
|
||||
serviceType?: string,
|
||||
additionalInputs?: ComputeInput[]
|
||||
additionalInputs?: ComputeInput[],
|
||||
ddo?: DDO
|
||||
): Promise<ComputeJob> {
|
||||
output = this.checkOutput(consumerAccount, output)
|
||||
const ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) {
|
||||
ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) throw new Error(`Couldn't resolve the did ${did}`)
|
||||
}
|
||||
const service = ddo.findServiceByType('compute')
|
||||
const { serviceEndpoint } = service
|
||||
if (did && txId) {
|
||||
@ -147,14 +152,19 @@ export class Compute extends Instantiable {
|
||||
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
||||
* @param {string} did Decentralized identifier.
|
||||
* @param {string} jobId The ID of the compute job to be stopped
|
||||
* @param {DDO} ddo If undefined then the ddo will be fetched by did
|
||||
* @return {Promise<ComputeJob>} Returns the new status of a job
|
||||
*/
|
||||
public async stop(
|
||||
consumerAccount: Account,
|
||||
did: string,
|
||||
jobId: string
|
||||
jobId: string,
|
||||
ddo?: DDO
|
||||
): Promise<ComputeJob> {
|
||||
const ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) {
|
||||
ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) throw new Error(`Couldn't resolve the did ${did}`)
|
||||
}
|
||||
const service = ddo.findServiceByType('compute')
|
||||
const { serviceEndpoint } = service
|
||||
const provider = await Provider.getInstance(this.instanceConfig)
|
||||
@ -169,14 +179,19 @@ export class Compute extends Instantiable {
|
||||
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
||||
* @param {string} did Decentralized identifier.
|
||||
* @param {string} jobId The ID of the compute job to be stopped
|
||||
* @param {DDO} ddo If undefined then the ddo will be fetched by did
|
||||
* @return {Promise<ComputeJob>} Returns the new status of a job
|
||||
*/
|
||||
public async delete(
|
||||
consumerAccount: Account,
|
||||
did: string,
|
||||
jobId: string
|
||||
jobId: string,
|
||||
ddo?: DDO
|
||||
): Promise<ComputeJob> {
|
||||
const ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) {
|
||||
ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) throw new Error(`Couldn't resolve the did ${did}`)
|
||||
}
|
||||
const service = ddo.findServiceByType('compute')
|
||||
const { serviceEndpoint } = service
|
||||
const provider = await Provider.getInstance(this.instanceConfig)
|
||||
@ -243,14 +258,19 @@ export class Compute extends Instantiable {
|
||||
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
||||
* @param {string} did Decentralized identifier.
|
||||
* @param {string} jobId The ID of the compute job to be stopped.
|
||||
* @param {DDO} ddo If undefined then the ddo will be fetched by did
|
||||
* @return {Promise<ComputeJob>} Returns the DDO of the result asset.
|
||||
*/
|
||||
public async result(
|
||||
consumerAccount: Account,
|
||||
did: string,
|
||||
jobId: string
|
||||
jobId: string,
|
||||
ddo?: DDO
|
||||
): Promise<ComputeJob> {
|
||||
const ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) {
|
||||
ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) throw new Error(`Couldn't resolve the did ${did}`)
|
||||
}
|
||||
const service = ddo.findServiceByType('compute')
|
||||
const { serviceEndpoint } = service
|
||||
const provider = await Provider.getInstance(this.instanceConfig)
|
||||
@ -401,6 +421,8 @@ export class Compute extends Instantiable {
|
||||
* @param {string} serviceIndex The Service index
|
||||
* @param {string} algorithmDid The DID of the algorithm asset (of type `algorithm`) to run on the asset.
|
||||
* @param {MetaData} algorithmMeta Metadata about the algorithm being run if `algorithm` is being used. This is ignored when `algorithmDid` is specified.
|
||||
* @param {DDO} datasetDdo Dataset DDO object. If undefined then the ddo will be fetched by did
|
||||
* @param {DDO} algorithmDDO Algorithm DDO object. If undefined then the ddo will be fetched by did
|
||||
* @return {Promise<boolean>} True is you can order this
|
||||
*
|
||||
* Note: algorithmDid and algorithmMeta are optional, but if they are not passed,
|
||||
@ -410,10 +432,15 @@ export class Compute extends Instantiable {
|
||||
public async isOrderable(
|
||||
datasetDid: string,
|
||||
serviceIndex: number,
|
||||
algorithm: ComputeAlgorithm
|
||||
algorithm: ComputeAlgorithm,
|
||||
datasetDdo?: DDO,
|
||||
algorithmDDO?: DDO
|
||||
): Promise<boolean> {
|
||||
const ddo: DDO = await this.ocean.assets.resolve(datasetDid)
|
||||
const service: Service = ddo.findServiceById(serviceIndex)
|
||||
if (!datasetDdo) {
|
||||
datasetDdo = await this.ocean.assets.resolve(datasetDid)
|
||||
if (!datasetDdo) throw new Error(`Couldn't resolve the did ${datasetDid}`)
|
||||
}
|
||||
const service: Service = datasetDdo.findServiceById(serviceIndex)
|
||||
if (!service) return false
|
||||
if (service.type === 'compute') {
|
||||
if (algorithm.meta) {
|
||||
@ -426,8 +453,14 @@ export class Compute extends Instantiable {
|
||||
if (algorithm.did) {
|
||||
// check if both have compute services and then if they are served by the same provider
|
||||
if (algorithm.serviceIndex) {
|
||||
const algoDDO: DDO = await this.ocean.assets.resolve(algorithm.did)
|
||||
const algoService: Service = algoDDO.findServiceById(algorithm.serviceIndex)
|
||||
if (!algorithmDDO) {
|
||||
algorithmDDO = await this.ocean.assets.resolve(algorithm.did)
|
||||
if (!algorithmDDO)
|
||||
throw new Error(`Couldn't resolve the did ${algorithm.did}`)
|
||||
}
|
||||
const algoService: Service = algorithmDDO.findServiceById(
|
||||
algorithm.serviceIndex
|
||||
)
|
||||
if (algoService && algoService.type === 'compute') {
|
||||
// since both dataset & algo services are compute, we need to check if they are served by the same provider
|
||||
const algoProvider = await Provider.getInstance(this.instanceConfig)
|
||||
@ -511,18 +544,28 @@ export class Compute extends Instantiable {
|
||||
algorithm: ComputeAlgorithm,
|
||||
mpAddress?: string,
|
||||
computeAddress?: string,
|
||||
datasetDdo?: DDO,
|
||||
searchPreviousOrders = true
|
||||
): SubscribablePromise<OrderProgressStep, string> {
|
||||
return new SubscribablePromise(async (observer) => {
|
||||
// first check if we can order this
|
||||
const allowed = await this.isOrderable(datasetDid, serviceIndex, algorithm)
|
||||
const allowed = await this.isOrderable(
|
||||
datasetDid,
|
||||
serviceIndex,
|
||||
algorithm,
|
||||
datasetDdo
|
||||
)
|
||||
if (!allowed)
|
||||
throw new Error(
|
||||
`Dataset order failed, dataset is not orderable with the specified algorithm`
|
||||
)
|
||||
const ddo: DDO = await this.ocean.assets.resolve(datasetDid)
|
||||
|
||||
if (!datasetDdo) {
|
||||
datasetDdo = await this.ocean.assets.resolve(datasetDid)
|
||||
if (!datasetDdo) throw new Error(`Couldn't resolve the did ${datasetDid}`)
|
||||
}
|
||||
// const service: Service = ddo.findServiceByType('compute')
|
||||
const service: Service = ddo.findServiceById(serviceIndex)
|
||||
const service: Service = datasetDdo.findServiceById(serviceIndex)
|
||||
if (!service)
|
||||
throw new Error(`Dataset order failed, Could not find service for the DDO`)
|
||||
try {
|
||||
@ -631,8 +674,9 @@ export class Compute extends Instantiable {
|
||||
}
|
||||
if (typeof ddo.service[serviceIndex] === 'undefined') return null
|
||||
if (ddo.service[serviceIndex].type !== 'compute') return null
|
||||
ddo.service[serviceIndex].attributes.main.privacy.allowAllPublishedAlgorithms =
|
||||
newState
|
||||
ddo.service[
|
||||
serviceIndex
|
||||
].attributes.main.privacy.allowAllPublishedAlgorithms = newState
|
||||
return ddo
|
||||
}
|
||||
|
||||
@ -747,12 +791,13 @@ export class Compute extends Instantiable {
|
||||
if (ddo.service[serviceIndex].type !== 'compute') return ddo
|
||||
if (!ddo.service[serviceIndex].attributes.main.privacy.publisherTrustedAlgorithms)
|
||||
return ddo
|
||||
ddo.service[serviceIndex].attributes.main.privacy.publisherTrustedAlgorithms =
|
||||
ddo.service[serviceIndex].attributes.main.privacy.publisherTrustedAlgorithms.filter(
|
||||
function (el) {
|
||||
return el.did !== algoDid
|
||||
}
|
||||
)
|
||||
ddo.service[
|
||||
serviceIndex
|
||||
].attributes.main.privacy.publisherTrustedAlgorithms = ddo.service[
|
||||
serviceIndex
|
||||
].attributes.main.privacy.publisherTrustedAlgorithms.filter(function (el) {
|
||||
return el.did !== algoDid
|
||||
})
|
||||
return ddo
|
||||
}
|
||||
}
|
||||
|
@ -189,15 +189,12 @@ export class Provider extends Instantiable {
|
||||
did: string,
|
||||
serviceIndex: number,
|
||||
serviceType: string,
|
||||
consumerAddress: string
|
||||
consumerAddress: string,
|
||||
ddo?: DDO
|
||||
): Promise<string> {
|
||||
let DDO: DDO
|
||||
|
||||
try {
|
||||
DDO = await this.ocean.assets.resolve(did)
|
||||
} catch (e) {
|
||||
this.logger.error(e)
|
||||
throw new Error('Failed to resolve DID')
|
||||
if (!ddo) {
|
||||
ddo = await this.ocean.assets.resolve(did)
|
||||
if (!ddo) throw new Error(`Couldn't resolve the did ${did}`)
|
||||
}
|
||||
let initializeUrl = this.getInitializeEndpoint()
|
||||
? this.getInitializeEndpoint().urlPath
|
||||
@ -206,7 +203,7 @@ export class Provider extends Instantiable {
|
||||
initializeUrl += `?documentId=${did}`
|
||||
initializeUrl += `&serviceId=${serviceIndex}`
|
||||
initializeUrl += `&serviceType=${serviceType}`
|
||||
initializeUrl += `&dataToken=${DDO.dataToken}`
|
||||
initializeUrl += `&dataToken=${ddo.dataToken}`
|
||||
initializeUrl += `&consumerAddress=${consumerAddress}`
|
||||
try {
|
||||
const response = await this.ocean.utils.fetch.get(initializeUrl)
|
||||
|
@ -150,8 +150,14 @@ export class ConfigHelper {
|
||||
// use the defaults first
|
||||
let configAddresses: Partial<ConfigHelperConfig>
|
||||
if (DefaultContractsAddresses[network]) {
|
||||
const { DTFactory, BFactory, FixedRateExchange, Dispenser, Metadata, Ocean } =
|
||||
DefaultContractsAddresses[network]
|
||||
const {
|
||||
DTFactory,
|
||||
BFactory,
|
||||
FixedRateExchange,
|
||||
Dispenser,
|
||||
Metadata,
|
||||
Ocean
|
||||
} = DefaultContractsAddresses[network]
|
||||
configAddresses = {
|
||||
factoryAddress: DTFactory,
|
||||
poolFactoryAddress: BFactory,
|
||||
@ -172,8 +178,14 @@ export class ConfigHelper {
|
||||
'utf8'
|
||||
)
|
||||
)
|
||||
const { DTFactory, BFactory, FixedRateExchange, Dispenser, Metadata, Ocean } =
|
||||
data[network]
|
||||
const {
|
||||
DTFactory,
|
||||
BFactory,
|
||||
FixedRateExchange,
|
||||
Dispenser,
|
||||
Metadata,
|
||||
Ocean
|
||||
} = data[network]
|
||||
configAddresses = {
|
||||
factoryAddress: DTFactory,
|
||||
poolFactoryAddress: BFactory,
|
||||
|
@ -17,7 +17,9 @@ export class SubscribablePromise<T extends any, P extends any> {
|
||||
setTimeout(() => this.init(executor), 1)
|
||||
}
|
||||
|
||||
public subscribe(onNext: (next: T) => void): {
|
||||
public subscribe(
|
||||
onNext: (next: T) => void
|
||||
): {
|
||||
unsubscribe: () => boolean
|
||||
} {
|
||||
return this.observer.subscribe(onNext)
|
||||
|
@ -104,7 +104,8 @@ describe('Compute flow', () => {
|
||||
language: 'js',
|
||||
format: 'docker-image',
|
||||
version: '0.1',
|
||||
url: 'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
container: {
|
||||
entrypoint: 'node $ALGO',
|
||||
image: 'node',
|
||||
@ -249,7 +250,8 @@ describe('Compute flow', () => {
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url: 'https://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
url:
|
||||
'https://raw.githubusercontent.com/tbertinmahieux/MSongsDB/master/Tasks_Demos/CoverSongs/shs_dataset_test.txt',
|
||||
checksum: 'efb2c764274b745f5fc37f97c6b0e764',
|
||||
contentLength: '4535431',
|
||||
contentType: 'text/csv',
|
||||
@ -485,7 +487,8 @@ describe('Compute flow', () => {
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url: 'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
contentType: 'text/js',
|
||||
encoding: 'UTF-8'
|
||||
}
|
||||
@ -537,7 +540,8 @@ describe('Compute flow', () => {
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url: 'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
contentType: 'text/js',
|
||||
encoding: 'UTF-8'
|
||||
}
|
||||
@ -598,7 +602,8 @@ describe('Compute flow', () => {
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url: 'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
contentType: 'text/js',
|
||||
encoding: 'UTF-8'
|
||||
}
|
||||
@ -662,7 +667,8 @@ describe('Compute flow', () => {
|
||||
license: 'CC-BY',
|
||||
files: [
|
||||
{
|
||||
url: 'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js',
|
||||
contentType: 'text/js',
|
||||
encoding: 'UTF-8'
|
||||
}
|
||||
@ -840,7 +846,8 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo
|
||||
)
|
||||
assert(allowed === true)
|
||||
computeOrderId = await ocean.compute.orderAsset(
|
||||
@ -849,7 +856,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddo
|
||||
)
|
||||
assert(computeOrderId != null, 'computeOrderId === null')
|
||||
const response = await ocean.compute.start(
|
||||
@ -860,7 +868,9 @@ describe('Compute flow', () => {
|
||||
algoDefinition,
|
||||
output,
|
||||
`${computeService.index}`,
|
||||
computeService.type
|
||||
computeService.type,
|
||||
undefined,
|
||||
ddo
|
||||
)
|
||||
assert(response, 'Compute error')
|
||||
jobId = response.jobId
|
||||
@ -918,7 +928,7 @@ describe('Compute flow', () => {
|
||||
})
|
||||
it('Bob should stop compute job', async () => {
|
||||
assert(jobId != null, 'Jobid is null')
|
||||
await ocean.compute.stop(bob, ddo.id, jobId)
|
||||
await ocean.compute.stop(bob, ddo.id, jobId, ddo)
|
||||
const response = await ocean.compute.status(bob, ddo.id, undefined, undefined, jobId)
|
||||
// TODO: typings say that `stopreq` does not exist
|
||||
assert((response[0] as any).stopreq === 1, 'Response.stopreq is invalid')
|
||||
@ -941,7 +951,8 @@ describe('Compute flow', () => {
|
||||
service1.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
datasetNoRawAlgo
|
||||
)
|
||||
assert(order === null, 'Order should be null')
|
||||
} catch (error) {
|
||||
@ -964,7 +975,8 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
datasetWithTrustedAlgo.id,
|
||||
service1.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
datasetWithTrustedAlgo
|
||||
)
|
||||
assert(allowed === false)
|
||||
|
||||
@ -976,7 +988,8 @@ describe('Compute flow', () => {
|
||||
service1.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
datasetWithTrustedAlgo
|
||||
)
|
||||
assert(order === null, 'Order should be null')
|
||||
} catch (error) {
|
||||
@ -995,7 +1008,9 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAsset
|
||||
)
|
||||
assert(allowed === false)
|
||||
|
||||
@ -1006,7 +1021,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddo
|
||||
)
|
||||
assert(order === null, 'Order should be null')
|
||||
} catch (error) {
|
||||
@ -1081,8 +1097,9 @@ describe('Compute flow', () => {
|
||||
algorithmAssetRemoteProviderWithCompute != null,
|
||||
'algorithmAsset should not be null'
|
||||
)
|
||||
const serviceAlgo =
|
||||
algorithmAssetRemoteProviderWithCompute.findServiceByType('compute')
|
||||
const serviceAlgo = algorithmAssetRemoteProviderWithCompute.findServiceByType(
|
||||
'compute'
|
||||
)
|
||||
assert(serviceAlgo != null, 'serviceAlgo should not be null')
|
||||
// get the compute address first
|
||||
computeAddress = await ocean.compute.getComputeAddress(ddo.id, computeService.index)
|
||||
@ -1094,7 +1111,9 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAssetRemoteProviderWithCompute
|
||||
)
|
||||
assert(allowed === false)
|
||||
try {
|
||||
@ -1104,7 +1123,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddo
|
||||
)
|
||||
assert(order === null, 'Order should be null')
|
||||
} catch (error) {
|
||||
@ -1127,7 +1147,9 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAssetwithCompute
|
||||
)
|
||||
assert(allowed === true)
|
||||
const order = await ocean.compute.orderAsset(
|
||||
@ -1136,7 +1158,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddo
|
||||
)
|
||||
assert(order != null, 'Order should not be null')
|
||||
// order the algorithm
|
||||
@ -1159,7 +1182,9 @@ describe('Compute flow', () => {
|
||||
algoDefinition,
|
||||
output,
|
||||
`${computeService.index}`,
|
||||
computeService.type
|
||||
computeService.type,
|
||||
undefined,
|
||||
ddo
|
||||
)
|
||||
assert(response, 'Compute error')
|
||||
jobId = response.jobId
|
||||
@ -1183,7 +1208,9 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAsset
|
||||
)
|
||||
assert(allowed === true)
|
||||
const order = await ocean.compute.orderAsset(
|
||||
@ -1192,7 +1219,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddo
|
||||
)
|
||||
assert(order != null, 'Order should not be null')
|
||||
// order the algorithm
|
||||
@ -1215,7 +1243,9 @@ describe('Compute flow', () => {
|
||||
algoDefinition,
|
||||
output,
|
||||
`${computeService.index}`,
|
||||
computeService.type
|
||||
computeService.type,
|
||||
undefined,
|
||||
ddo
|
||||
)
|
||||
assert(response, 'Compute error')
|
||||
jobId = response.jobId
|
||||
@ -1242,7 +1272,9 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAssetRemoteProvider
|
||||
)
|
||||
assert(allowed === true)
|
||||
const order = await ocean.compute.orderAsset(
|
||||
@ -1251,7 +1283,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddo
|
||||
)
|
||||
assert(order != null, 'Order should not be null')
|
||||
const orderalgo = await ocean.compute.orderAlgorithm(
|
||||
@ -1273,7 +1306,9 @@ describe('Compute flow', () => {
|
||||
algoDefinition,
|
||||
output,
|
||||
`${computeService.index}`,
|
||||
computeService.type
|
||||
computeService.type,
|
||||
undefined,
|
||||
ddo
|
||||
)
|
||||
assert(response, 'Compute error')
|
||||
assert(response.status >= 1, 'Invalid response status')
|
||||
@ -1296,7 +1331,9 @@ describe('Compute flow', () => {
|
||||
allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAsset
|
||||
)
|
||||
assert(allowed === true)
|
||||
const order = await ocean.compute.orderAsset(
|
||||
@ -1305,7 +1342,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddo
|
||||
)
|
||||
assert(order != null, 'Order should not be null')
|
||||
// order the algo
|
||||
@ -1324,7 +1362,8 @@ describe('Compute flow', () => {
|
||||
allowed = await ocean.compute.isOrderable(
|
||||
ddoAdditional1.id,
|
||||
inputOrder1Service.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddoAdditional1
|
||||
)
|
||||
assert(allowed === true)
|
||||
const inputOrder1 = await ocean.compute.orderAsset(
|
||||
@ -1333,7 +1372,8 @@ describe('Compute flow', () => {
|
||||
inputOrder1Service.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddoAdditional1
|
||||
)
|
||||
assert(inputOrder1 != null, 'inputOrder1 should not be null')
|
||||
assert(ddoAdditional1 != null, 'ddoAdditional1 should not be null')
|
||||
@ -1342,7 +1382,8 @@ describe('Compute flow', () => {
|
||||
allowed = await ocean.compute.isOrderable(
|
||||
ddoAdditional2.id,
|
||||
inputOrder2Service.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddoAdditional2
|
||||
)
|
||||
assert(allowed === true)
|
||||
const inputOrder2 = await ocean.compute.orderAsset(
|
||||
@ -1351,7 +1392,8 @@ describe('Compute flow', () => {
|
||||
inputOrder2Service.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
ddoAdditional2
|
||||
)
|
||||
assert(inputOrder2 != null, 'inputOrder2 should not be null')
|
||||
const additionalInputs: ComputeInput[] = [
|
||||
@ -1377,7 +1419,8 @@ describe('Compute flow', () => {
|
||||
output,
|
||||
`${computeService.index}`,
|
||||
computeService.type,
|
||||
additionalInputs
|
||||
additionalInputs,
|
||||
ddo
|
||||
)
|
||||
assert(response.status >= 1, 'Invalid response.status')
|
||||
assert(response.jobId, 'Invalid jobId')
|
||||
@ -1464,7 +1507,9 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAsset
|
||||
)
|
||||
assert(allowed === false, 'This should fail, the algo container section was changed!')
|
||||
})
|
||||
@ -1500,7 +1545,9 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
ddo.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
ddo,
|
||||
algorithmAssetRemoteProvider
|
||||
)
|
||||
assert(allowed === false, 'This should fail, the algo files section was changed!')
|
||||
})
|
||||
@ -1556,7 +1603,8 @@ describe('Compute flow', () => {
|
||||
const allowed = await ocean.compute.isOrderable(
|
||||
datasetWithBogusProvider.id,
|
||||
computeService.index,
|
||||
algoDefinition
|
||||
algoDefinition,
|
||||
datasetWithBogusProvider
|
||||
)
|
||||
assert(allowed === false)
|
||||
// we know that it is not Orderable, but we are trying to force it
|
||||
@ -1568,7 +1616,8 @@ describe('Compute flow', () => {
|
||||
computeService.index,
|
||||
algoDefinition,
|
||||
null, // no marketplace fee
|
||||
computeAddress // CtD is the consumer of the dataset
|
||||
computeAddress, // CtD is the consumer of the dataset
|
||||
datasetWithBogusProvider
|
||||
)
|
||||
assert(order === null, 'Order should be null')
|
||||
} catch (error) {
|
||||
@ -1585,7 +1634,9 @@ describe('Compute flow', () => {
|
||||
algoDefinition,
|
||||
output,
|
||||
`${computeService.index}`,
|
||||
computeService.type
|
||||
computeService.type,
|
||||
undefined,
|
||||
ddo
|
||||
)
|
||||
assert(response === null || response === undefined, 'Compute error')
|
||||
})
|
||||
@ -1604,7 +1655,12 @@ describe('Compute flow', () => {
|
||||
})
|
||||
it('Bob should fail to stop a fake compute job on a bogus provider', async () => {
|
||||
const jobid = '1234'
|
||||
const response = await ocean.compute.stop(bob, datasetWithBogusProvider.id, jobid)
|
||||
const response = await ocean.compute.stop(
|
||||
bob,
|
||||
datasetWithBogusProvider.id,
|
||||
jobid,
|
||||
ddo
|
||||
)
|
||||
assert(response === null || response === undefined, 'Invalid response')
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user