1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

improved exportation of typings related to DDOs

This commit is contained in:
Pedro Gutiérrez 2019-02-04 11:46:24 +01:00 committed by Pedro Gutiérrez
parent 9e51918f29
commit 518a784554
26 changed files with 413 additions and 433 deletions

View File

@ -1,5 +1,5 @@
import {URL} from "whatwg-url"
import DDO from "../ddo/DDO"
import { URL } from "whatwg-url"
import { DDO } from "../ddo/DDO"
import Config from "../models/Config"
import DID from "../ocean/DID"
import Logger from "../utils/Logger"

View File

@ -1,39 +0,0 @@
import StructuredMarkup from "./StructuredMarkup"
/**
* Additional Information of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#additional-information
*/
export default class AdditionalInformation {
/**
* An indication of update latency - i.e. How often are updates expected (seldom,
* annually, quarterly, etc.), or is the resource static that is never expected
* to get updated.
* @type {string}
* @example "yearly"
*/
public updateFrecuency: string = "yearly"
/**
* A link to machine-readable structured markup (such as ttl/json-ld/rdf)
* describing the dataset.
* @type {StructuredMarkup[]}
*/
public structuredMarkup: StructuredMarkup[] = [
{
uri: "http://skos.um.es/unescothes/C01194/jsonld",
mediaType: "application/ld+json",
} as StructuredMarkup,
{
uri: "http://skos.um.es/unescothes/C01194/turtle",
mediaType: "text/turtle",
} as StructuredMarkup,
]
/**
* Checksum of attributes to be able to compare if there are changes in
* the asset that you are purchasing.
* @type {string}
*/
public checksum: string
}

View File

