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

more typings updates

This commit is contained in:
Matthias Kretschmann 2020-10-12 15:31:02 +02:00
parent 195f6c311f
commit 97b182f4ab
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 41 additions and 38 deletions

View File

@ -183,7 +183,8 @@ export class Compute extends Instantiable {
did?: string, did?: string,
jobId?: string jobId?: string
): Promise<ComputeJob[]> { ): Promise<ComputeJob[]> {
let provider let provider: Provider
if (did) { if (did) {
const ddo = await this.ocean.assets.resolve(did) const ddo = await this.ocean.assets.resolve(did)
const service = ddo.findServiceByType('compute') const service = ddo.findServiceByType('compute')

View File

@ -20,7 +20,8 @@ const apiPath = '/api/v1/services'
export class Provider extends Instantiable { export class Provider extends Instantiable {
public nonce: string public nonce: string
private baseUrl: string private baseUrl: string
public get url() {
public get url(): string {
return this.baseUrl return this.baseUrl
} }

View File

@ -3,50 +3,50 @@ import { TestContractHandler } from '../TestContractHandler'
import { DataTokens } from '../../src/datatokens/Datatokens' import { DataTokens } from '../../src/datatokens/Datatokens'
import { Ocean } from '../../src/ocean/Ocean' import { Ocean } from '../../src/ocean/Ocean'
import { ConfigHelper } from '../../src/utils/ConfigHelper' import { ConfigHelper } from '../../src/utils/ConfigHelper'
import { assert } from 'chai' import { assert } from 'chai'
import { ServiceCommon, ServiceComputePrivacy } from '../../src/ddo/interfaces/Service' import { Service, ServiceComputePrivacy } from '../../src/ddo/interfaces/Service'
import Web3 from 'web3' import Web3 from 'web3'
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json' import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json' import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
import { Account, DDO, Metadata } from '../../src/lib'
import { Cluster, Container, Server } from '../../src/ocean/Compute'
const web3 = new Web3('http://127.0.0.1:8545') const web3 = new Web3('http://127.0.0.1:8545')
function sleep(ms) { function sleep(ms: number) {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(resolve, ms) setTimeout(resolve, ms)
}) })
} }
describe('Compute flow', () => { describe('Compute flow', () => {
let owner let owner: Account
let bob let bob: Account
let ddo let ddo: DDO
let alice let alice: Account
let asset let asset: Metadata
let datasetNoRawAlgo let datasetNoRawAlgo: DDO
let datasetWithTrustedAlgo let datasetWithTrustedAlgo: DDO
let algorithmAsset let algorithmAsset: DDO
let contracts let contracts: TestContractHandler
let datatoken: DataTokens let datatoken: DataTokens
let tokenAddress let tokenAddress: string
let tokenAddressNoRawAlgo let tokenAddressNoRawAlgo: string
let tokenAddressWithTrustedAlgo let tokenAddressWithTrustedAlgo: string
let tokenAddressAlgorithm let tokenAddressAlgorithm: string
let price: string let price: string
let ocean let ocean: Ocean
let computeService: ServiceCommon let computeService: Service
let data let data: { t: number; url: string }
let blob let blob: string
let jobId let jobId: string
let cluster let cluster: Cluster
let servers let servers: Server[]
let containers let containers: Container[]
let provider let providerAttributes: any
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 tokenAmount = '100' const tokenAmount = '100'
const timeout = 86400 const timeout = 86400
@ -170,7 +170,7 @@ describe('Compute flow', () => {
'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc' 'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc'
) )
] ]
provider = ocean.compute.createProviderAttributes( providerAttributes = ocean.compute.createProviderAttributes(
'Azure', 'Azure',
'Compute service with 16gb ram for each node.', 'Compute service with 16gb ram for each node.',
cluster, cluster,
@ -186,7 +186,7 @@ describe('Compute flow', () => {
alice, alice,
price, price,
dateCreated, dateCreated,
provider, providerAttributes,
origComputePrivacy as ServiceComputePrivacy origComputePrivacy as ServiceComputePrivacy
) )
ddo = await ocean.assets.create(asset, alice, [computeService], tokenAddress) ddo = await ocean.assets.create(asset, alice, [computeService], tokenAddress)
@ -205,7 +205,7 @@ describe('Compute flow', () => {
alice, alice,
'1000', '1000',
dateCreated, dateCreated,
provider, providerAttributes,
origComputePrivacy as ServiceComputePrivacy origComputePrivacy as ServiceComputePrivacy
) )
datasetNoRawAlgo = await ocean.assets.create( datasetNoRawAlgo = await ocean.assets.create(
@ -229,7 +229,7 @@ describe('Compute flow', () => {
alice, alice,
'1000', '1000',
dateCreated, dateCreated,
provider, providerAttributes,
origComputePrivacy as ServiceComputePrivacy origComputePrivacy as ServiceComputePrivacy
) )
datasetWithTrustedAlgo = await ocean.assets.create( datasetWithTrustedAlgo = await ocean.assets.create(
@ -243,7 +243,7 @@ describe('Compute flow', () => {
}) })
it('should publish an algorithm', async () => { it('should publish an algorithm', async () => {
const algoAsset = { const algoAsset: Metadata = {
main: { main: {
type: 'algorithm', type: 'algorithm',
name: 'Test Algo', name: 'Test Algo',
@ -344,7 +344,7 @@ describe('Compute flow', () => {
undefined, undefined,
algorithmMeta, algorithmMeta,
output, output,
computeService.index, `${computeService.index}`,
computeService.type computeService.type
) )
jobId = response.jobId jobId = response.jobId
@ -365,7 +365,8 @@ describe('Compute flow', () => {
assert(jobId != null) assert(jobId != null)
await ocean.compute.stop(bob, ddo.id, jobId) await ocean.compute.stop(bob, ddo.id, jobId)
const response = await ocean.compute.status(bob, ddo.id, jobId) const response = await ocean.compute.status(bob, ddo.id, jobId)
assert(response[0].stopreq === 1) // TODO: typings say that `stopreq` does not exist
assert((response[0] as any).stopreq === 1)
}) })
it('should not allow order the compute service with raw algo for dataset that does not allow raw algo', async () => { it('should not allow order the compute service with raw algo for dataset that does not allow raw algo', async () => {
const service1 = datasetNoRawAlgo.findServiceByType('compute') const service1 = datasetNoRawAlgo.findServiceByType('compute')
@ -416,7 +417,7 @@ describe('Compute flow', () => {
algorithmAsset.id, algorithmAsset.id,
undefined, undefined,
output, output,
computeService.index, `${computeService.index}`,
computeService.type, computeService.type,
orderalgo, orderalgo,
algorithmAsset.dataToken algorithmAsset.dataToken

View File

@ -5,7 +5,7 @@ import spies from 'chai-spies'
import Web3 from 'web3' import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types' import { AbiItem } from 'web3-utils/types'
import { DataTokens } from '../../src/datatokens/Datatokens' import { DataTokens } from '../../src/datatokens/Datatokens'
import { Account, EditableMetadata, ServiceAccess, ServiceCommon } from '../../src/lib' import { Account, EditableMetadata, Service, ServiceAccess } from '../../src/lib'
import { Ocean } from '../../src/ocean/Ocean' import { Ocean } from '../../src/ocean/Ocean'
import { ConfigHelper } from '../../src/utils/ConfigHelper' import { ConfigHelper } from '../../src/utils/ConfigHelper'
import { TestContractHandler } from '../TestContractHandler' import { TestContractHandler } from '../TestContractHandler'
@ -33,7 +33,7 @@ describe('Marketplace flow', () => {
let service1: ServiceAccess let service1: ServiceAccess
let price: string let price: string
let ocean: Ocean let ocean: Ocean
let accessService: ServiceCommon let accessService: Service
let data let data
let blob let blob