mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
fix compute.order() integration test
This commit is contained in:
parent
0e13f53f6f
commit
faf277bce4
@ -2,11 +2,11 @@ import { assert } from 'chai'
|
||||
|
||||
import { config } from '../config'
|
||||
import { Ocean, Account, DDO, MetaData, ComputeJobStatus } from '../../../src' // @oceanprotocol/squid
|
||||
import { getMetadata, getComputeServiceExample } from '../utils'
|
||||
import { getMetadata, createComputeService } from '../utils'
|
||||
import { ServiceCompute } from '../../../src/ddo/Service'
|
||||
|
||||
const metadataAsset = getMetadata()
|
||||
const metadataAlgorithm = getMetadata(0, 'algorithm')
|
||||
const computeServiceExample = getComputeServiceExample()
|
||||
|
||||
describe('Compute', () => {
|
||||
let ocean: Ocean
|
||||
@ -14,10 +14,17 @@ describe('Compute', () => {
|
||||
let agreementId: string
|
||||
let dataset: DDO
|
||||
let algorithm: DDO
|
||||
let computeService: ServiceCompute
|
||||
|
||||
before(async () => {
|
||||
ocean = await Ocean.getInstance(config)
|
||||
;[account] = await ocean.accounts.list()
|
||||
computeService = await createComputeService(
|
||||
ocean,
|
||||
account,
|
||||
'1000',
|
||||
metadataAsset.main.datePublished
|
||||
)
|
||||
})
|
||||
|
||||
it('should authenticate the consumer account', async () => {
|
||||
@ -26,11 +33,16 @@ describe('Compute', () => {
|
||||
|
||||
it('should publish a dataset with a compute service object', async () => {
|
||||
const stepsAsset = []
|
||||
|
||||
dataset = await ocean.assets
|
||||
.create(metadataAsset as MetaData, account, [computeServiceExample])
|
||||
.create(metadataAsset as MetaData, account, [computeService])
|
||||
.next(step => stepsAsset.push(step))
|
||||
|
||||
assert.instanceOf(dataset, DDO)
|
||||
assert.isDefined(
|
||||
dataset.findServiceByType('compute'),
|
||||
`DDO compute service doesn't exist`
|
||||
)
|
||||
assert.deepEqual(stepsAsset, [0, 1, 2, 3, 4, 5, 6, 7])
|
||||
})
|
||||
|
||||
@ -48,17 +60,17 @@ describe('Compute', () => {
|
||||
const steps = []
|
||||
try {
|
||||
await account.requestTokens(
|
||||
+computeServiceExample.attributes.main.price *
|
||||
+computeService.attributes.main.price *
|
||||
10 ** -(await ocean.keeper.token.decimals())
|
||||
)
|
||||
|
||||
agreementId = await ocean.compute
|
||||
.order(account, dataset.id)
|
||||
.next(step => steps.push(step))
|
||||
} catch {}
|
||||
|
||||
assert.isDefined(agreementId)
|
||||
assert.deepEqual(steps, [0, 1, 2, 3])
|
||||
assert.isDefined(agreementId)
|
||||
assert.deepEqual(steps, [0, 1, 2, 3])
|
||||
} catch {}
|
||||
})
|
||||
|
||||
it('should start a compute job', async () => {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { MetaData, MetaDataAlgorithm } from '../../../src' // @oceanprotocol/squid
|
||||
import { ServiceType } from '../../../src/ddo/Service'
|
||||
import ddoExample from '../../unit/__fixtures__/ddo.json'
|
||||
import { MetaData, MetaDataAlgorithm, Ocean, Account } from '../../../src' // @oceanprotocol/squid
|
||||
import { ServiceCompute } from '../../../src/ddo/Service'
|
||||
|
||||
const metadata: Partial<MetaData> = {
|
||||
main: {
|
||||
@ -79,15 +78,28 @@ export const generateMetadata = (
|
||||
export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') =>
|
||||
generateMetadata('TestAsset', type, price)
|
||||
|
||||
export const getComputeServiceExample = () => {
|
||||
const computeService = ddoExample.service.find(service => service.type === 'compute')
|
||||
const { index, serviceEndpoint, templateId, attributes } = computeService
|
||||
export const createComputeService = async (
|
||||
ocean: Ocean,
|
||||
publisher: Account,
|
||||
price: string,
|
||||
datePublished: string
|
||||
): Promise<ServiceCompute> => {
|
||||
const { templates } = ocean.keeper
|
||||
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
||||
|
||||
return {
|
||||
type: 'compute' as ServiceType,
|
||||
index,
|
||||
serviceEndpoint,
|
||||
templateId,
|
||||
attributes
|
||||
type: 'compute',
|
||||
index: 3,
|
||||
serviceEndpoint: ocean.brizo.getComputeEndpoint(),
|
||||
templateId: templates.escrowAccessSecretStoreTemplate.getId(),
|
||||
attributes: {
|
||||
main: {
|
||||
creator: publisher.getId(),
|
||||
datePublished,
|
||||
price,
|
||||
timeout: 3600
|
||||
},
|
||||
serviceAgreementTemplate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,12 +196,12 @@
|
||||
{
|
||||
"type": "compute",
|
||||
"index": 1,
|
||||
"serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/compute",
|
||||
"serviceEndpoint": "http://localhost:8030/api/v1/brizo/services/compute",
|
||||
"templateId": "",
|
||||
"attributes": {
|
||||
"main": {
|
||||
"name": "dataAssetComputingServiceAgreement",
|
||||
"creator": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
|
||||
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
|
||||
"datePublished": "2019-04-09T19:02:11Z",
|
||||
"price": "10",
|
||||
"timeout": 86400,
|
||||
|
Loading…
Reference in New Issue
Block a user