@ -1,4 +1,4 @@
export default class Authentication {
public type: string = "RsaSignatureAuthentication2018"
public publicKey: string = "did:op:123456789abcdefghi#keys-1"
export interface Authentication {
public type: string
public publicKey: string
}

View File

@ -1,15 +1,48 @@
import Dependency from "./Dependency"
import Event from "./Event"
import Parameter from "./Parameter"
import { Event } from "./Event"
export default class Condition {
public name: string
public contractName: string = "AccessCondition"
public functionName: string = "lockPayment"
public timeout: number = 0
public conditionKey: string = "0x12122434"
public parameters: Parameter[]
public events: Event[]
public dependencies: Dependency[] = []
public isTerminalCondition: boolean = false
export interface Parameter {
name: string
type: string
value: any
}
export interface Dependency {
/**
* @example "lockPayment"
*/
name: string
/**
* @example 0
*/
timeout: number
}
export interface Condition {
name: string
/**
* @example "AccessCondition"
*/
contractName: string
/**
* @example "lockPayment"
*/
functionName: string
/**
* @example 0
*/
timeout: number
/**
* @example "0x12122434"
*/
conditionKey: string
parameters: Parameter[]
events: Event[]
/**
* @example []
*/
dependencies: Dependency[]
/**
* @example false
*/
isTerminalCondition: boolean
}

View File

@ -1,7 +1,7 @@
import Event from "./Event"
export default class Contract {
public contractName: string
public fulfillmentOperator: number
public events: Event[]
export interface Contract {
contractName: string
fulfillmentOperator: number
events: Event[]
}

View File

@ -1,26 +0,0 @@
/**
* Curation attributes of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#curation-attributes
*/
export default class Curation {
/**
* Decimal value between 0 and 1. 0 is the default value.
* @type {number}
* @example 0.93
*/
public rating: number = 0.93
/**
* Number of votes. 0 is the default value.
* @type {number}
* @example 123
*/
public numVotes: number = 123
/**
* Schema applied to calculate the rating.
* @type {number}
* @example "Binary Votting"
*/
public schema?: string = "Binary Votting"
}

View File

@ -1,12 +1,13 @@
import Authentication from "./Authentication"
import PublicKey from "./PublicKey"
import Service from "./Service"
import { Authentication } from "./Authentication"
import { PublicKey } from "./PublicKey"
import { Service } from "./Service"
import { Proof } from "./Proof"
/**
* DID Descriptor Object.
* Contains all the data related to an asset.
*/
export default class DDO {
export class DDO {
/**
* Serializes the DDO object.
@ -29,6 +30,7 @@ export default class DDO {
}
public "@context": string = "https://w3id.org/future-method/v1"
/**
* DID, descentralized ID.
* @type {string}
@ -37,13 +39,9 @@ export default class DDO {
public publicKey: PublicKey[]
public authentication: Authentication[]
public service: Service[]
public proof: Proof
public constructor(ddo?: {
id?: string,
publicKey?: PublicKey[],
authentication?: Authentication[],
service?: Service[],
}) {
public constructor(ddo?: Partial<DDO>) {
this.authentication = (ddo && ddo.authentication) || []
this.id = (ddo && ddo.id) || null
this.publicKey = (ddo && ddo.publicKey) || []

View File

@ -1,4 +0,0 @@
export default class Dependency {
public name: string = "lockPayment"
public timeout: number = 0
}

View File

@ -1,7 +1,20 @@
import EventHandler from "./EventHandler"
export default class Event {
public name: string
public actorType: string
public handler: EventHandler
export interface EventHandler {
/**
* @example "serviceAgreement"
*/
moduleName: string
/**
* @example "fulfillAgreement"
*/
functionName: string
/**
* @example "0.1"
*/
version: string
}
export interface Event {
name: string
actorType: string
handler: EventHandler
}

View File

@ -1,5 +0,0 @@
export default class EventHandler {
public moduleName: string = "serviceAgreement"
public functionName: string = "fulfillAgreement"
public version: string = "0.1"
}

View File

@ -1,65 +1,209 @@
import AdditionalInformation from "./AdditionalInformation"
import Curation from "./Curation"
import MetaDataBase from "./MetaDataBase"
import StructuredMarkup from "./StructuredMarkup"
/**
* Base attributes of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#base-attributes
*/
export class MetaDataBase {
const base: MetaDataBase = {
name: "UK Weather information 2011",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "text/csv",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
contentUrls: [
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
} as MetaDataBase
/**
* Descriptive name of the Asset.
* @type {string}
* @example "UK Weather information 2011"
*/
name: string
const curation: Curation = {
rating: 0.93,
numVotes: 123,
schema: "Binary Votting",
} as Curation
/**
* Type of the Asset. Helps to filter by the type of asset,
* initially ("dataset", "algorithm", "container", "workflow", "other").
* @type {string}
* @example "dataset"
*/
type: "dataset" | "algorithm" | "container" | "workflow" | "other"
const additionalInformation: AdditionalInformation = {
updateFrecuency: "yearly",
structuredMarkup: [
{
uri: "http://skos.um.es/unescothes/C01194/jsonld",
mediaType: "application/ld+json",
} as StructuredMarkup,
{
uri: "http://skos.um.es/unescothes/C01194/turtle",
mediaType: "text/turtle",
} as StructuredMarkup,
],
} as AdditionalInformation
/**
* Details of what the resource is. For a dataset, this attribute
* explains what the data represents and what it can be used for.
* @type {string}
* @example "Weather information of UK including temperature and humidity"
*/
description?: string
export default class MetaData {
/**
* The date on which the asset was created or was added.
* @type {string}
* @example "2012-10-10T17:00:000Z"
*/
dateCreated: string
public additionalInformation: AdditionalInformation
public base: MetaDataBase
public curation: Curation
/**
* Size of the asset (e.g. 18MB). In the absence of a unit (MB, kB etc.), kB will be assumed.
* @type {string}
* @example "3.1gb"
*/
size: string
constructor(metaData?: MetaData) {
this.additionalInformation = (metaData && metaData.additionalInformation) || additionalInformation
this.base = (metaData && metaData.base) || base
this.curation = (metaData && metaData.curation) || curation
}
/**
* Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.).
* @type {string}
* @example "Met Office"
*/
author: string
/**
* Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ).
* If it's not specified, the following value will be added: "No License Specified".
* @type {string}
* @example "CC-BY"
*/
license: string
/**
* The party holding the legal copyright. Empty by default.
* @type {string}
* @example "Met Office"
*/
copyrightHolder?: string
/**
* File encoding.
* @type {string}
* @example "UTF-8"
*/
encoding?: string
/**
* File compression (e.g. no, gzip, bzip2, etc).
* @type {string}
* @example "zip"
*/
compression?: string
/**
* File format, if applicable.
* @type {string}
* @example "text/csv"
*/
contentType: string
/**
* Example of the concept of this asset. This example is part
* of the metadata, not an external link.
* @type {string}
* @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68"
*/
workExample?: string
/**
* List of content URLs resolving the Asset files.
* @type {string | string[]}
* @example "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip"
*/
contentUrls: string | string[]
/**
* Mapping of links for data samples, or links to find out more information.
* Links may be to either a URL or another Asset. We expect marketplaces to
* converge on agreements of typical formats for linked data: The Ocean Protocol
* itself does not mandate any specific formats as these requirements are likely
* to be domain-specific.
* @type {any[]}
* @example
* [
* {
* anotherSample: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/",
* },
* {
* fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/",
* },
* ]
*/
links?: {[name: string]: string}[]
/**
* The language of the content. Please use one of the language
* codes from the {@link https://tools.ietf.org/html/bcp47 IETF BCP 47 standard}.
* @type {String}
* @example "en"
*/
inLanguage?: string
/**
* Keywords or tags used to describe this content. Multiple entries in a keyword
* list are typically delimited by commas. Empty by default.
* @type {String}
* @example "weather, uk, 2011, temperature, humidity"
*/
tags?: string
/**
* Price of the asset.
* @type {String}
* @example 10
*/
price: number
}
/**
* Curation attributes of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#curation-attributes
*/
export interface Curation {
/**
* Decimal value between 0 and 1. 0 is the default value.
* @type {number}
* @example 0.93
*/
rating: number
/**
* Number of votes. 0 is the default value.
* @type {number}
* @example 123
*/
numVotes: number
/**
* Schema applied to calculate the rating.
* @type {number}
* @example "Binary Votting"
*/
schema?: string
}
/**
* Additional Information of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#additional-information
*/
export interface AdditionalInformation {
/**
* An indication of update latency - i.e. How often are updates expected (seldom,
* annually, quarterly, etc.), or is the resource static that is never expected
* to get updated.
* @type {string}
* @example "yearly"
*/
updateFrecuency: string
/**
* A link to machine-readable structured markup (such as ttl/json-ld/rdf)
* describing the dataset.
* @type {StructuredMarkup[]}
*/
structuredMarkup: {
uri: string
mediaType: string
}[]
/**
* Checksum of attributes to be able to compare if there are changes in
* the asset that you are purchasing.
* @type {string}
*/
checksum: string
}
export interface MetaData {
additionalInformation: AdditionalInformation
base: MetaDataBase
curation: Curation
}

View File

@ -1,147 +0,0 @@
/**
* Base attributes of Assets Metadata.
* @see https://github.com/oceanprotocol/OEPs/tree/master/8#base-attributes
*/
export default class MetaDataBase {
/**
* Descriptive name of the Asset.
* @type {string}
* @example "UK Weather information 2011"
*/
public name: string = "UK Weather information 2011"
/**
* Type of the Asset. Helps to filter by the type of asset,
* initially ("dataset", "algorithm", "container", "workflow", "other").
* @type {string}
* @example "dataset"
*/
public type: "dataset" | "algorithm" | "container" | "workflow" | "other" = "dataset"
/**
* Details of what the resource is. For a dataset, this attribute
* explains what the data represents and what it can be used for.
* @type {string}
* @example "Weather information of UK including temperature and humidity"
*/
public description?: string = "Weather information of UK including temperature and humidity"
/**
* The date on which the asset was created or was added.
* @type {string}
* @example "2012-10-10T17:00:000Z"
*/
public dateCreated: string = "2012-10-10T17:00:000Z"
/**
* Size of the asset (e.g. 18MB). In the absence of a unit (MB, kB etc.), kB will be assumed.
* @type {string}
* @example "3.1gb"
*/
public size: string = "3.1gb"
/**
* Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.).
* @type {string}
* @example "Met Office"
*/
public author: string = "Met Office"
/**
* Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ).
* If it's not specified, the following value will be added: "No License Specified".
* @type {string}
* @example "CC-BY"
*/
public license: string = "CC-BY"
/**
* The party holding the legal copyright. Empty by default.
* @type {string}
* @example "Met Office"
*/
public copyrightHolder?: string = "Met Office"
/**
* File encoding.
* @type {string}
* @example "UTF-8"
*/
public encoding?: string = "UTF-8"
/**
* File compression (e.g. no, gzip, bzip2, etc).
* @type {string}
* @example "zip"
*/
public compression?: string = "zip"
/**
* File format, if applicable.
* @type {string}
* @example "text/csv"
*/
public contentType: string = "text/csv"
/**
* Example of the concept of this asset. This example is part
* of the metadata, not an external link.
* @type {string}
* @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68"
*/
public workExample?: string = "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68"
/**
* List of content URLs resolving the Asset files.
* @type {string | string[]}
* @example "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip"
*/
public contentUrls: string | string[] = [
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
]
/**
* Mapping of links for data samples, or links to find out more information.
* Links may be to either a URL or another Asset. We expect marketplaces to
* converge on agreements of typical formats for linked data: The Ocean Protocol
* itself does not mandate any specific formats as these requirements are likely
* to be domain-specific.
* @type {any[]}
*/
public links?: any[] = [
{
sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/",
},
{
sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/",
},
{
fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/",
},
]
/**
* The language of the content. Please use one of the language
* codes from the {@link https://tools.ietf.org/html/bcp47 IETF BCP 47 standard}.
* @type {String}
* @example "en"
*/
public inLanguage?: string = "en"
/**
* Keywords or tags used to describe this content. Multiple entries in a keyword
* list are typically delimited by commas. Empty by default.
* @type {String}
* @example "weather, uk, 2011, temperature, humidity"
*/
public tags?: string = "weather, uk, 2011, temperature, humidity"
/**
* Price of the asset.
* @type {String}
* @example 10
*/
public price: number = 10
}

View File

@ -1,5 +0,0 @@
export default class Parameter {
public name: string
public type: string
public value: any
}

6
src/ddo/Proof.ts Normal file
View File

@ -0,0 +1,6 @@
export interface Proof {
type: string
created: string
creator: string
signatureValue: string
}

View File

@ -1,7 +1,28 @@
export default class PublicKey {
public id: string = "did:op:123456789abcdefghi#keys-1"
public type: string = "Ed25519VerificationKey2018"
public owner: string = "did:op:123456789abcdefghi"
public publicKeyPem?: string = "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n"
public publicKeyBase58?: string = "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
/**
* Public key data.
*/
export interface PublicKey {
/**
* ID of the key.
* @type {string}
* @example "did:op:123456789abcdefghi#keys-1"
*/
id: string
/**
* Type of key.
* @type {string}
*/
type: 'Ed25519VerificationKey2018' | 'RsaVerificationKey2018' | 'EdDsaSAPublicKeySecp256k1'
/**
* Key owner.
* @type {string}
* @example "did:op:123456789abcdefghi"
*/
owner: string
publicKeyPem?: string
publicKeyBase58?: string
publicKeyHex?: string
}

View File

@ -1,15 +1,15 @@
import Condition from "./Condition"
import Contract from "./Contract"
import MetaData from "./MetaData"
import { Condition } from "./Condition"
import { Contract } from "./Contract"
import { MetaData } from "./MetaData"
export default class Service {
public type: string = "OpenIdConnectVersion1.0Service"
public serviceDefinitionId?: string
public templateId?: string
public serviceEndpoint: string = "https://openid.example.com/"
public purchaseEndpoint?: string
public description?: string = "My public social inbox"
public metadata?: MetaData = {} as MetaData
public serviceAgreementContract?: Contract
public conditions?: Condition[] = []
export interface Service {
type: string
serviceDefinitionId?: string
templateId?: string
serviceEndpoint: string
purchaseEndpoint?: string
description?: string
metadata?: MetaData
serviceAgreementContract?: Contract
conditions?: Condition[]
}

View File

@ -1,4 +0,0 @@
export default class StructuredMarkup {
public uri: string = "http://skos.um.es/unescothes/C01194/jsonld"
public mediaType: string = "application/ld+json"
}

View File

@ -1,6 +1,6 @@
{
"nodeUri": "http://localhost:8545",
"aquariusUri": "http://aquarius.dev-ocean.com:5000",
"aquariusUri": "https://nginx-aquarius.dev-ocean.com",
"brizoUri": "http://localhost:8030",
"parityUri": "http://localhost:9545",
"secretStoreUri": "http://localhost:12001",

View File

@ -1,15 +1,10 @@
import AquariusProvider from "../aquarius/AquariusProvider"
import SearchQuery from "../aquarius/query/SearchQuery"
import BrizoProvider from "../brizo/BrizoProvider"
import Authentication from "../ddo/Authentication"
import Condition from "../ddo/Condition"
import Contract from "../ddo/Contract"
import DDO from "../ddo/DDO"
import Event from "../ddo/Event"
import EventHandler from "../ddo/EventHandler"
import MetaData from "../ddo/MetaData"
import PublicKey from "../ddo/PublicKey"
import Service from "../ddo/Service"
import { Condition } from "../ddo/Condition"
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import { Service } from "../ddo/Service"
import ContractEvent from "../keeper/Event"
import EventListener from "../keeper/EventListener"
import Keeper from "../keeper/Keeper"
@ -88,7 +83,7 @@ export default class OceanAssets {
authentication: [{
type: "RsaSignatureAuthentication2018",
publicKey: did.getDid() + "#keys-1",
} as Authentication],
}],
id: did.getDid(),
publicKey: [
{
@ -96,7 +91,7 @@ export default class OceanAssets {
type: "Ed25519VerificationKey2018",
owner: did.getDid(),
publicKeyBase58: await publisher.getPublicKey(),
} as PublicKey,
},
],
service: [
{
@ -118,24 +113,24 @@ export default class OceanAssets {
moduleName: "payment",
functionName: "lockPayment",
version: "0.1",
} as EventHandler,
} as Event,
},
},
],
} as Contract,
},
conditions,
} as Service,
},
{
type: "Compute",
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(),
computeServiceDefintionId, "xxx", "xxx"),
serviceDefinitionId: computeServiceDefintionId,
} as Service,
},
{
type: "Metadata",
serviceEndpoint,
serviceDefinitionId: metadataServiceDefinitionId,
metadata,
} as Service,
},
],
})

