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

76 lines
2.9 KiB
TypeScript
Raw Normal View History

2018-10-29 17:28:40 +01:00
import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider"
import MetaData from "../../src/ddo/MetaData"
2018-10-29 17:28:40 +01:00
import Account from "../../src/ocean/Account"
import IdGenerator from "../../src/ocean/IdGenerator"
2018-10-29 17:28:40 +01:00
import Ocean from "../../src/ocean/Ocean"
2018-11-05 14:56:14 +01:00
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
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"
import TestContractHandler from "../keeper/TestContractHandler"
2018-10-29 17:28:40 +01:00
let ocean: Ocean
let accounts: Account[]
describe("ServiceAgreementTemplate", () => {
before(async () => {
ConfigProvider.setConfig(config)
await TestContractHandler.prepareContracts()
2018-10-29 17:28:40 +01:00
ocean = await Ocean.getInstance(config)
accounts = await ocean.getAccounts()
})
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
const templateOwner = accounts[0]
2018-11-07 09:35:47 +01:00
const access: TemplateBase = new Access()
access.id = IdGenerator.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-07 09:35:47 +01:00
const registered: boolean = await serviceAgreementTemplate.register(templateOwner.getId())
assert(registered)
2018-10-29 17:28:40 +01:00
assert(serviceAgreementTemplate.getId())
assert((await serviceAgreementTemplate.getOwner()).getId() === templateOwner.getId())
})
})
describe("#getConditions()", () => {
it("should setup an Access agreement template correctly", async () => {
const access: TemplateBase = new Access()
access.id = IdGenerator.generatePrefixedId()
const serviceAgreementTemplate: ServiceAgreementTemplate =
new ServiceAgreementTemplate(access)
assert(serviceAgreementTemplate)
const conds = await serviceAgreementTemplate.getConditions(new MetaData(), IdGenerator.generateId())
assert(conds)
})
})
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()
access.id = IdGenerator.generatePrefixedId()
const serviceAgreementTemplate: ServiceAgreementTemplate =
2018-11-07 09:35:47 +01:00
new ServiceAgreementTemplate(access)
assert(serviceAgreementTemplate)
2018-11-07 09:35:47 +01:00
const registered: boolean = await serviceAgreementTemplate.register(publisherAccount.getId())
assert(registered)
const templateStatus = await serviceAgreementTemplate.getStatus()
assert(templateStatus === true)
2018-10-29 17:28:40 +01:00
})
})
})