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/ServiceAgreement.test.ts

90 lines
3.2 KiB
TypeScript
Raw Normal View History

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[]
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()
templateOwnerAccount = accounts[0]
publisherAccount = accounts[1]
consumerAccount = accounts[2]
2018-10-29 17:28:40 +01:00
const resourceName = "superb car data"
testServiceAgreementTemplate =
await ServiceAgreementTemplate.registerServiceAgreementsTemplate(resourceName, templateOwnerAccount)
2018-10-29 17:28:40 +01:00
})
describe("#executeServiceAgreement()", () => {
it("should execute an service agreement", async () => {
2018-10-29 17:28:40 +01:00
const did: string = IdGenerator.generateId()
const assetId: string = IdGenerator.generateId()
2018-10-29 17:28:40 +01:00
const serviceAgreement: ServiceAgreement =
await ServiceAgreement.signServiceAgreement(testServiceAgreementTemplate, publisherAccount,
did, assetId, consumerAccount)
2018-10-29 17:28:40 +01:00
assert(serviceAgreement)
const id = serviceAgreement.getId()
assert(id)
assert(id !== did)
2018-10-29 17:28:40 +01:00
})
})
describe("#getStatus()", () => {
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()
const assetId: string = IdGenerator.generateId()
2018-10-29 17:28:40 +01:00
const serviceAgreement: ServiceAgreement =
await ServiceAgreement.signServiceAgreement(testServiceAgreementTemplate, publisherAccount,
did, assetId, consumerAccount)
2018-10-29 17:28:40 +01:00
assert(serviceAgreement)
2018-10-29 17:28:40 +01:00
const status = await serviceAgreement.getStatus()
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
})
})
})