View File

@ -1,7 +1,7 @@
import * as assert from "assert"
import Aquarius from "../../src/aquarius/Aquarius"
import SearchQuery from "../../src/aquarius/query/SearchQuery"
import DDO from "../../src/ddo/DDO"
import { DDO } from "../../src/ddo/DDO"
import DID from "../../src/ocean/DID"
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
import config from "../config"
@ -10,6 +10,7 @@ import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
describe("Aquarius", () => {
const aquarius: Aquarius = new Aquarius(config)
describe("#queryMetadata()", () => {
const query = {
@ -40,6 +41,7 @@ describe("Aquarius", () => {
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()]))
const result: DDO[] = await aquarius.queryMetadata(query)
console.log(result)
assert(result)
assert(result[0].findServiceById)
})

View File

@ -1,13 +1,9 @@
import {assert} from "chai"
import AdditionalInformation from "../../src/ddo/AdditionalInformation"
import Authentication from "../../src/ddo/Authentication"
import Curation from "../../src/ddo/Curation"
import DDO from "../../src/ddo/DDO"
import MetaData from "../../src/ddo/MetaData"
import MetaDataBase from "../../src/ddo/MetaDataBase"
import PublicKey from "../../src/ddo/PublicKey"
import Service from "../../src/ddo/Service"
import StructuredMarkup from "../../src/ddo/StructuredMarkup"
import { Authentication} from "../../src/ddo/Authentication"
import { DDO } from "../../src/ddo/DDO"
import { MetaData, MetaDataBase, Curation, AdditionalInformation } from "../../src/ddo/MetaData"
import { PublicKey } from "../../src/ddo/PublicKey"
import { Service } from "../../src/ddo/Service"
import * as jsonDDO from "../testdata/ddo.json"
describe("DDO", () => {
@ -26,12 +22,6 @@ describe("DDO", () => {
owner: "did:op:123456789abcdefghi",
publicKeyBase58: "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
} as PublicKey,
{
id: "did:op:123456789abcdefghi#keys-3",
type: "RsaPublicKeyExchangeKey2018",
owner: "did:op:123456789abcdefghi",
publicKeyPem: "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n",
} as PublicKey,
],
authentication: [
{
@ -137,11 +127,11 @@ describe("DDO", () => {
{
uri: "http://skos.um.es/unescothes/C01194/jsonld",
mediaType: "application/ld+json",
} as StructuredMarkup,
},
{
uri: "http://skos.um.es/unescothes/C01194/turtle",
mediaType: "text/turtle",
} as StructuredMarkup,
},
],
} as AdditionalInformation,
} as MetaData,

View File

@ -1,5 +1,5 @@
import Aquarius from "../../src/aquarius/Aquarius"
import DDO from "../../src/ddo/DDO"
import { DDO } from "../../src/ddo/DDO"
import DID from "../../src/ocean/DID"
const ddoStore: Map<string, any> = new Map<string, any>()

View File

@ -3,9 +3,8 @@ import AquariusProvider from "../../src/aquarius/AquariusProvider"
import SearchQuery from "../../src/aquarius/query/SearchQuery"
import BrizoProvider from "../../src/brizo/BrizoProvider"
import ConfigProvider from "../../src/ConfigProvider"
import DDO from "../../src/ddo/DDO"
import MetaData from "../../src/ddo/MetaData"
import Service from "../../src/ddo/Service"
import { DDO } from "../../src/ddo/DDO"
import { Service } from "../../src/ddo/Service"
import Account from "../../src/ocean/Account"
import Ocean from "../../src/ocean/Ocean"
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
@ -17,6 +16,7 @@ import AquariusMock from "../mocks/Aquarius.mock"
import BrizoMock from "../mocks/Brizo.mock"
import SecretStoreMock from "../mocks/SecretStore.mock"
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean
let accounts: Account[]
@ -24,6 +24,8 @@ let testPublisher: Account
describe("Ocean", () => {
const metadata = metadataMock
before(async () => {
ConfigProvider.setConfig(config)
AquariusProvider.setAquarius(new AquariusMock(config))
@ -37,7 +39,6 @@ describe("Ocean", () => {
})
describe("#getInstance()", () => {
it("should get an instance of cean", async () => {
const oceanInstance: Ocean = await Ocean.getInstance(config)
@ -47,7 +48,6 @@ describe("Ocean", () => {
})
describe("#getAccounts()", () => {
it("should list accounts", async () => {
const accs: Account[] = await ocean.getAccounts()
@ -56,30 +56,22 @@ describe("Ocean", () => {
assert(0 === (await accs[5].getBalance()).ocn)
assert("string" === typeof accs[0].getId())
})
})
describe("#resolveDID()", () => {
it("should resolve a did to a ddo", async () => {
const metaData: MetaData = new MetaData()
const ddo: DDO = await ocean.registerAsset(metaData, testPublisher)
const ddo: DDO = await ocean.registerAsset(metadata, testPublisher)
const resolvedDDO: DDO = await ocean.resolveDID(ddo.id)
assert(resolvedDDO)
assert(resolvedDDO.id === ddo.id)
})
})
describe("#registerAsset()", () => {
it("should register an asset", async () => {
const metaData: MetaData = new MetaData()
const ddo: DDO = await ocean.registerAsset(metaData, testPublisher)
const ddo: DDO = await ocean.registerAsset(metadata, testPublisher)
assert(ddo)
assert(ddo.id.startsWith("did:op:"))
@ -87,9 +79,7 @@ describe("Ocean", () => {
})
describe("#searchAssets()", () => {
it("should search for assets", async () => {
const query = {
offset: 100,
page: 0,
@ -106,36 +96,30 @@ describe("Ocean", () => {
assert(assets)
})
})
describe("#searchAssetsByText()", () => {
it("should search for assets", async () => {
const text = "office"
const assets: any[] = await ocean.searchAssetsByText(text)
assert(assets)
})
})
describe("#signServiceAgreement()", () => {
it("should sign an service agreement", async () => {
const publisher = accounts[0]
const consumer = accounts[1]
const metaData = new MetaData()
const ddo: DDO = await ocean.registerAsset(metaData, publisher)
const ddo: DDO = await ocean.registerAsset(metadata, publisher)
const service: Service = ddo.findServiceByType("Access")
// @ts-ignore
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo))
await consumer.requestTokens(metaData.base.price)
await consumer.requestTokens(metadata.base.price)
const signServiceAgreementResult: any = await ocean.signServiceAgreement(ddo.id,
service.serviceDefinitionId, consumer)
@ -146,17 +130,14 @@ describe("Ocean", () => {
assert(signServiceAgreementResult.serviceAgreementSignature.startsWith("0x"))
assert(signServiceAgreementResult.serviceAgreementSignature.length === 132)
})
})
describe("#executeServiceAgreement()", () => {
it("should execute a service agreement", async () => {
const publisher = accounts[0]
const consumer = accounts[1]
const ddo: DDO = await ocean.registerAsset(new MetaData(), publisher)
const ddo: DDO = await ocean.registerAsset(metadata, publisher)
const service: Service = ddo.findServiceByType("Access")
// @ts-ignore
@ -171,6 +152,5 @@ describe("Ocean", () => {
assert(serviceAgreement)
})
})
})

View File

@ -1,9 +1,8 @@
import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider"
import Condition from "../../src/ddo/Condition"
import DDO from "../../src/ddo/DDO"
import MetaData from "../../src/ddo/MetaData"
import Service from "../../src/ddo/Service"
import { Condition } from "../../src/ddo/Condition"
import { DDO } from "../../src/ddo/DDO"
import { Service } from "../../src/ddo/Service"
import Account from "../../src/ocean/Account"
import DID from "../../src/ocean/DID"
import IdGenerator from "../../src/ocean/IdGenerator"
@ -15,6 +14,8 @@ import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProv
import config from "../config"
import TestContractHandler from "../keeper/TestContractHandler"
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean
let accounts: Account[]
@ -28,6 +29,8 @@ const did: DID = DID.generate()
describe("ServiceAgreement", () => {
const metadata = metadataMock
before(async () => {
ConfigProvider.setConfig(config)
await TestContractHandler.prepareContracts()
@ -37,7 +40,6 @@ describe("ServiceAgreement", () => {
publisherAccount = accounts[1]
consumerAccount = accounts[2]
const metadata = new MetaData()
const serviceAgreementTemplate: ServiceAgreementTemplate =
new ServiceAgreementTemplate(new Access())

View File

@ -1,6 +1,5 @@
import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider"
import MetaData from "../../src/ddo/MetaData"
import Account from "../../src/ocean/Account"
import Ocean from "../../src/ocean/Ocean"
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
@ -9,12 +8,16 @@ import TemplateBase from "../../src/ocean/ServiceAgreements/Templates/TemplateBa
import config from "../config"
import TestContractHandler from "../keeper/TestContractHandler"
import TestIdGenerator from "../TestIdGenerator"
import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean
let accounts: Account[]
describe("ServiceAgreementTemplate", () => {
const metadata = metadataMock
before(async () => {
ConfigProvider.setConfig(config)
await TestContractHandler.prepareContracts()
@ -49,7 +52,7 @@ describe("ServiceAgreementTemplate", () => {
new ServiceAgreementTemplate(access)
assert(serviceAgreementTemplate)
const conds = await serviceAgreementTemplate.getConditions(new MetaData(),
const conds = await serviceAgreementTemplate.getConditions(metadata,
TestIdGenerator.generatePrefixedId())
assert(conds)
})

View File

@ -1,34 +1,57 @@
import MetaDataModel from "../../src/ddo/MetaData"
import MetaDataBase from "../../src/ddo/MetaDataBase"
import { MetaData } from "../../src/ddo/MetaData"
const MetaData = new MetaDataModel({
export const metadataMock: MetaData = {
base: {
name: "Office Humidity",
name: "UK Weather information 2011",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
dateCreated: "2012-10-10T17:00:000Z",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "text/csv",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
workExample: "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
contentUrls: [
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
{
// tslint:disable-next-line
sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"
},
{
// tslint:disable-next-line
sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"
},
{
fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/",
},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
} as MetaDataBase,
} as MetaDataModel)
export default MetaData
},
curation: {
rating: 0.93,
numVotes: 123,
schema: "Binary Votting",
},
additionalInformation: {
updateFrecuency: "yearly",
checksum: "",
structuredMarkup: [
{
uri: "http://skos.um.es/unescothes/C01194/jsonld",
mediaType: "application/ld+json",
},
{
uri: "http://skos.um.es/unescothes/C01194/turtle",
mediaType: "text/turtle",
},
],
},
}