mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
metadataStore → metadataCache
This commit is contained in:
parent
5c2cef618e
commit
d0b4bb537e
@ -57,7 +57,7 @@ const defaultConfig: Config = new ConfigHelper().getConfig(
|
||||
|
||||
const config = {
|
||||
...defaultConfig,
|
||||
metadataStoreUri: 'https://your-metadata-store.com',
|
||||
metadataCacheUri: 'https://your-metadata-cache.com',
|
||||
providerUri: 'https://your-provider.com'
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ const datatokensTemplate = require('@oceanprotocol/contracts/artifacts/DataToken
|
||||
|
||||
// Alice's config
|
||||
const config = {
|
||||
metadataStoreUri: 'http://aquarius:5000',
|
||||
metadataCacheUri: 'http://aquarius:5000',
|
||||
providerUri: 'http://localhost:8030',
|
||||
nodeUri: `http://localhost:${process.env.ETH_PORT || 8545}`,
|
||||
verbose: LogLevel.Error,
|
||||
@ -60,7 +60,7 @@ datatoken = new DataTokens(
|
||||
datatokensTemplate.abi,
|
||||
web3
|
||||
)
|
||||
const data = { t: 1, url: ocean.config.metadataStoreUri }
|
||||
const data = { t: 1, url: ocean.config.metadataCacheUri }
|
||||
const blob = JSON.stringify(data)
|
||||
|
||||
const dataTokenAddress = await datatoken.create(blob, alice.getId())
|
||||
|
@ -64,7 +64,7 @@ export class DataTokens {
|
||||
|
||||
/**
|
||||
* Create new datatoken
|
||||
* @param {String} metaDataStoreURI
|
||||
* @param {String} metadataCacheUri
|
||||
* @param {String} address
|
||||
* @param {String} cap Maximum cap (Number) - will be converted to wei
|
||||
* @param {String} name Token name
|
||||
@ -72,7 +72,7 @@ export class DataTokens {
|
||||
* @return {Promise<string>} datatoken address
|
||||
*/
|
||||
public async create(
|
||||
metaDataStoreURI: string,
|
||||
metadataCacheUri: string,
|
||||
address: string,
|
||||
cap?: string,
|
||||
name?: string,
|
||||
@ -90,14 +90,14 @@ export class DataTokens {
|
||||
from: address
|
||||
})
|
||||
const estGas = await factory.methods
|
||||
.createToken(metaDataStoreURI, name, symbol, this.web3.utils.toWei(cap))
|
||||
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
|
||||
.estimateGas(function (err: string, estGas: string) {
|
||||
if (err) console.log('Datatokens: ' + err)
|
||||
return estGas
|
||||
})
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await factory.methods
|
||||
.createToken(metaDataStoreURI, name, symbol, this.web3.utils.toWei(cap))
|
||||
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
|
@ -3,7 +3,7 @@ import Account from './ocean/Account'
|
||||
import DID from './ocean/DID'
|
||||
import { Ocean } from './ocean/Ocean'
|
||||
import { LoggerInstance as Logger } from './utils/Logger'
|
||||
import { MetadataStore } from './metadatastore/MetadataStore'
|
||||
import { MetadataCache } from './metadatacache/MetadataCache'
|
||||
import { DataTokens } from './datatokens/Datatokens'
|
||||
import { ConfigHelper } from './utils/ConfigHelper'
|
||||
|
||||
@ -27,7 +27,7 @@ export {
|
||||
Config,
|
||||
DID,
|
||||
Logger,
|
||||
MetadataStore,
|
||||
MetadataCache,
|
||||
DataTokens,
|
||||
utils,
|
||||
ConfigHelper
|
||||
|
@ -23,27 +23,27 @@ export interface SearchQuery {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an interface with Metadata Store.
|
||||
* Metadata Store provides an off-chain database store for metadata about data assets.
|
||||
* Provides an interface with Metadata Cache.
|
||||
* Metadata Cache provides an off-chain database cache for on-chain metadata about data assets.
|
||||
*/
|
||||
export class MetadataStore {
|
||||
export class MetadataCache {
|
||||
public fetch: WebServiceConnector
|
||||
private logger: Logger
|
||||
private metadataStoreUri: string
|
||||
private metadataCacheUri: string
|
||||
|
||||
private get url() {
|
||||
return this.metadataStoreUri
|
||||
return this.metadataCacheUri
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate Metadata Store (independently of Ocean) for off-chain interaction.
|
||||
* @param {String} metadataStoreUri
|
||||
* Instantiate Metadata Cache (independently of Ocean) for off-chain interaction.
|
||||
* @param {String} metadataCacheUri
|
||||
* @param {Logger} logger
|
||||
*/
|
||||
constructor(metadataStoreUri: string, logger: Logger) {
|
||||
constructor(metadataCacheUri: string, logger: Logger) {
|
||||
this.fetch = new WebServiceConnector(logger)
|
||||
this.logger = logger
|
||||
this.metadataStoreUri = metadataStoreUri
|
||||
this.metadataCacheUri = metadataCacheUri
|
||||
}
|
||||
|
||||
public async getVersionInfo(): Promise<any> {
|
@ -11,10 +11,10 @@ import { didZeroX } from '../utils'
|
||||
import { LZMA } from 'lzma/src/lzma-c'
|
||||
|
||||
/**
|
||||
* Provides an interface with Metadata Store.
|
||||
* Metadata Store provides an off-chain database store for metadata about data assets.
|
||||
* Provides an interface with Metadata Cache.
|
||||
* Metadata Cache provides an off-chain database store for metadata about data assets.
|
||||
*/
|
||||
export class OnChainMetadataStore {
|
||||
export class OnChainMetadataCache {
|
||||
public DDOContractAddress: string
|
||||
public DDOContractABI: AbiItem | AbiItem[]
|
||||
public web3: Web3
|
||||
@ -107,7 +107,7 @@ export class OnChainMetadataStore {
|
||||
/* const estGas = await this.DDOContract.methods
|
||||
.create(didZeroX(did), flags, data)
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) console.log('OnChainMetadataStoreEstimateGas: ' + err)
|
||||
if (err) console.log('OnChainMetadataCacheEstimateGas: ' + err)
|
||||
return estGas
|
||||
})
|
||||
*/
|
@ -18,7 +18,7 @@ export class Config {
|
||||
* Metadata Store URL.
|
||||
* @type {string}
|
||||
*/
|
||||
public metadataStoreUri?: string
|
||||
public metadataCacheUri?: string
|
||||
|
||||
/**
|
||||
* Provider URL.
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SearchQuery, QueryResult } from '../metadatastore/MetadataStore'
|
||||
import { SearchQuery, QueryResult } from '../metadatacache/MetadataCache'
|
||||
import { DDO } from '../ddo/DDO'
|
||||
import { Metadata } from '../ddo/interfaces/Metadata'
|
||||
import {
|
||||
@ -97,8 +97,8 @@ export class Assets extends Instantiable {
|
||||
if (!dtAddress) {
|
||||
this.logger.log('Creating datatoken')
|
||||
observer.next(CreateProgressStep.CreatingDataToken)
|
||||
const metadataStoreURI = this.ocean.metadatastore.getURI()
|
||||
const jsonBlob = { t: 1, url: metadataStoreURI }
|
||||
const metadataCacheUri = this.ocean.metadatacache.getURI()
|
||||
const jsonBlob = { t: 1, url: metadataCacheUri }
|
||||
const { datatokens } = this.ocean
|
||||
|
||||
dtAddress = await datatokens.create(
|
||||
@ -199,8 +199,8 @@ export class Assets extends Instantiable {
|
||||
observer.next(CreateProgressStep.ProofGenerated)
|
||||
this.logger.log('Storing DDO')
|
||||
observer.next(CreateProgressStep.StoringDdo)
|
||||
// const storedDdo = await this.ocean.metadatastore.storeDDO(ddo)
|
||||
const storeTx = await this.ocean.OnChainMetadataStore.publish(
|
||||
// const storedDdo = await this.ocean.metadatacache.storeDDO(ddo)
|
||||
const storeTx = await this.ocean.OnChainMetadataCache.publish(
|
||||
ddo.id,
|
||||
ddo,
|
||||
publisher.getId()
|
||||
@ -218,7 +218,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<string[]>} List of DIDs.
|
||||
*/
|
||||
public async ownerAssets(owner: string): Promise<QueryResult> {
|
||||
return this.ocean.metadatastore.getOwnerAssets(owner)
|
||||
return this.ocean.metadatacache.getOwnerAssets(owner)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,7 +227,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<DDO>}
|
||||
*/
|
||||
public async resolve(did: string): Promise<DDO> {
|
||||
return this.ocean.metadatastore.retrieveDDO(did)
|
||||
return this.ocean.metadatacache.retrieveDDO(did)
|
||||
}
|
||||
|
||||
public async resolveByDTAddress(
|
||||
@ -247,7 +247,7 @@ export class Assets extends Instantiable {
|
||||
},
|
||||
text: dtAddress
|
||||
} as SearchQuery
|
||||
return (await this.ocean.metadatastore.queryMetadata(searchQuery)).results
|
||||
return (await this.ocean.metadatacache.queryMetadata(searchQuery)).results
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,7 +262,7 @@ export class Assets extends Instantiable {
|
||||
newMetadata: EditableMetadata,
|
||||
account: Account
|
||||
): Promise<DDO> {
|
||||
const oldDdo = await this.ocean.metadatastore.retrieveDDO(did)
|
||||
const oldDdo = await this.ocean.metadatacache.retrieveDDO(did)
|
||||
let i
|
||||
for (i = 0; i < oldDdo.service.length; i++) {
|
||||
if (oldDdo.service[i].type === 'metadata') {
|
||||
@ -287,7 +287,7 @@ export class Assets extends Instantiable {
|
||||
}
|
||||
}
|
||||
}
|
||||
const storeTx = await this.ocean.OnChainMetadataStore.update(
|
||||
const storeTx = await this.ocean.OnChainMetadataCache.update(
|
||||
oldDdo.id,
|
||||
oldDdo,
|
||||
account.getId()
|
||||
@ -310,7 +310,7 @@ export class Assets extends Instantiable {
|
||||
computePrivacy: ServiceComputePrivacy,
|
||||
account: Account
|
||||
): Promise<DDO> {
|
||||
const oldDdo = await this.ocean.metadatastore.retrieveDDO(did)
|
||||
const oldDdo = await this.ocean.metadatacache.retrieveDDO(did)
|
||||
if (oldDdo.service[serviceIndex].type !== 'compute') return null
|
||||
oldDdo.service[serviceIndex].attributes.main.privacy.allowRawAlgorithm =
|
||||
computePrivacy.allowRawAlgorithm
|
||||
@ -318,7 +318,7 @@ export class Assets extends Instantiable {
|
||||
computePrivacy.allowNetworkAccess
|
||||
oldDdo.service[serviceIndex].attributes.main.privacy.trustedAlgorithms =
|
||||
computePrivacy.trustedAlgorithms
|
||||
const storeTx = await this.ocean.OnChainMetadataStore.update(
|
||||
const storeTx = await this.ocean.OnChainMetadataCache.update(
|
||||
oldDdo.id,
|
||||
oldDdo,
|
||||
account.getId()
|
||||
@ -353,7 +353,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<QueryResult>}
|
||||
*/
|
||||
public async query(query: SearchQuery): Promise<QueryResult> {
|
||||
return this.ocean.metadatastore.queryMetadata(query)
|
||||
return this.ocean.metadatacache.queryMetadata(query)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -362,7 +362,7 @@ export class Assets extends Instantiable {
|
||||
* @return {Promise<QueryResult>}
|
||||
*/
|
||||
public async search(text: string): Promise<QueryResult> {
|
||||
return this.ocean.metadatastore.queryMetadata({
|
||||
return this.ocean.metadatacache.queryMetadata({
|
||||
text,
|
||||
page: 1,
|
||||
offset: 100,
|
||||
|
@ -357,7 +357,7 @@ export class Compute extends Instantiable {
|
||||
publishOutput: output.publishOutput,
|
||||
providerAddress: output.providerAddress || this.config.providerAddress,
|
||||
providerUri: output.providerUri || this.config.providerUri,
|
||||
metadataUri: output.metadataUri || this.config.metadataStoreUri,
|
||||
metadataUri: output.metadataUri || this.config.metadataCacheUri,
|
||||
nodeUri: output.nodeUri || this.config.nodeUri,
|
||||
owner: output.owner || consumerAccount.getId()
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ import { Accounts } from './Accounts'
|
||||
import { Assets } from './Assets'
|
||||
import { Versions } from './Versions'
|
||||
import { OceanUtils } from './utils/Utils'
|
||||
import { MetadataStore } from '../metadatastore/MetadataStore'
|
||||
import { OnChainMetadataStore } from '../metadatastore/OnChainMetaData'
|
||||
import { MetadataCache } from '../metadatacache/MetadataCache'
|
||||
import { OnChainMetadataCache } from '../metadatacache/OnChainMetaDataCache'
|
||||
import { Provider } from '../provider/Provider'
|
||||
import { DataTokens } from '../datatokens/Datatokens'
|
||||
import { Network } from '../datatokens/Network'
|
||||
@ -37,8 +37,8 @@ export class Ocean extends Instantiable {
|
||||
instance.utils = await OceanUtils.getInstance(instanceConfig)
|
||||
|
||||
instance.provider = new Provider(instanceConfig)
|
||||
instance.metadatastore = new MetadataStore(
|
||||
instanceConfig.config.metadataStoreUri,
|
||||
instance.metadatacache = new MetadataCache(
|
||||
instanceConfig.config.metadataCacheUri,
|
||||
instanceConfig.logger
|
||||
)
|
||||
|
||||
@ -65,7 +65,7 @@ export class Ocean extends Instantiable {
|
||||
instanceConfig.config.fixedRateExchangeAddressABI,
|
||||
instanceConfig.config.oceanTokenAddress
|
||||
)
|
||||
instance.OnChainMetadataStore = new OnChainMetadataStore(
|
||||
instance.OnChainMetadataCache = new OnChainMetadataCache(
|
||||
instanceConfig.config.web3Provider,
|
||||
instanceConfig.config.metadataContractAddress,
|
||||
instanceConfig.config.metadataContractABI
|
||||
@ -94,15 +94,15 @@ export class Ocean extends Instantiable {
|
||||
public web3Provider: any
|
||||
|
||||
/**
|
||||
* MetadataStore instance.
|
||||
* @type {MetadataStore}
|
||||
* MetadataCache instance.
|
||||
* @type {MetadataCache}
|
||||
*/
|
||||
public metadatastore: MetadataStore
|
||||
public metadatacache: MetadataCache
|
||||
/**
|
||||
* OnChainMetadataStore instance.
|
||||
* @type {OnChainMetadataStore}
|
||||
* OnChainMetadataCache instance.
|
||||
* @type {OnChainMetadataCache}
|
||||
*/
|
||||
public OnChainMetadataStore: OnChainMetadataStore
|
||||
public OnChainMetadataCache: OnChainMetadataCache
|
||||
/**
|
||||
* Ocean account submodule
|
||||
* @type {Accounts}
|
||||
|
@ -18,7 +18,7 @@ export interface OceanPlatformTech {
|
||||
|
||||
export interface OceanPlatformVersions {
|
||||
lib: OceanPlatformTech
|
||||
metadataStore: OceanPlatformTech
|
||||
metadataCache: OceanPlatformTech
|
||||
provider: OceanPlatformTech
|
||||
status: {
|
||||
ok: boolean
|
||||
@ -49,17 +49,17 @@ export class Versions extends Instantiable {
|
||||
status: OceanPlatformTechStatus.Working
|
||||
}
|
||||
|
||||
// MetadataStore
|
||||
// MetadataCache
|
||||
try {
|
||||
const { software: name, version } = await this.ocean.metadatastore.getVersionInfo()
|
||||
versions.metadataStore = {
|
||||
const { software: name, version } = await this.ocean.metadatacache.getVersionInfo()
|
||||
versions.metadataCache = {
|
||||
name,
|
||||
status: OceanPlatformTechStatus.Working,
|
||||
version
|
||||
}
|
||||
} catch {
|
||||
versions.metadataStore = {
|
||||
name: 'MetadataStore',
|
||||
versions.metadataCache = {
|
||||
name: 'MetadataCache',
|
||||
status: OceanPlatformTechStatus.Stopped
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ const configs: ConfigHelperConfig[] = [
|
||||
network: 'unknown',
|
||||
nodeUri: 'http://localhost:8545',
|
||||
factoryAddress: null,
|
||||
metadataStoreUri: 'http://127.0.0.1:5000',
|
||||
metadataCacheUri: 'http://127.0.0.1:5000',
|
||||
providerUri: 'http://127.0.0.1:8030',
|
||||
poolFactoryAddress: null,
|
||||
fixedRateExchangeAddress: null,
|
||||
@ -34,7 +34,7 @@ const configs: ConfigHelperConfig[] = [
|
||||
network: 'development',
|
||||
nodeUri: 'http://localhost:8545',
|
||||
factoryAddress: null,
|
||||
metadataStoreUri: 'http://127.0.0.1:5000',
|
||||
metadataCacheUri: 'http://127.0.0.1:5000',
|
||||
providerUri: 'http://127.0.0.1:8030',
|
||||
poolFactoryAddress: null,
|
||||
fixedRateExchangeAddress: null,
|
||||
@ -46,7 +46,7 @@ const configs: ConfigHelperConfig[] = [
|
||||
nodeUri: 'https://rinkeby.infura.io/v3',
|
||||
factoryAddress: '0x3fd7A00106038Fb5c802c6d63fa7147Fe429E83a',
|
||||
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
|
||||
metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
||||
metadataCacheUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
|
||||
providerUri: 'https://provider.rinkeby.v3.dev-ocean.com',
|
||||
poolFactoryAddress: '0x53eDF9289B0898e1652Ce009AACf8D25fA9A42F8',
|
||||
fixedRateExchangeAddress: '0xeD1DfC5F3a589CfC4E8B91C1fbfC18FC6699Fbde',
|
||||
@ -58,7 +58,7 @@ const configs: ConfigHelperConfig[] = [
|
||||
nodeUri: 'https://mainnet.infura.io/v3',
|
||||
factoryAddress: '0x1234',
|
||||
oceanTokenAddress: '0x7AFeBBB46fDb47ed17b22ed075Cde2447694fB9e',
|
||||
metadataStoreUri: null,
|
||||
metadataCacheUri: null,
|
||||
providerUri: null,
|
||||
poolFactoryAddress: null,
|
||||
fixedRateExchangeAddress: null,
|
||||
@ -86,7 +86,7 @@ export class ConfigHelper {
|
||||
fixedRateExchangeAddress: FixedRateExchange,
|
||||
metadataContractAddress: Metadata,
|
||||
oceanTokenAddress: Ocean,
|
||||
...(process.env.AQUARIUS_URI && { metadataStoreUri: process.env.AQUARIUS_URI })
|
||||
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
|
||||
}
|
||||
|
||||
return configAddresses
|
||||
|
@ -77,7 +77,7 @@ describe('Compute flow', () => {
|
||||
owner = (await ocean.accounts.list())[0]
|
||||
alice = (await ocean.accounts.list())[1]
|
||||
bob = (await ocean.accounts.list())[2]
|
||||
data = { t: 1, url: config.metadataStoreUri }
|
||||
data = { t: 1, url: config.metadataCacheUri }
|
||||
blob = JSON.stringify(data)
|
||||
await contracts.deployContracts(owner.getId())
|
||||
})
|
||||
|
@ -55,7 +55,7 @@ describe('Marketplace flow', () => {
|
||||
alice = (await ocean.accounts.list())[1]
|
||||
bob = (await ocean.accounts.list())[2]
|
||||
marketplace = (await ocean.accounts.list())[3]
|
||||
data = { t: 1, url: config.metadataStoreUri }
|
||||
data = { t: 1, url: config.metadataCacheUri }
|
||||
blob = JSON.stringify(data)
|
||||
await contracts.deployContracts(owner.getId())
|
||||
})
|
||||
|
@ -7,7 +7,7 @@ LoggerInstance.setLevel(LogLevel.Error)
|
||||
const web3 = new Web3('http://127.0.0.1:8545')
|
||||
|
||||
export default {
|
||||
metadataStoreUri: 'http://aquarius:5000',
|
||||
metadataCacheUri: 'http://aquarius:5000',
|
||||
providerUri: 'http://localhost:8030',
|
||||
nodeUri: `http://localhost:${process.env.ETH_PORT || 8545}`,
|
||||
verbose: LogLevel.Error,
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { MetadataStore } from '../../../src/metadatastore/MetadataStore'
|
||||
import { MetadataCache } from '../../../src/metadatacache/MetadataCache'
|
||||
import { DDO } from '../../../src/ddo/DDO'
|
||||
import DID from '../../../src/ocean/DID'
|
||||
|
||||
const ddoStore: Map<string, any> = new Map<string, any>()
|
||||
|
||||
export default class MetadataStoreMock extends MetadataStore {
|
||||
export default class MetadataCacheMock extends MetadataCache {
|
||||
public async getAccessUrl(accessToken: any, payload: any): Promise<string> {
|
||||
return 'http://test/test'
|
||||
}
|
@ -4,7 +4,7 @@ import { LoggerInstance, LogLevel } from '../../src/utils'
|
||||
LoggerInstance.setLevel(LogLevel.Error)
|
||||
|
||||
export default {
|
||||
metadataStoreUri: 'http://localhost:5000',
|
||||
metadataCacheUri: 'http://localhost:5000',
|
||||
providerUri: 'http://localhost:8030',
|
||||
nodeUri: `http://localhost:${process.env.ETH_PORT || 8545}`,
|
||||
parityUri: 'http://localhost:9545',
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { assert, spy, use } from 'chai'
|
||||
import spies from 'chai-spies'
|
||||
import { Ocean } from '../../../src/ocean/Ocean'
|
||||
import { MetadataStore, SearchQuery } from '../../../src/metadatastore/MetadataStore'
|
||||
import { MetadataCache, SearchQuery } from '../../../src/metadatacache/MetadataCache'
|
||||
import { DDO } from '../../../src/ddo/DDO'
|
||||
import DID from '../../../src/ocean/DID'
|
||||
import config from '../config'
|
||||
@ -10,13 +10,13 @@ import { responsify, getSearchResults } from '../helpers'
|
||||
|
||||
use(spies)
|
||||
|
||||
describe('MetadataStore', () => {
|
||||
describe('MetadataCache', () => {
|
||||
let ocean: Ocean
|
||||
let metadataStore: MetadataStore
|
||||
let metadataCache: MetadataCache
|
||||
|
||||
beforeEach(async () => {
|
||||
ocean = await Ocean.getInstance(config)
|
||||
metadataStore = ocean.metadatastore // eslint-disable-line prefer-destructuring
|
||||
metadataCache = ocean.metadatacache // eslint-disable-line prefer-destructuring
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@ -37,9 +37,9 @@ describe('MetadataStore', () => {
|
||||
} as SearchQuery
|
||||
|
||||
it('should query metadata', async () => {
|
||||
spy.on(metadataStore.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
spy.on(metadataCache.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
|
||||
const result = await metadataStore.queryMetadata(query)
|
||||
const result = await metadataCache.queryMetadata(query)
|
||||
assert.typeOf(result.results, 'array')
|
||||
assert.lengthOf(result.results, 1)
|
||||
assert.equal(result.page, 0)
|
||||
@ -48,7 +48,7 @@ describe('MetadataStore', () => {
|
||||
})
|
||||
|
||||
it('should query metadata with a new instance', async () => {
|
||||
const metadatastoreNew = new MetadataStore(config.metadataStoreUri, LoggerInstance)
|
||||
const metadatastoreNew = new MetadataCache(config.metadataCacheUri, LoggerInstance)
|
||||
spy.on(metadatastoreNew.fetch, 'post', () =>
|
||||
responsify(getSearchResults([new DDO()]))
|
||||
)
|
||||
@ -62,9 +62,9 @@ describe('MetadataStore', () => {
|
||||
})
|
||||
|
||||
it('should query metadata and return real ddo', async () => {
|
||||
spy.on(metadataStore.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
spy.on(metadataCache.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
|
||||
const result = await metadataStore.queryMetadata(query)
|
||||
const result = await metadataCache.queryMetadata(query)
|
||||
assert.typeOf(result.results, 'array')
|
||||
assert.lengthOf(result.results, 1)
|
||||
assert.isDefined(result.results[0].findServiceById)
|
||||
@ -78,9 +78,9 @@ describe('MetadataStore', () => {
|
||||
id: did.getId()
|
||||
})
|
||||
|
||||
spy.on(metadataStore.fetch, 'post', () => responsify(ddo))
|
||||
spy.on(metadataCache.fetch, 'post', () => responsify(ddo))
|
||||
|
||||
const result: DDO = await metadataStore.storeDDO(ddo)
|
||||
const result: DDO = await metadataCache.storeDDO(ddo)
|
||||
assert(result)
|
||||
assert(result.id === ddo.id)
|
||||
})
|
||||
@ -93,15 +93,15 @@ describe('MetadataStore', () => {
|
||||
id: did.getId()
|
||||
})
|
||||
|
||||
spy.on(metadataStore.fetch, 'post', () => responsify(ddo))
|
||||
spy.on(metadataStore.fetch, 'get', () => responsify(ddo))
|
||||
spy.on(metadataCache.fetch, 'post', () => responsify(ddo))
|
||||
spy.on(metadataCache.fetch, 'get', () => responsify(ddo))
|
||||
|
||||
const storageResult: DDO = await metadataStore.storeDDO(ddo)
|
||||
const storageResult: DDO = await metadataCache.storeDDO(ddo)
|
||||
assert(storageResult)
|
||||
|
||||
assert(storageResult.id === did.getId())
|
||||
|
||||
const restrieveResult: DDO = await metadataStore.retrieveDDO(did)
|
||||
const restrieveResult: DDO = await metadataCache.retrieveDDO(did)
|
||||
assert(restrieveResult)
|
||||
|
||||
assert(restrieveResult.id === did.getId())
|
@ -1,7 +1,7 @@
|
||||
import { assert, spy, use } from 'chai'
|
||||
import spies from 'chai-spies'
|
||||
|
||||
import { SearchQuery, MetadataStore } from '../../../src/metadatastore/MetadataStore'
|
||||
import { SearchQuery, MetadataCache } from '../../../src/metadatacache/MetadataCache'
|
||||
import { Ocean } from '../../../src/ocean/Ocean'
|
||||
import config from '../config'
|
||||
import { DDO } from '../../../src/lib'
|
||||
@ -11,11 +11,11 @@ use(spies)
|
||||
|
||||
describe('Assets', () => {
|
||||
let ocean: Ocean
|
||||
let metadataStore: MetadataStore
|
||||
let metadataCache: MetadataCache
|
||||
|
||||
beforeEach(async () => {
|
||||
ocean = await Ocean.getInstance(config)
|
||||
metadataStore = ocean.metadatastore // eslint-disable-line prefer-destructuring
|
||||
metadataCache = ocean.metadatacache // eslint-disable-line prefer-destructuring
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@ -35,7 +35,7 @@ describe('Assets', () => {
|
||||
}
|
||||
} as SearchQuery
|
||||
|
||||
spy.on(metadataStore.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
spy.on(metadataCache.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
const assets = await ocean.assets.query(query)
|
||||
|
||||
assert.typeOf(assets.results, 'array')
|
||||
@ -47,7 +47,7 @@ describe('Assets', () => {
|
||||
describe('#search()', () => {
|
||||
it('should search for assets', async () => {
|
||||
const text = 'office'
|
||||
spy.on(metadataStore.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
spy.on(metadataCache.fetch, 'post', () => responsify(getSearchResults([new DDO()])))
|
||||
const assets = await ocean.assets.search(text)
|
||||
|
||||
assert.typeOf(assets.results, 'array')
|
||||
|
Loading…
x
Reference in New Issue
Block a user