mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add compute dataset/compute algo (#711)
This commit is contained in:
parent
08fb29418d
commit
3533695353
@ -66,6 +66,7 @@ describe('Compute flow', () => {
|
|||||||
let datasetWithTrustedAlgo: DDO
|
let datasetWithTrustedAlgo: DDO
|
||||||
let datasetWithBogusProvider: DDO
|
let datasetWithBogusProvider: DDO
|
||||||
let algorithmAsset: DDO
|
let algorithmAsset: DDO
|
||||||
|
let algorithmAssetwithCompute: DDO
|
||||||
let algorithmAssetRemoteProvider: DDO
|
let algorithmAssetRemoteProvider: DDO
|
||||||
let contracts: TestContractHandler
|
let contracts: TestContractHandler
|
||||||
let datatoken: DataTokens
|
let datatoken: DataTokens
|
||||||
@ -74,6 +75,7 @@ describe('Compute flow', () => {
|
|||||||
let tokenAddressWithTrustedAlgo: string
|
let tokenAddressWithTrustedAlgo: string
|
||||||
let tokenAddressWithBogusProvider: string
|
let tokenAddressWithBogusProvider: string
|
||||||
let tokenAddressAlgorithm: string
|
let tokenAddressAlgorithm: string
|
||||||
|
let tokenAddressAlgorithmwithCompute: string
|
||||||
let tokenAddressAlgorithmRemoteProvider: string
|
let tokenAddressAlgorithmRemoteProvider: string
|
||||||
let tokenAddressAdditional1: string
|
let tokenAddressAdditional1: string
|
||||||
let tokenAddressAdditional2: string
|
let tokenAddressAdditional2: string
|
||||||
@ -185,6 +187,15 @@ describe('Compute flow', () => {
|
|||||||
)
|
)
|
||||||
assert(tokenAddressAlgorithm != null, 'Creation of tokenAddressAlgorithm failed')
|
assert(tokenAddressAlgorithm != null, 'Creation of tokenAddressAlgorithm failed')
|
||||||
|
|
||||||
|
tokenAddressAlgorithmwithCompute = await datatoken.create(
|
||||||
|
blob,
|
||||||
|
alice.getId(),
|
||||||
|
'10000000000',
|
||||||
|
'AlgoDTwCompute',
|
||||||
|
'ALGwC'
|
||||||
|
)
|
||||||
|
assert(tokenAddressAlgorithm != null, 'Creation of tokenAddressAlgorithm failed')
|
||||||
|
|
||||||
tokenAddressAlgorithmRemoteProvider = await datatoken.create(
|
tokenAddressAlgorithmRemoteProvider = await datatoken.create(
|
||||||
blob,
|
blob,
|
||||||
alice.getId(),
|
alice.getId(),
|
||||||
@ -506,6 +517,67 @@ describe('Compute flow', () => {
|
|||||||
await waitForAqua(ocean, algorithmAsset.id)
|
await waitForAqua(ocean, algorithmAsset.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should publish an algorithm with a compute service', async () => {
|
||||||
|
const algoAssetwithCompute: Metadata = {
|
||||||
|
main: {
|
||||||
|
type: 'algorithm',
|
||||||
|
name: 'Test Algo with Compute',
|
||||||
|
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 origComputePrivacy = {
|
||||||
|
allowRawAlgorithm: false,
|
||||||
|
allowNetworkAccess: false,
|
||||||
|
allowAllPublishedAlgorithms: false,
|
||||||
|
publisherTrustedAlgorithms: []
|
||||||
|
}
|
||||||
|
const service1 = ocean.compute.createComputeService(
|
||||||
|
alice,
|
||||||
|
'1',
|
||||||
|
dateCreated,
|
||||||
|
providerAttributes,
|
||||||
|
origComputePrivacy as ServiceComputePrivacy
|
||||||
|
)
|
||||||
|
|
||||||
|
algorithmAssetwithCompute = await ocean.assets.create(
|
||||||
|
algoAssetwithCompute,
|
||||||
|
alice,
|
||||||
|
[service1],
|
||||||
|
tokenAddressAlgorithmwithCompute
|
||||||
|
)
|
||||||
|
assert(
|
||||||
|
algorithmAssetwithCompute.dataToken === tokenAddressAlgorithmwithCompute,
|
||||||
|
'algorithmAssetwithCompute.dataToken !== tokenAddressAlgorithm'
|
||||||
|
)
|
||||||
|
const storeTx = await ocean.onChainMetadata.publish(
|
||||||
|
algorithmAssetwithCompute.id,
|
||||||
|
algorithmAssetwithCompute,
|
||||||
|
alice.getId()
|
||||||
|
)
|
||||||
|
assert(storeTx)
|
||||||
|
await waitForAqua(ocean, algorithmAssetwithCompute.id)
|
||||||
|
})
|
||||||
|
|
||||||
it('should publish an algorithm using the 2nd provider', async () => {
|
it('should publish an algorithm using the 2nd provider', async () => {
|
||||||
const remoteProviderUri = 'http://172.15.0.7:8030'
|
const remoteProviderUri = 'http://172.15.0.7:8030'
|
||||||
const algoAssetRemoteProvider: Metadata = {
|
const algoAssetRemoteProvider: Metadata = {
|
||||||
@ -577,6 +649,7 @@ describe('Compute flow', () => {
|
|||||||
await datatoken.mint(tokenAddressWithTrustedAlgo, alice.getId(), tokenAmount)
|
await datatoken.mint(tokenAddressWithTrustedAlgo, alice.getId(), tokenAmount)
|
||||||
await datatoken.mint(tokenAddressWithBogusProvider, alice.getId(), tokenAmount)
|
await datatoken.mint(tokenAddressWithBogusProvider, alice.getId(), tokenAmount)
|
||||||
await datatoken.mint(tokenAddressAlgorithm, alice.getId(), tokenAmount)
|
await datatoken.mint(tokenAddressAlgorithm, alice.getId(), tokenAmount)
|
||||||
|
await datatoken.mint(tokenAddressAlgorithmwithCompute, alice.getId(), tokenAmount)
|
||||||
await datatoken.mint(tokenAddressAlgorithmRemoteProvider, alice.getId(), tokenAmount)
|
await datatoken.mint(tokenAddressAlgorithmRemoteProvider, alice.getId(), tokenAmount)
|
||||||
await datatoken.mint(tokenAddressAdditional1, alice.getId(), tokenAmount)
|
await datatoken.mint(tokenAddressAdditional1, alice.getId(), tokenAmount)
|
||||||
await datatoken.mint(tokenAddressAdditional2, alice.getId(), tokenAmount)
|
await datatoken.mint(tokenAddressAdditional2, alice.getId(), tokenAmount)
|
||||||
@ -618,6 +691,15 @@ describe('Compute flow', () => {
|
|||||||
const balance = await datatoken.balance(tokenAddressAlgorithm, bob.getId())
|
const balance = await datatoken.balance(tokenAddressAlgorithm, bob.getId())
|
||||||
assert(balance.toString() === dTamount.toString())
|
assert(balance.toString() === dTamount.toString())
|
||||||
})
|
})
|
||||||
|
await datatoken
|
||||||
|
.transfer(tokenAddressAlgorithmwithCompute, bob.getId(), dTamount, alice.getId())
|
||||||
|
.then(async () => {
|
||||||
|
const balance = await datatoken.balance(
|
||||||
|
tokenAddressAlgorithmwithCompute,
|
||||||
|
bob.getId()
|
||||||
|
)
|
||||||
|
assert(balance.toString() === dTamount.toString())
|
||||||
|
})
|
||||||
await datatoken
|
await datatoken
|
||||||
.transfer(tokenAddressAlgorithmRemoteProvider, bob.getId(), dTamount, alice.getId())
|
.transfer(tokenAddressAlgorithmRemoteProvider, bob.getId(), dTamount, alice.getId())
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
@ -858,6 +940,63 @@ describe('Compute flow', () => {
|
|||||||
'allowNetworkAccess does not match'
|
'allowNetworkAccess does not match'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
it('should start a compute job with a published algo that has a compute service', async () => {
|
||||||
|
const output = {}
|
||||||
|
const computeService = ddo.findServiceByType('compute')
|
||||||
|
// get the compute address first
|
||||||
|
computeAddress = await ocean.compute.getComputeAddress(ddo.id, computeService.index)
|
||||||
|
assert(ddo != null, 'ddo should not be null')
|
||||||
|
|
||||||
|
// check if asset is orderable. otherwise, you might pay for it, but it has some algo restrictions
|
||||||
|
const allowed = await ocean.compute.isOrderable(
|
||||||
|
ddo.id,
|
||||||
|
computeService.index,
|
||||||
|
algorithmAssetwithCompute.id,
|
||||||
|
undefined
|
||||||
|
)
|
||||||
|
assert(allowed === true)
|
||||||
|
const order = await ocean.compute.orderAsset(
|
||||||
|
bob.getId(),
|
||||||
|
ddo.id,
|
||||||
|
computeService.index,
|
||||||
|
algorithmAssetwithCompute.id,
|
||||||
|
undefined,
|
||||||
|
null, // no marketplace fee
|
||||||
|
computeAddress // CtD is the consumer of the dataset
|
||||||
|
)
|
||||||
|
assert(order != null, 'Order should not be null')
|
||||||
|
// order the algorithm
|
||||||
|
assert(algorithmAsset != null, 'algorithmAsset should not be null')
|
||||||
|
const serviceAlgo = algorithmAssetwithCompute.findServiceByType('compute')
|
||||||
|
const orderalgo = await ocean.compute.orderAlgorithm(
|
||||||
|
algorithmAssetwithCompute.id,
|
||||||
|
serviceAlgo.type,
|
||||||
|
bob.getId(),
|
||||||
|
serviceAlgo.index,
|
||||||
|
null, // no marketplace fee
|
||||||
|
computeAddress // CtD is the consumer of the dataset
|
||||||
|
)
|
||||||
|
assert(orderalgo != null, 'Order should not be null')
|
||||||
|
|
||||||
|
const response = await ocean.compute.start(
|
||||||
|
ddo.id,
|
||||||
|
order,
|
||||||
|
tokenAddress,
|
||||||
|
bob,
|
||||||
|
algorithmAssetwithCompute.id,
|
||||||
|
undefined,
|
||||||
|
output,
|
||||||
|
`${computeService.index}`,
|
||||||
|
computeService.type,
|
||||||
|
orderalgo,
|
||||||
|
algorithmAssetwithCompute.dataToken
|
||||||
|
)
|
||||||
|
assert(response, 'Compute error')
|
||||||
|
jobId = response.jobId
|
||||||
|
assert(response.status >= 1, 'Invalid response status')
|
||||||
|
assert(response.jobId, 'Invalid jobId')
|
||||||
|
})
|
||||||
|
|
||||||
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 output = {}
|
||||||
const computeService = ddo.findServiceByType('compute')
|
const computeService = ddo.findServiceByType('compute')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user