2018-10-29 17:28:40 +01:00
|
|
|
import {assert} from "chai"
|
|
|
|
import ConfigProvider from "../../src/ConfigProvider"
|
|
|
|
import ContractHandler from "../../src/keeper/ContractHandler"
|
|
|
|
import Account from "../../src/ocean/Account"
|
|
|
|
import IdGenerator from "../../src/ocean/IdGenerator"
|
|
|
|
import Ocean from "../../src/ocean/Ocean"
|
|
|
|
import ServiceAgreement from "../../src/ocean/ServiceAgreement"
|
|
|
|
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreementTemplate"
|
2018-10-30 08:30:05 +01:00
|
|
|
import config from "../config"
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
let ocean: Ocean
|
|
|
|
let accounts: Account[]
|
2018-11-01 08:31:21 +01:00
|
|
|
let publisherAccount: Account
|
|
|
|
let templateOwnerAccount: Account
|
|
|
|
let consumerAccount: Account
|
|
|
|
|
2018-10-29 17:28:40 +01:00
|
|
|
let testServiceAgreementTemplate: ServiceAgreementTemplate
|
|
|
|
|
|
|
|
describe("ServiceAgreement", () => {
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
ConfigProvider.setConfig(config)
|
|
|
|
await ContractHandler.deployContracts()
|
|
|
|
ocean = await Ocean.getInstance(config)
|
|
|
|
accounts = await ocean.getAccounts()
|
|
|
|
|
2018-11-01 08:31:21 +01:00
|
|
|
templateOwnerAccount = accounts[0]
|
|
|
|
publisherAccount = accounts[1]
|
|
|
|
consumerAccount = accounts[2]
|
|
|
|
|
2018-10-29 17:28:40 +01:00
|
|
|
const resourceName = "superb car data"
|
|
|
|
testServiceAgreementTemplate =
|
2018-11-01 08:31:21 +01:00
|
|
|
await ServiceAgreementTemplate.registerServiceAgreementsTemplate(resourceName, templateOwnerAccount)
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#executeServiceAgreement()", () => {
|
2018-11-01 08:31:21 +01:00
|
|
|
it("should execute an service agreement", async () => {
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
const did: string = IdGenerator.generateId()
|
2018-11-01 08:31:21 +01:00
|
|
|
const assetId: string = IdGenerator.generateId()
|
|
|
|
|
2018-10-29 17:28:40 +01:00
|
|
|
const serviceAgreement: ServiceAgreement =
|
2018-11-01 08:31:21 +01:00
|
|
|
await ServiceAgreement.signServiceAgreement(testServiceAgreementTemplate, publisherAccount,
|
|
|
|
did, assetId, consumerAccount)
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
assert(serviceAgreement)
|
2018-11-01 08:31:21 +01:00
|
|
|
const id = serviceAgreement.getId()
|
|
|
|
assert(id)
|
|
|
|
assert(id !== did)
|
2018-10-29 17:28:40 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#getStatus()", () => {
|
2018-11-01 08:31:21 +01:00
|
|
|
it("should get the status of a newly created service agreement", async () => {
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
const did: string = IdGenerator.generateId()
|
2018-11-01 08:31:21 +01:00
|
|
|
const assetId: string = IdGenerator.generateId()
|
|
|
|
|
2018-10-29 17:28:40 +01:00
|
|
|
const serviceAgreement: ServiceAgreement =
|
2018-11-01 08:31:21 +01:00
|
|
|
await ServiceAgreement.signServiceAgreement(testServiceAgreementTemplate, publisherAccount,
|
|
|
|
did, assetId, consumerAccount)
|
2018-10-29 17:28:40 +01:00
|
|
|
|
2018-11-01 08:31:21 +01:00
|
|
|
assert(serviceAgreement)
|
2018-10-29 17:28:40 +01:00
|
|
|
const status = await serviceAgreement.getStatus()
|
2018-11-01 08:31:21 +01:00
|
|
|
assert(status === false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#grantAccess()", () => {
|
|
|
|
it("should grant access in that service agreement", async () => {
|
|
|
|
|
|
|
|
const did: string = IdGenerator.generateId()
|
|
|
|
const assetId: string = IdGenerator.generateId()
|
|
|
|
|
|
|
|
const resourceName = "nice service"
|
|
|
|
const serviceAgreementTemplate =
|
|
|
|
await ServiceAgreementTemplate.registerServiceAgreementsTemplate(resourceName, templateOwnerAccount)
|
|
|
|
|
|
|
|
const serviceAgreement: ServiceAgreement =
|
|
|
|
await ServiceAgreement.signServiceAgreement(serviceAgreementTemplate, publisherAccount,
|
|
|
|
did, assetId, consumerAccount)
|
|
|
|
assert(serviceAgreement)
|
|
|
|
|
|
|
|
const fulfilled: boolean = await serviceAgreement.grantAccess(did, IdGenerator.generateId())
|
|
|
|
assert(fulfilled)
|
2018-10-29 17:28:40 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|