2018-10-29 17:28:40 +01:00
|
|
|
import {assert} from "chai"
|
|
|
|
import ConfigProvider from "../../src/ConfigProvider"
|
|
|
|
import Account from "../../src/ocean/Account"
|
|
|
|
import Ocean from "../../src/ocean/Ocean"
|
2018-11-05 14:56:14 +01:00
|
|
|
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
2018-11-05 17:50:56 +01:00
|
|
|
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
2018-11-07 09:35:47 +01:00
|
|
|
import TemplateBase from "../../src/ocean/ServiceAgreements/Templates/TemplateBase"
|
2018-10-29 17:28:40 +01:00
|
|
|
import config from "../config"
|
2018-11-07 14:33:56 +01:00
|
|
|
import TestContractHandler from "../keeper/TestContractHandler"
|
2019-02-04 11:46:24 +01:00
|
|
|
import { metadataMock } from "../testdata/MetaData"
|
2019-02-04 18:13:54 +01:00
|
|
|
import TestIdGenerator from "../TestIdGenerator"
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
let ocean: Ocean
|
|
|
|
let accounts: Account[]
|
|
|
|
|
|
|
|
describe("ServiceAgreementTemplate", () => {
|
|
|
|
|
2019-02-04 11:46:24 +01:00
|
|
|
const metadata = metadataMock
|
|
|
|
|
2018-10-29 17:28:40 +01:00
|
|
|
before(async () => {
|
|
|
|
ConfigProvider.setConfig(config)
|
2018-11-07 14:33:56 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
2018-10-29 17:28:40 +01:00
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
accounts = await ocean.getAccounts()
|
|
|
|
})
|
|
|
|
|
2018-11-06 16:13:12 +01:00
|
|
|
describe("#register()", () => {
|
2018-11-07 08:43:04 +01:00
|
|
|
it("should setup an Access agreement template correctly", async () => {
|
2018-10-29 17:28:40 +01:00
|
|
|
|
2018-11-01 08:31:21 +01:00
|
|
|
const templateOwner = accounts[0]
|
2018-11-07 09:35:47 +01:00
|
|
|
const access: TemplateBase = new Access()
|
2018-12-17 14:29:09 +01:00
|
|
|
access.id = TestIdGenerator.generatePrefixedId()
|
2018-10-29 17:28:40 +01:00
|
|
|
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
2018-11-07 09:35:47 +01:00
|
|
|
new ServiceAgreementTemplate(access)
|
2018-10-29 17:28:40 +01:00
|
|
|
assert(serviceAgreementTemplate)
|
2018-11-06 16:13:12 +01:00
|
|
|
|
2018-11-07 09:35:47 +01:00
|
|
|
const registered: boolean = await serviceAgreementTemplate.register(templateOwner.getId())
|
|
|
|
assert(registered)
|
2018-11-06 16:13:12 +01:00
|
|
|
|
2018-10-29 17:28:40 +01:00
|
|
|
assert(serviceAgreementTemplate.getId())
|
2018-11-06 16:13:12 +01:00
|
|
|
assert((await serviceAgreementTemplate.getOwner()).getId() === templateOwner.getId())
|
2018-11-01 08:31:21 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-11-20 09:13:03 +01:00
|
|
|
describe("#getConditions()", () => {
|
|
|
|
it("should setup an Access agreement template correctly", async () => {
|
|
|
|
|
|
|
|
const access: TemplateBase = new Access()
|
2018-12-17 14:29:09 +01:00
|
|
|
access.id = TestIdGenerator.generatePrefixedId()
|
2018-11-20 09:13:03 +01:00
|
|
|
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
|
|
|
new ServiceAgreementTemplate(access)
|
|
|
|
assert(serviceAgreementTemplate)
|
|
|
|
|
2019-02-04 11:46:24 +01:00
|
|
|
const conds = await serviceAgreementTemplate.getConditions(metadata,
|
2018-12-17 14:29:09 +01:00
|
|
|
TestIdGenerator.generatePrefixedId())
|
2018-11-20 09:13:03 +01:00
|
|
|
assert(conds)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-11-01 08:31:21 +01:00
|
|
|
describe("#getStatus()", () => {
|
|
|
|
it("should get the status of a newly deployed agreement template", async () => {
|
|
|
|
|
|
|
|
const publisherAccount = accounts[0]
|
2018-11-07 09:35:47 +01:00
|
|
|
const access: TemplateBase = new Access()
|
2018-12-17 14:29:09 +01:00
|
|
|
access.id = TestIdGenerator.generatePrefixedId()
|
2018-11-01 08:31:21 +01:00
|
|
|
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
2018-11-07 09:35:47 +01:00
|
|
|
new ServiceAgreementTemplate(access)
|
2018-11-01 09:18:34 +01:00
|
|
|
assert(serviceAgreementTemplate)
|
2018-11-01 08:31:21 +01:00
|
|
|
|
2018-11-07 09:35:47 +01:00
|
|
|
const registered: boolean = await serviceAgreementTemplate.register(publisherAccount.getId())
|
|
|
|
assert(registered)
|
2018-11-06 16:13:12 +01:00
|
|
|
|
2018-11-01 08:31:21 +01:00
|
|
|
const templateStatus = await serviceAgreementTemplate.getStatus()
|
|
|
|
assert(templateStatus === true)
|
2018-10-29 17:28:40 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|