mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #117 from oceanprotocol/feature/asset-resolve
feature/resolve-assets
This commit is contained in:
commit
cad81b65f5
@ -1,7 +1,12 @@
|
|||||||
import { SearchQuery } from '../metadatastore/MetadataStore'
|
import { SearchQuery } from '../metadatastore/MetadataStore'
|
||||||
import { DDO } from '../ddo/DDO'
|
import { DDO } from '../ddo/DDO'
|
||||||
import { Metadata } from '../ddo/interfaces/Metadata'
|
import { Metadata } from '../ddo/interfaces/Metadata'
|
||||||
import { Service, ServiceAccess, ServiceComputePrivacy } from '../ddo/interfaces/Service'
|
import {
|
||||||
|
Service,
|
||||||
|
ServiceAccess,
|
||||||
|
ServiceComputePrivacy,
|
||||||
|
ServiceCommon
|
||||||
|
} from '../ddo/interfaces/Service'
|
||||||
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
|
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
|
||||||
import Account from './Account'
|
import Account from './Account'
|
||||||
import DID from './DID'
|
import DID from './DID'
|
||||||
@ -352,8 +357,19 @@ export class Assets extends Instantiable {
|
|||||||
} as SearchQuery)
|
} as SearchQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getService(did: string, serviceType: string): Promise<ServiceCommon> {
|
||||||
|
const services: ServiceCommon[] = (await this.resolve(did)).service
|
||||||
|
let service
|
||||||
|
services.forEach((serv) => {
|
||||||
|
if (serv.type.toString() === serviceType) {
|
||||||
|
service = serv
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return service
|
||||||
|
}
|
||||||
|
|
||||||
public async createAccessServiceAttributes(
|
public async createAccessServiceAttributes(
|
||||||
consumerAccount: Account,
|
creator: Account,
|
||||||
dtCost: number,
|
dtCost: number,
|
||||||
datePublished: string,
|
datePublished: string,
|
||||||
timeout: number = 0
|
timeout: number = 0
|
||||||
@ -364,7 +380,7 @@ export class Assets extends Instantiable {
|
|||||||
serviceEndpoint: this.ocean.provider.getConsumeEndpoint(),
|
serviceEndpoint: this.ocean.provider.getConsumeEndpoint(),
|
||||||
attributes: {
|
attributes: {
|
||||||
main: {
|
main: {
|
||||||
creator: consumerAccount.getId(),
|
creator: creator.getId(),
|
||||||
datePublished,
|
datePublished,
|
||||||
dtCost,
|
dtCost,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
|
@ -17,16 +17,12 @@ describe('Marketplace flow', () => {
|
|||||||
let ddo
|
let ddo
|
||||||
let alice
|
let alice
|
||||||
let asset
|
let asset
|
||||||
let accounts
|
|
||||||
let marketplace
|
let marketplace
|
||||||
let marketOcean
|
|
||||||
let contracts
|
let contracts
|
||||||
let datatoken
|
let datatoken
|
||||||
let tokenAddress
|
let tokenAddress
|
||||||
let transactionId
|
|
||||||
let service1
|
let service1
|
||||||
let service2
|
let price
|
||||||
|
|
||||||
let ocean
|
let ocean
|
||||||
|
|
||||||
const marketplaceAllowance = 20
|
const marketplaceAllowance = 20
|
||||||
@ -89,7 +85,16 @@ describe('Marketplace flow', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Alice publishes a dataset', async () => {
|
it('Alice publishes a dataset', async () => {
|
||||||
ddo = await ocean.assets.create(asset, alice, [], tokenAddress)
|
price = 10 // in datatoken
|
||||||
|
const publishedDate = new Date(Date.now()).toISOString().split('.')[0] + 'Z'
|
||||||
|
const timeout = 0
|
||||||
|
service1 = await ocean.assets.createAccessServiceAttributes(
|
||||||
|
alice,
|
||||||
|
price,
|
||||||
|
publishedDate,
|
||||||
|
timeout
|
||||||
|
)
|
||||||
|
ddo = await ocean.assets.create(asset, alice, [service1], tokenAddress)
|
||||||
assert(ddo.dataToken === tokenAddress)
|
assert(ddo.dataToken === tokenAddress)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -133,24 +138,23 @@ describe('Marketplace flow', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
it('Marketplace should resolve asset using DID', async () => {
|
||||||
|
assert(ddo, await ocean.assets.resolve(ddo.id))
|
||||||
|
})
|
||||||
|
|
||||||
// it('Marketplace posts asset for sale', async () => {
|
it('Marketplace posts asset for sale', async () => {
|
||||||
// const config = new Config()
|
const accessService = await ocean.assets.getService(ddo.id, 'access')
|
||||||
// marketOcean = await Ocean.getInstance(config)
|
const price = 20
|
||||||
|
assert(accessService.attributes.main.dtCost * price === 200)
|
||||||
// service1 = marketOcean.assets.getService('download')
|
})
|
||||||
// service2 = marketOcean.assets.getService('access')
|
|
||||||
|
|
||||||
// })
|
|
||||||
|
|
||||||
it('Bob gets datatokens', async () => {
|
it('Bob gets datatokens', async () => {
|
||||||
const ts = await datatoken.transfer(
|
await datatoken
|
||||||
tokenAddress,
|
.transfer(tokenAddress, bob.getId(), transferAmount, alice.getId())
|
||||||
bob.getId(),
|
.then(async () => {
|
||||||
transferAmount,
|
const balance = await datatoken.balance(tokenAddress, bob.getId())
|
||||||
alice.getId()
|
assert(balance.toString() === transferAmount.toString())
|
||||||
)
|
})
|
||||||
transactionId = ts.transactionHash
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// it('Bob consumes asset 1', async () => {
|
// it('Bob consumes asset 1', async () => {
|
||||||
@ -158,9 +162,5 @@ describe('Marketplace flow', () => {
|
|||||||
// const ocean = await Ocean.getInstance(config)
|
// const ocean = await Ocean.getInstance(config)
|
||||||
// await ocean.assets.download(asset.did, service1.index, bob, '~/my-datasets')
|
// await ocean.assets.download(asset.did, service1.index, bob, '~/my-datasets')
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// it('Bob consumes asset 2', async () => {
|
|
||||||
// // TODO
|
|
||||||
// })
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user