2018-10-18 09:19:10 +02:00
|
|
|
import {assert} from "chai"
|
2018-11-12 12:09:42 +01:00
|
|
|
import AquariusConnectorProvider from "../../src/aquarius/AquariusConnectorProvider"
|
2018-10-26 10:40:46 +02:00
|
|
|
import AquariusProvider from "../../src/aquarius/AquariusProvider"
|
2018-11-05 10:01:58 +01:00
|
|
|
import SearchQuery from "../../src/aquarius/query/SearchQuery"
|
2018-10-16 14:56:18 +02:00
|
|
|
import ConfigProvider from "../../src/ConfigProvider"
|
2018-11-05 10:01:58 +01:00
|
|
|
import DDO from "../../src/ddo/DDO"
|
2018-11-07 14:33:56 +01:00
|
|
|
import MetaData from "../../src/ddo/MetaData"
|
2018-11-14 15:44:25 +01:00
|
|
|
import Service from "../../src/ddo/Service"
|
2018-10-16 14:56:18 +02:00
|
|
|
import Account from "../../src/ocean/Account"
|
2018-10-05 12:34:18 +02:00
|
|
|
import Ocean from "../../src/ocean/Ocean"
|
2018-11-12 12:09:42 +01:00
|
|
|
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
|
2018-10-26 13:37:09 +02:00
|
|
|
import SecretStoreProvider from "../../src/secretstore/SecretStoreProvider"
|
2018-10-16 14:56:18 +02:00
|
|
|
import config from "../config"
|
2018-11-07 14:33:56 +01:00
|
|
|
import TestContractHandler from "../keeper/TestContractHandler"
|
2018-10-26 10:40:46 +02:00
|
|
|
import AquariusMock from "../mocks/Aquarius.mock"
|
2018-11-12 12:09:42 +01:00
|
|
|
import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
|
2018-10-26 13:37:09 +02:00
|
|
|
import SecretStoreMock from "../mocks/SecretStore.mock"
|
2018-10-05 12:34:18 +02:00
|
|
|
|
|
|
|
let ocean: Ocean
|
2018-10-16 14:56:18 +02:00
|
|
|
let accounts: Account[]
|
2018-10-17 18:24:01 +02:00
|
|
|
let testPublisher: Account
|
|
|
|
|
2018-10-05 12:34:18 +02:00
|
|
|
describe("Ocean", () => {
|
|
|
|
|
2018-10-26 10:40:46 +02:00
|
|
|
before(async () => {
|
|
|
|
ConfigProvider.setConfig(config)
|
2018-10-26 11:57:26 +02:00
|
|
|
AquariusProvider.setAquarius(new AquariusMock(config))
|
2018-10-26 13:37:09 +02:00
|
|
|
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
|
2018-11-07 14:33:56 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
2018-10-26 10:40:46 +02:00
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
accounts = await ocean.getAccounts()
|
|
|
|
|
|
|
|
testPublisher = accounts[0]
|
|
|
|
})
|
2018-10-26 11:57:26 +02:00
|
|
|
|
2018-10-18 13:06:52 +02:00
|
|
|
describe("#getInstance()", () => {
|
|
|
|
|
2018-11-05 10:01:58 +01:00
|
|
|
it("should get an instance of cean", async () => {
|
2018-10-18 13:06:52 +02:00
|
|
|
|
2018-11-05 10:01:58 +01:00
|
|
|
const oceanInstance: Ocean = await Ocean.getInstance(config)
|
2018-10-18 13:06:52 +02:00
|
|
|
|
2018-11-05 10:01:58 +01:00
|
|
|
assert(oceanInstance)
|
2018-10-18 13:06:52 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
describe("#getAccounts()", () => {
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
it("should list accounts", async () => {
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
const accs: Account[] = await ocean.getAccounts()
|
|
|
|
|
|
|
|
assert(10 === accs.length)
|
|
|
|
assert(0 === (await accs[5].getBalance()).ocn)
|
|
|
|
assert("string" === typeof accs[0].getId())
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|
|
|
|
|
2018-10-16 14:56:18 +02:00
|
|
|
})
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2018-11-07 14:33:56 +01:00
|
|
|
describe("#registerAsset()", () => {
|
2018-10-16 14:56:18 +02:00
|
|
|
|
|
|
|
it("should register an asset", async () => {
|
|
|
|
|
2018-11-07 14:33:56 +01:00
|
|
|
const metaData: MetaData = new MetaData()
|
|
|
|
const ddo: DDO = await ocean.registerAsset(metaData, testPublisher)
|
2018-10-16 14:56:18 +02:00
|
|
|
|
2018-11-07 14:33:56 +01:00
|
|
|
assert(ddo)
|
2018-11-05 10:01:58 +01:00
|
|
|
assert(ddo.id.startsWith("did:op:"))
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|
2018-10-16 14:56:18 +02:00
|
|
|
})
|
2018-10-05 12:34:18 +02:00
|
|
|
|
2018-10-26 10:40:46 +02:00
|
|
|
describe("#searchAssets()", () => {
|
|
|
|
|
|
|
|
it("should search for assets", async () => {
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
offset: 100,
|
|
|
|
page: 0,
|
|
|
|
query: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
sort: {
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
text: "Office",
|
2018-11-05 10:01:58 +01:00
|
|
|
} as SearchQuery
|
2018-10-26 10:40:46 +02:00
|
|
|
|
|
|
|
const assets: any[] = await ocean.searchAssets(query)
|
|
|
|
|
|
|
|
assert(assets)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
2018-11-05 17:50:56 +01:00
|
|
|
|
|
|
|
describe("#searchAssetsByText()", () => {
|
|
|
|
|
|
|
|
it("should search for assets", async () => {
|
|
|
|
const text = "office"
|
|
|
|
const assets: any[] = await ocean.searchAssetsByText(text)
|
|
|
|
|
|
|
|
assert(assets)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
2018-11-12 12:09:42 +01:00
|
|
|
|
|
|
|
describe("#signServiceAgreement()", () => {
|
|
|
|
|
|
|
|
it("should sign an service agreement", async () => {
|
|
|
|
|
|
|
|
const publisher = accounts[0]
|
|
|
|
const consumer = accounts[1]
|
|
|
|
|
|
|
|
const ddo: DDO = await ocean.registerAsset(new MetaData(), publisher)
|
|
|
|
|
2018-11-14 15:44:25 +01:00
|
|
|
const service: Service = ddo.findServiceByType("Access")
|
|
|
|
|
2018-11-12 12:09:42 +01:00
|
|
|
// @ts-ignore
|
|
|
|
AquariusConnectorProvider.setConnector(new AquariusConnectorMock(ddo))
|
|
|
|
|
2018-11-14 15:44:25 +01:00
|
|
|
const serviceAgreementSignature: any = await ocean.signServiceAgreement(ddo.id,
|
|
|
|
service.serviceDefinitionId, consumer)
|
2018-11-12 12:09:42 +01:00
|
|
|
|
|
|
|
assert(serviceAgreementSignature)
|
2018-11-14 15:44:25 +01:00
|
|
|
assert(serviceAgreementSignature.serviceAgreementId)
|
|
|
|
assert(serviceAgreementSignature.serviceAgreementSignature)
|
|
|
|
assert(serviceAgreementSignature.serviceAgreementSignature.startsWith("0x"))
|
2018-11-12 12:09:42 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#executeServiceAgreement()", () => {
|
|
|
|
|
|
|
|
it("should execute an service agreement", async () => {
|
|
|
|
|
|
|
|
const publisher = accounts[0]
|
|
|
|
const consumer = accounts[1]
|
|
|
|
|
|
|
|
const ddo: DDO = await ocean.registerAsset(new MetaData(), publisher)
|
2018-11-14 15:44:25 +01:00
|
|
|
const service: Service = ddo.findServiceByType("Access")
|
2018-11-12 12:09:42 +01:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
AquariusConnectorProvider.setConnector(new AquariusConnectorMock(ddo))
|
|
|
|
|
2018-11-14 15:44:25 +01:00
|
|
|
const signServiceAgreementResult: any = await ocean.signServiceAgreement(ddo.id,
|
|
|
|
service.serviceDefinitionId, consumer)
|
2018-11-12 12:09:42 +01:00
|
|
|
|
2018-11-14 15:44:25 +01:00
|
|
|
const serviceAgreement: ServiceAgreement = await ocean.executeServiceAgreement(ddo.id,
|
|
|
|
service.serviceDefinitionId, signServiceAgreementResult.serviceAgreementId,
|
|
|
|
signServiceAgreementResult.serviceAgreementSignature, consumer, publisher)
|
2018-11-12 12:09:42 +01:00
|
|
|
|
|
|
|
assert(serviceAgreement)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
2018-10-05 12:34:18 +02:00
|
|
|
})
|