Skip to content

Commit

Permalink
Merge pull request #350 from oceanprotocol/fix/docs-assets
Browse files Browse the repository at this point in the history
jsdocs updates
  • Loading branch information
kremalicious authored Oct 13, 2020
2 parents 5c2cef6 + 97b182f commit 411bb68
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 65 deletions.
45 changes: 19 additions & 26 deletions src/ocean/Assets.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { SearchQuery, QueryResult } from '../metadatastore/MetadataStore'
import { DDO } from '../ddo/DDO'
import { Metadata } from '../ddo/interfaces/Metadata'
import {
Service,
ServiceAccess,
ServiceComputePrivacy,
ServiceCommon
} from '../ddo/interfaces/Service'

import { Service, ServiceAccess, ServiceComputePrivacy } from '../ddo/interfaces/Service'
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
import Account from './Account'
import DID from './DID'
Expand All @@ -17,6 +11,7 @@ import { WebServiceConnector } from './utils/WebServiceConnector'
import BigNumber from 'bignumber.js'
import { Provider } from '../provider/Provider'
import { isAddress } from 'web3-utils'
import { MetadataMain } from '../ddo/interfaces'

export enum CreateProgressStep {
CreatingDataToken,
Expand Down Expand Up @@ -124,7 +119,8 @@ export class Assets extends Instantiable {

this.logger.log('Encrypting files')
observer.next(CreateProgressStep.EncryptingFiles)
let provider
let provider: Provider

if (providerUri) {
provider = new Provider(this.instanceConfig)
provider.setBaseUrl(providerUri)
Expand Down Expand Up @@ -175,7 +171,7 @@ export class Assets extends Instantiable {
index,
url: undefined
}))
} as any
} as MetadataMain
}
},
...services
Expand Down Expand Up @@ -263,7 +259,8 @@ export class Assets extends Instantiable {
account: Account
): Promise<DDO> {
const oldDdo = await this.ocean.metadatastore.retrieveDDO(did)
let i
let i: number

for (i = 0; i < oldDdo.service.length; i++) {
if (oldDdo.service[i].type === 'metadata') {
if (newMetadata.title) oldDdo.service[i].attributes.main.name = newMetadata.title
Expand Down Expand Up @@ -375,12 +372,10 @@ export class Assets extends Instantiable {
} as SearchQuery)
}

public async getServiceByType(
did: string,
serviceType: string
): Promise<ServiceCommon> {
const services: ServiceCommon[] = (await this.resolve(did)).service
let service
public async getServiceByType(did: string, serviceType: string): Promise<Service> {
let service: Service
const services: Service[] = (await this.resolve(did)).service

services.forEach((serv) => {
if (serv.type.toString() === serviceType) {
service = serv
Expand All @@ -389,12 +384,10 @@ export class Assets extends Instantiable {
return service
}

public async getServiceByIndex(
did: string,
serviceIndex: number
): Promise<ServiceCommon> {
const services: ServiceCommon[] = (await this.resolve(did)).service
let service
public async getServiceByIndex(did: string, serviceIndex: number): Promise<Service> {
let service: Service
const services: Service[] = (await this.resolve(did)).service

services.forEach((serv) => {
if (serv.index === serviceIndex) {
service = serv
Expand Down Expand Up @@ -441,8 +434,7 @@ export class Assets extends Instantiable {
* @param {String} serviceType
* @param {String} consumerAddress
* @param {Number} serviceIndex
* @param {String} mpFeePercent will be converted to Wei
* @param {String} mpAddress mp fee collector address
* @param {String} serviceEndpoint
* @return {Promise<any>} Order details
*/
public async initialize(
Expand All @@ -466,7 +458,7 @@ export class Assets extends Instantiable {
* @param {String} serviceType
* @param {String} payerAddress
* @param {Number} serviceIndex
* @param {String} mpAddress mp fee collector address
* @param {String} mpAddress Marketplace fee collector address
* @param {String} consumerAddress Optionally, if the consumer is another address than payer
* @return {Promise<String>} transactionHash of the payment
*/
Expand All @@ -478,7 +470,8 @@ export class Assets extends Instantiable {
mpAddress?: string,
consumerAddress?: string
): Promise<string> {
let service
let service: Service

if (!consumerAddress) consumerAddress = payerAddress
if (serviceIndex === -1) {
service = await this.getServiceByType(did, serviceType)
Expand Down
3 changes: 2 additions & 1 deletion src/ocean/Compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export class Compute extends Instantiable {
did?: string,
jobId?: string
): Promise<ComputeJob[]> {
let provider
let provider: Provider

if (did) {
const ddo = await this.ocean.assets.resolve(did)
const service = ddo.findServiceByType('compute')
Expand Down
7 changes: 5 additions & 2 deletions src/provider/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Output } from '../ocean/interfaces/ComputeOutput'
import { MetadataAlgorithm } from '../ddo/interfaces/MetadataAlgorithm'
import { Versions } from '../ocean/Versions'
import { Response } from 'node-fetch'
import { DDO } from '../ddo/DDO'

const apiPath = '/api/v1/services'

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

public get url(): string {
return this.baseUrl
}

Expand Down Expand Up @@ -101,7 +103,8 @@ export class Provider extends Instantiable {
serviceType: string,
consumerAddress: string
): Promise<string> {
let DDO
let DDO: DDO

try {
DDO = await this.ocean.assets.resolve(did)
} catch (e) {
Expand Down
69 changes: 35 additions & 34 deletions test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@ import { TestContractHandler } from '../TestContractHandler'
import { DataTokens } from '../../src/datatokens/Datatokens'
import { Ocean } from '../../src/ocean/Ocean'
import { ConfigHelper } from '../../src/utils/ConfigHelper'

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 factory from '@oceanprotocol/contracts/artifacts/DTFactory.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')

function sleep(ms) {
function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}

describe('Compute flow', () => {
let owner
let bob
let ddo
let alice
let asset
let datasetNoRawAlgo
let datasetWithTrustedAlgo
let algorithmAsset
let contracts
let owner: Account
let bob: Account
let ddo: DDO
let alice: Account
let asset: Metadata
let datasetNoRawAlgo: DDO
let datasetWithTrustedAlgo: DDO
let algorithmAsset: DDO
let contracts: TestContractHandler
let datatoken: DataTokens
let tokenAddress
let tokenAddressNoRawAlgo
let tokenAddressWithTrustedAlgo
let tokenAddressAlgorithm
let tokenAddress: string
let tokenAddressNoRawAlgo: string
let tokenAddressWithTrustedAlgo: string
let tokenAddressAlgorithm: string
let price: string
let ocean
let computeService: ServiceCommon
let data
let blob
let jobId
let ocean: Ocean
let computeService: Service
let data: { t: number; url: string }
let blob: string
let jobId: string

let cluster
let servers
let containers
let provider
let cluster: Cluster
let servers: Server[]
let containers: Container[]
let providerAttributes: any

const dateCreated = new Date(Date.now()).toISOString().split('.')[0] + 'Z' // remove milliseconds

const marketplaceAllowance = '20'
const tokenAmount = '100'

const timeout = 86400
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('Compute flow', () => {
'sha256:cb57ecfa6ebbefd8ffc7f75c0f00e57a7fa739578a429b6f72a0df19315deadc'
)
]
provider = ocean.compute.createProviderAttributes(
providerAttributes = ocean.compute.createProviderAttributes(
'Azure',
'Compute service with 16gb ram for each node.',
cluster,
Expand All @@ -186,7 +186,7 @@ describe('Compute flow', () => {
alice,
price,
dateCreated,
provider,
providerAttributes,
origComputePrivacy as ServiceComputePrivacy
)
ddo = await ocean.assets.create(asset, alice, [computeService], tokenAddress)
Expand All @@ -205,7 +205,7 @@ describe('Compute flow', () => {
alice,
'1000',
dateCreated,
provider,
providerAttributes,
origComputePrivacy as ServiceComputePrivacy
)
datasetNoRawAlgo = await ocean.assets.create(
Expand All @@ -229,7 +229,7 @@ describe('Compute flow', () => {
alice,
'1000',
dateCreated,
provider,
providerAttributes,
origComputePrivacy as ServiceComputePrivacy
)
datasetWithTrustedAlgo = await ocean.assets.create(
Expand All @@ -243,7 +243,7 @@ describe('Compute flow', () => {
})

it('should publish an algorithm', async () => {
const algoAsset = {
const algoAsset: Metadata = {
main: {
type: 'algorithm',
name: 'Test Algo',
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('Compute flow', () => {
undefined,
algorithmMeta,
output,
computeService.index,
`${computeService.index}`,
computeService.type
)
jobId = response.jobId
Expand All @@ -365,7 +365,8 @@ describe('Compute flow', () => {
assert(jobId != null)
await ocean.compute.stop(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 () => {
const service1 = datasetNoRawAlgo.findServiceByType('compute')
Expand Down Expand Up @@ -416,7 +417,7 @@ describe('Compute flow', () => {
algorithmAsset.id,
undefined,
output,
computeService.index,
`${computeService.index}`,
computeService.type,
orderalgo,
algorithmAsset.dataToken
Expand Down
4 changes: 2 additions & 2 deletions test/integration/Marketplaceflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import spies from 'chai-spies'
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
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 { ConfigHelper } from '../../src/utils/ConfigHelper'
import { TestContractHandler } from '../TestContractHandler'
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('Marketplace flow', () => {
let service1: ServiceAccess
let price: string
let ocean: Ocean
let accessService: ServiceCommon
let accessService: Service
let data
let blob

Expand Down

0 comments on commit 411bb68

Please sign in to comment.