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

add compute test with published algo

This commit is contained in:
alexcos20 2020-07-13 02:12:34 -07:00
parent 2bf04170d7
commit fdbc692064
3 changed files with 62 additions and 6 deletions

View File

@ -68,7 +68,9 @@ export class Compute extends Instantiable {
algorithmMeta?: MetadataAlgorithm, algorithmMeta?: MetadataAlgorithm,
output?: Output, output?: Output,
serviceIndex?: string, serviceIndex?: string,
serviceType?: string serviceType?: string,
algorithmTransferTxId?: string,
algorithmDataToken?: string
): Promise<ComputeJob> { ): Promise<ComputeJob> {
output = this.checkOutput(consumerAccount, output) output = this.checkOutput(consumerAccount, output)
if (did) { if (did) {
@ -83,7 +85,9 @@ export class Compute extends Instantiable {
txId, txId,
serviceIndex, serviceIndex,
serviceType, serviceType,
tokenAddress tokenAddress,
algorithmTransferTxId,
algorithmDataToken
) )
return computeJobsList[0] as ComputeJob return computeJobsList[0] as ComputeJob
} else return null } else return null

View File

@ -144,10 +144,11 @@ export class Provider extends Instantiable {
txId?: string, txId?: string,
serviceIndex?: string, serviceIndex?: string,
serviceType?: string, serviceType?: string,
tokenAddress?: string tokenAddress?: string,
algorithmTransferTxId?: string,
algorithmDataToken?: string
): Promise<ComputeJob | ComputeJob[]> { ): Promise<ComputeJob | ComputeJob[]> {
const address = consumerAccount.getId() const address = consumerAccount.getId()
let signatureMessage = address let signatureMessage = address
signatureMessage += jobId || '' signatureMessage += jobId || ''
signatureMessage += (did && `${noZeroX(did)}`) || '' signatureMessage += (did && `${noZeroX(did)}`) || ''
@ -169,6 +170,11 @@ export class Provider extends Instantiable {
url += (jobId && `&jobId=${jobId}`) || '' url += (jobId && `&jobId=${jobId}`) || ''
url += `&consumerAddress=${address}` url += `&consumerAddress=${address}`
url += `&transferTxId=${txId}` || '' url += `&transferTxId=${txId}` || ''
url +=
(algorithmTransferTxId &&
`&algorithmTransferTxId=${algorithmTransferTxId}`) ||
''
url += (algorithmDataToken && `&algorithmDataToken=${algorithmDataToken}`) || ''
url += `&serviceId=${serviceIndex}` || '' url += `&serviceId=${serviceIndex}` || ''
url += `&serviceType=${serviceType}` || '' url += `&serviceType=${serviceType}` || ''
url += `&dataToken=${tokenAddress}` || '' url += `&dataToken=${tokenAddress}` || ''

View File

@ -114,7 +114,7 @@ describe('Marketplace flow', () => {
}) })
it('Alice publishes dataset with a compute service that allows Raw Algo', async () => { it('Alice publishes dataset with a compute service that allows Raw Algo', async () => {
price = 10 // in datatoken price = 2 // in datatoken
cluster = ocean.compute.createClusterAttributes( cluster = ocean.compute.createClusterAttributes(
'Kubernetes', 'Kubernetes',
'http://10.0.0.17/xxx' 'http://10.0.0.17/xxx'
@ -337,7 +337,53 @@ describe('Marketplace flow', () => {
) )
assert(order === null) assert(order === null)
}) })
// it('should start a compute job with a published algo', async () => { it('should start a compute job with a published algo', async () => {
const output = {}
const serviceAlgo = algorithmAsset.findServiceByType('access')
const orderalgo = await ocean.assets.order(
algorithmAsset.id,
serviceAlgo.type,
bob.getId()
)
const algoOrder = JSON.parse(orderalgo)
const algoTx = await datatoken.transfer(
algoOrder['dataToken'],
algoOrder['to'],
algoOrder['numTokens'],
algoOrder['from']
)
const order = await ocean.compute.order(
bob.getId(),
ddo.id,
computeService.index,
algorithmAsset.id,
undefined
)
assert(order != null)
const computeOrder = JSON.parse(order)
const 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,
algoTx,
algorithmAsset.datatoken
)
jobId = response.jobId
assert(response.status >= 10)
})
// it('Bob restarts compute job', async () => {}) // it('Bob restarts compute job', async () => {})
// it('Bob gets outputs', async () => {}) // it('Bob gets outputs', async () => {})
}) })