mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
move template registration outside of asset registration again
This commit is contained in:
parent
7b399a049a
commit
6ab85631ca
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@oceanprotocol/squid",
|
"name": "@oceanprotocol/squid",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -120,9 +120,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@oceanprotocol/keeper-contracts": {
|
"@oceanprotocol/keeper-contracts": {
|
||||||
"version": "0.3.16",
|
"version": "0.3.17",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.3.16.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.3.17.tgz",
|
||||||
"integrity": "sha512-aEXJcyqj59YhaCg4me9GEyTF9xX6dYAg4413puVE3sBcOpQUsX27W+uVOd9nQe+b95+Yq7I+dmg1kjN0Xtthpg=="
|
"integrity": "sha512-2/dXD2DrHEToVf4QBC+LBI1uMvptW2GnFIQCp3Bfir79crTVKcGymYbpKLUnRO11tb/Hp7ZgdInIFGcxDDLnQA=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/secret-store-client": {
|
"@oceanprotocol/secret-store-client": {
|
||||||
"version": "0.0.7",
|
"version": "0.0.7",
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
"node": ">=8 <10"
|
"node": ">=8 <10"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/keeper-contracts": "^0.3.16",
|
"@oceanprotocol/keeper-contracts": "^0.3.17",
|
||||||
"@oceanprotocol/secret-store-client": "0.0.7",
|
"@oceanprotocol/secret-store-client": "0.0.7",
|
||||||
"bignumber.js": "^8.0.1",
|
"bignumber.js": "^8.0.1",
|
||||||
"eth-crypto": "^1.2.5",
|
"eth-crypto": "^1.2.5",
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import Contract from "web3-eth-contract"
|
import Contract from "web3-eth-contract"
|
||||||
|
import ServiceAgreementTemplate from "../ocean/ServiceAgreements/ServiceAgreementTemplate"
|
||||||
|
import Access from "../ocean/ServiceAgreements/Templates/Access"
|
||||||
|
import FitchainCompute from "../ocean/ServiceAgreements/Templates/FitchainCompute"
|
||||||
import Logger from "../utils/Logger"
|
import Logger from "../utils/Logger"
|
||||||
import Keeper from "./Keeper"
|
import Keeper from "./Keeper"
|
||||||
import Web3Provider from "./Web3Provider"
|
import Web3Provider from "./Web3Provider"
|
||||||
@ -15,13 +18,24 @@ export default class ContractHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async deployContracts() {
|
public static async prepareContracts() {
|
||||||
Logger.log("Trying to deploy contracts")
|
|
||||||
|
|
||||||
const web3 = Web3Provider.getWeb3()
|
const web3 = Web3Provider.getWeb3()
|
||||||
|
|
||||||
const deployerAddress = (await web3.eth.getAccounts())[0]
|
const deployerAddress = (await web3.eth.getAccounts())[0]
|
||||||
|
|
||||||
|
// deploy contracts
|
||||||
|
await ContractHandler.deployContracts(deployerAddress)
|
||||||
|
|
||||||
|
// register templates
|
||||||
|
await new ServiceAgreementTemplate(new Access()).register(deployerAddress)
|
||||||
|
await new ServiceAgreementTemplate(new FitchainCompute()).register(deployerAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
private static contracts: Map<string, Contract> = new Map<string, Contract>()
|
||||||
|
|
||||||
|
private static async deployContracts(deployerAddress: string) {
|
||||||
|
Logger.log("Trying to deploy contracts")
|
||||||
|
|
||||||
// deploy libs
|
// deploy libs
|
||||||
/* not part of trilobite
|
/* not part of trilobite
|
||||||
const dll = await ContractHandler.deployContract("DLL", deployerAddress)
|
const dll = await ContractHandler.deployContract("DLL", deployerAddress)
|
||||||
@ -72,8 +86,6 @@ export default class ContractHandler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private static contracts: Map<string, Contract> = new Map<string, Contract>()
|
|
||||||
|
|
||||||
private static async load(what: string, where: string): Promise<Contract> {
|
private static async load(what: string, where: string): Promise<Contract> {
|
||||||
const web3 = Web3Provider.getWeb3()
|
const web3 = Web3Provider.getWeb3()
|
||||||
// Logger.log("Loading", what, "from", where)
|
// Logger.log("Loading", what, "from", where)
|
||||||
|
@ -24,6 +24,11 @@ export default class ServiceAgreement extends ContractBase {
|
|||||||
return this.call("getTemplateStatus", [templateId])
|
return this.call("getTemplateStatus", [templateId])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getTemplateOwner(templateId: string) {
|
||||||
|
|
||||||
|
return this.call("getTemplateOwner", [templateId])
|
||||||
|
}
|
||||||
|
|
||||||
public async getAgreementStatus(serviceDefinitionId: string) {
|
public async getAgreementStatus(serviceDefinitionId: string) {
|
||||||
|
|
||||||
return this.call("getAgreementStatus", [serviceDefinitionId])
|
return this.call("getAgreementStatus", [serviceDefinitionId])
|
||||||
|
@ -49,13 +49,11 @@ export default class Ocean {
|
|||||||
|
|
||||||
const assetId: string = IdGenerator.generateId()
|
const assetId: string = IdGenerator.generateId()
|
||||||
const did: string = `did:op:${assetId}`
|
const did: string = `did:op:${assetId}`
|
||||||
|
const template = new Access()
|
||||||
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
const serviceAgreementTemplate = new ServiceAgreementTemplate(template)
|
||||||
await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods,
|
|
||||||
asset.publisher)
|
|
||||||
|
|
||||||
// get condition keys from template
|
// get condition keys from template
|
||||||
const conditions: Condition[] = serviceAgreementTemplate.getConditions()
|
const conditions: Condition[] = await serviceAgreementTemplate.getConditions()
|
||||||
|
|
||||||
// create ddo conditions out of the keys
|
// create ddo conditions out of the keys
|
||||||
const ddoConditions: DDOCondition[] = conditions.map((condition: Condition): DDOCondition => {
|
const ddoConditions: DDOCondition[] = conditions.map((condition: Condition): DDOCondition => {
|
||||||
@ -78,7 +76,7 @@ export default class Ocean {
|
|||||||
id: did,
|
id: did,
|
||||||
service: [
|
service: [
|
||||||
{
|
{
|
||||||
type: Access.templateName,
|
type: template.templateName,
|
||||||
// tslint:disable
|
// tslint:disable
|
||||||
serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}",
|
serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}",
|
||||||
purchaseEndpoint: "http://mybrizo.org/api/v1/brizo/services/access/purchase?",
|
purchaseEndpoint: "http://mybrizo.org/api/v1/brizo/services/access/purchase?",
|
||||||
|
@ -3,53 +3,51 @@ import ServiceAgreement from "../../keeper/contracts/ServiceAgreement"
|
|||||||
import Web3Provider from "../../keeper/Web3Provider"
|
import Web3Provider from "../../keeper/Web3Provider"
|
||||||
import MethodReflection from "../../models/MethodReflection"
|
import MethodReflection from "../../models/MethodReflection"
|
||||||
import ValuePair from "../../models/ValuePair"
|
import ValuePair from "../../models/ValuePair"
|
||||||
|
import Logger from "../../utils/Logger"
|
||||||
import Account from "../Account"
|
import Account from "../Account"
|
||||||
import OceanBase from "../OceanBase"
|
import OceanBase from "../OceanBase"
|
||||||
import Condition from "./Condition"
|
import Condition from "./Condition"
|
||||||
import Method from "./Method"
|
import Method from "./Method"
|
||||||
|
import TemplateBase from "./Templates/TemplateBase"
|
||||||
|
|
||||||
export default class ServiceAgreementTemplate extends OceanBase {
|
export default class ServiceAgreementTemplate extends OceanBase {
|
||||||
|
|
||||||
public static async registerServiceAgreementsTemplate(serviceName: string, methods: Method[],
|
public async register(templateOwnerAddress: string)
|
||||||
templateOwner: Account)
|
: Promise<boolean> {
|
||||||
: Promise<ServiceAgreementTemplate> {
|
|
||||||
|
|
||||||
const methodReflections: MethodReflection[] =
|
|
||||||
await Promise.all(methods.map(async (method: Method) => {
|
|
||||||
const methodReflection = await
|
|
||||||
ContractReflector.reflectContractMethod(method.path)
|
|
||||||
return methodReflection
|
|
||||||
}))
|
|
||||||
|
|
||||||
const dependencyMatrix: number[] =
|
const dependencyMatrix: number[] =
|
||||||
await Promise.all(methods.map(async (method: Method) => {
|
await Promise.all(this.template.Methods.map(async (method: Method) => {
|
||||||
// tslint:disable
|
// tslint:disable
|
||||||
return method.dependency | method.timeout
|
return method.dependency | method.timeout
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const serviceAgreement: ServiceAgreement = await ServiceAgreement.getInstance()
|
const serviceAgreement: ServiceAgreement = await ServiceAgreement.getInstance()
|
||||||
|
|
||||||
|
const methodReflections = await this.getMethodReflections()
|
||||||
|
|
||||||
|
const owner = await this.getOwner()
|
||||||
|
|
||||||
|
if (!owner.getId().startsWith("0x0")) {
|
||||||
|
Logger.error(`Template with id "${this.template.id}" already registered.`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
const receipt = await serviceAgreement.setupAgreementTemplate(
|
const receipt = await serviceAgreement.setupAgreementTemplate(
|
||||||
methodReflections, dependencyMatrix,
|
methodReflections, dependencyMatrix,
|
||||||
Web3Provider.getWeb3().utils.fromAscii(serviceName),
|
Web3Provider.getWeb3().utils.fromAscii(this.template.templateName),
|
||||||
templateOwner.getId())
|
templateOwnerAddress)
|
||||||
|
|
||||||
const serviceAgreementTemplateId =
|
const templateId = receipt.events.SetupAgreementTemplate.returnValues.serviceTemplateId
|
||||||
receipt.events.SetupAgreementTemplate.returnValues.serviceTemplateId
|
|
||||||
|
|
||||||
const conditions: Condition[] = methodReflections.map((methodReflection, i) => {
|
if (templateId !== this.template.id) {
|
||||||
return {
|
throw new Error(`TemplateId missmatch on ${this.template.templateName}! Should be "${this.template.id}" but is ${templateId}`)
|
||||||
methodReflection,
|
}
|
||||||
timeout: methods[i].timeout,
|
|
||||||
condtionKey: ServiceAgreementTemplate.generateConditionsKey(serviceAgreementTemplateId,
|
|
||||||
methodReflection),
|
|
||||||
} as Condition
|
|
||||||
})
|
|
||||||
|
|
||||||
return new ServiceAgreementTemplate(
|
if (receipt.status) {
|
||||||
serviceAgreementTemplateId,
|
Logger.error("Registering template failed")
|
||||||
conditions,
|
}
|
||||||
templateOwner)
|
|
||||||
|
return receipt.status
|
||||||
}
|
}
|
||||||
|
|
||||||
private static generateConditionsKey(serviceAgreementTemplateId: string, methodReflection: MethodReflection)
|
private static generateConditionsKey(serviceAgreementTemplateId: string, methodReflection: MethodReflection)
|
||||||
@ -62,9 +60,8 @@ export default class ServiceAgreementTemplate extends OceanBase {
|
|||||||
return Web3Provider.getWeb3().utils.soliditySha3(...values).toString("hex")
|
return Web3Provider.getWeb3().utils.soliditySha3(...values).toString("hex")
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor(serviceAgreementTemplateId, private conditions: Condition[],
|
public constructor(private template: TemplateBase) {
|
||||||
private owner: Account) {
|
super(template.id)
|
||||||
super(serviceAgreementTemplateId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,11 +72,34 @@ export default class ServiceAgreementTemplate extends OceanBase {
|
|||||||
return serviceAgreement.getTemplateStatus(this.getId())
|
return serviceAgreement.getTemplateStatus(this.getId())
|
||||||
}
|
}
|
||||||
|
|
||||||
public getOwner(): Account {
|
public async getOwner(): Promise<Account> {
|
||||||
return this.owner
|
const serviceAgreement: ServiceAgreement = await ServiceAgreement.getInstance()
|
||||||
|
|
||||||
|
return new Account(await serviceAgreement.getTemplateOwner(this.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
public getConditions(): Condition[] {
|
private async getMethodReflections(): Promise<MethodReflection[]> {
|
||||||
return this.conditions
|
const methodReflections: MethodReflection[] =
|
||||||
|
await Promise.all(this.template.Methods.map(async (method: Method) => {
|
||||||
|
const methodReflection = await
|
||||||
|
ContractReflector.reflectContractMethod(method.path)
|
||||||
|
return methodReflection
|
||||||
|
}))
|
||||||
|
return methodReflections
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getConditions(): Promise<Condition[]> {
|
||||||
|
const methodReflections = await this.getMethodReflections()
|
||||||
|
|
||||||
|
const conditions: Condition[] = methodReflections.map((methodReflection, i) => {
|
||||||
|
return {
|
||||||
|
methodReflection,
|
||||||
|
timeout: this.template.Methods[i].timeout,
|
||||||
|
condtionKey: ServiceAgreementTemplate.generateConditionsKey(this.getId(),
|
||||||
|
methodReflection),
|
||||||
|
} as Condition
|
||||||
|
})
|
||||||
|
|
||||||
|
return conditions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ import TemplateBase from "./TemplateBase"
|
|||||||
|
|
||||||
export default class Access extends TemplateBase {
|
export default class Access extends TemplateBase {
|
||||||
|
|
||||||
public static templateName: string = "Access"
|
public templateName: string = "Access"
|
||||||
public static id: string = "0x00000000000000000000000000000000000000000000000000000000000001"
|
public id: string = "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563"
|
||||||
public static Methods: Method[] = [
|
public Methods: Method[] = [
|
||||||
{
|
{
|
||||||
path: "PaymentConditions.lockPayment",
|
path: "PaymentConditions.lockPayment",
|
||||||
dependency: 0,
|
dependency: 0,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import Method from "../Method"
|
import Method from "../Method"
|
||||||
import TemplateBase from "./TemplateBase"
|
import TemplateBase from "./TemplateBase"
|
||||||
|
|
||||||
export default class Access extends TemplateBase {
|
export default class FitchainCompute extends TemplateBase {
|
||||||
|
|
||||||
public static templateName: string = "FitchainCompute"
|
public templateName: string = "FitchainCompute"
|
||||||
public static id: string = "0x00000000000000000000000000000000000000000000000000000000000002"
|
public id: string = "0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"
|
||||||
public static Methods: Method[] = [
|
public Methods: Method[] = [
|
||||||
{
|
{
|
||||||
path: "PaymentConditions.lockPayment",
|
path: "PaymentConditions.lockPayment",
|
||||||
dependency: 0,
|
dependency: 0,
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
export default class TemplateBase {
|
import Method from "../Method"
|
||||||
|
|
||||||
protected static templateName: string
|
export default abstract class TemplateBase {
|
||||||
protected static id: string = "0x00000000000000000000000000000000000000000000000000000000000000"
|
public Methods: Method[]
|
||||||
|
public templateName: string
|
||||||
|
public id: string = "0x00000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
|
||||||
|
constructor(id?: string) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ describe("ContractWrapperBase", () => {
|
|||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
await ContractHandler.deployContracts()
|
await ContractHandler.prepareContracts()
|
||||||
await wrappedContract.initMock()
|
await wrappedContract.initMock()
|
||||||
const ocean: Ocean = await Ocean.getInstance(config)
|
const ocean: Ocean = await Ocean.getInstance(config)
|
||||||
accounts = await ocean.getAccounts()
|
accounts = await ocean.getAccounts()
|
||||||
|
@ -7,7 +7,7 @@ describe("ContractHandler", () => {
|
|||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
await ContractHandler.deployContracts()
|
await ContractHandler.prepareContracts()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#get()", () => {
|
describe("#get()", () => {
|
||||||
|
@ -30,7 +30,7 @@ describe("Asset", () => {
|
|||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
AquariusProvider.setAquarius(new AquariusMock(config))
|
AquariusProvider.setAquarius(new AquariusMock(config))
|
||||||
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
|
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
|
||||||
await ContractHandler.deployContracts()
|
await ContractHandler.prepareContracts()
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
accounts = await ocean.getAccounts()
|
accounts = await ocean.getAccounts()
|
||||||
testPublisher = accounts[0]
|
testPublisher = accounts[0]
|
||||||
|
@ -26,7 +26,7 @@ describe("Ocean", () => {
|
|||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
AquariusProvider.setAquarius(new AquariusMock(config))
|
AquariusProvider.setAquarius(new AquariusMock(config))
|
||||||
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
|
SecretStoreProvider.setSecretStore(new SecretStoreMock(config))
|
||||||
await ContractHandler.deployContracts()
|
await ContractHandler.prepareContracts()
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
accounts = await ocean.getAccounts()
|
accounts = await ocean.getAccounts()
|
||||||
|
|
||||||
|
@ -19,30 +19,26 @@ import AquariusConnectorMock from "../mocks/AquariusConnector.mock"
|
|||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
let accounts: Account[]
|
let accounts: Account[]
|
||||||
let publisherAccount: Account
|
let publisherAccount: Account
|
||||||
let templateOwnerAccount: Account
|
|
||||||
let consumerAccount: Account
|
let consumerAccount: Account
|
||||||
|
|
||||||
let testServiceAgreementTemplate: ServiceAgreementTemplate
|
|
||||||
let serviceDefintion
|
let serviceDefintion
|
||||||
|
|
||||||
describe("ServiceAgreement", () => {
|
describe("ServiceAgreement", () => {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
await ContractHandler.deployContracts()
|
await ContractHandler.prepareContracts()
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
accounts = await ocean.getAccounts()
|
accounts = await ocean.getAccounts()
|
||||||
|
|
||||||
templateOwnerAccount = accounts[0]
|
|
||||||
publisherAccount = accounts[1]
|
publisherAccount = accounts[1]
|
||||||
consumerAccount = accounts[2]
|
consumerAccount = accounts[2]
|
||||||
|
|
||||||
testServiceAgreementTemplate =
|
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
||||||
await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods,
|
new ServiceAgreementTemplate(new Access())
|
||||||
templateOwnerAccount)
|
|
||||||
|
|
||||||
// get condition keys from template
|
// get condition keys from template
|
||||||
const conditions: Condition[] = testServiceAgreementTemplate.getConditions()
|
const conditions: Condition[] = await serviceAgreementTemplate.getConditions()
|
||||||
|
|
||||||
// create ddo conditions out of the keys
|
// create ddo conditions out of the keys
|
||||||
const ddoConditions: DDOCondition[] = conditions.map((condition): DDOCondition => {
|
const ddoConditions: DDOCondition[] = conditions.map((condition): DDOCondition => {
|
||||||
@ -62,7 +58,7 @@ describe("ServiceAgreement", () => {
|
|||||||
serviceDefintion = [
|
serviceDefintion = [
|
||||||
{
|
{
|
||||||
serviceDefinitionId: IdGenerator.generateId(),
|
serviceDefinitionId: IdGenerator.generateId(),
|
||||||
templateId: testServiceAgreementTemplate.getId(),
|
templateId: serviceAgreementTemplate.getId(),
|
||||||
conditions: ddoConditions,
|
conditions: ddoConditions,
|
||||||
} as Service,
|
} as Service,
|
||||||
]
|
]
|
||||||
|
@ -2,6 +2,7 @@ import {assert} from "chai"
|
|||||||
import ConfigProvider from "../../src/ConfigProvider"
|
import ConfigProvider from "../../src/ConfigProvider"
|
||||||
import ContractHandler from "../../src/keeper/ContractHandler"
|
import ContractHandler from "../../src/keeper/ContractHandler"
|
||||||
import Account from "../../src/ocean/Account"
|
import Account from "../../src/ocean/Account"
|
||||||
|
import IdGenerator from "../../src/ocean/IdGenerator"
|
||||||
import Ocean from "../../src/ocean/Ocean"
|
import Ocean from "../../src/ocean/Ocean"
|
||||||
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
||||||
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
||||||
@ -14,22 +15,23 @@ describe("ServiceAgreementTemplate", () => {
|
|||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
ConfigProvider.setConfig(config)
|
ConfigProvider.setConfig(config)
|
||||||
await ContractHandler.deployContracts()
|
await ContractHandler.prepareContracts()
|
||||||
ocean = await Ocean.getInstance(config)
|
ocean = await Ocean.getInstance(config)
|
||||||
accounts = await ocean.getAccounts()
|
accounts = await ocean.getAccounts()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#registerServiceAgreementsTemplate()", () => {
|
describe("#register()", () => {
|
||||||
it("should setup an agreement template", async () => {
|
it("should setup an agreement template", async () => {
|
||||||
|
|
||||||
const templateOwner = accounts[0]
|
const templateOwner = accounts[0]
|
||||||
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
||||||
await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods,
|
new ServiceAgreementTemplate(new Access(IdGenerator.generateId()))
|
||||||
templateOwner)
|
|
||||||
|
|
||||||
assert(serviceAgreementTemplate)
|
assert(serviceAgreementTemplate)
|
||||||
|
|
||||||
|
await serviceAgreementTemplate.register(templateOwner.getId())
|
||||||
|
|
||||||
assert(serviceAgreementTemplate.getId())
|
assert(serviceAgreementTemplate.getId())
|
||||||
assert(serviceAgreementTemplate.getOwner().getId() === templateOwner.getId())
|
assert((await serviceAgreementTemplate.getOwner()).getId() === templateOwner.getId())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -38,10 +40,11 @@ describe("ServiceAgreementTemplate", () => {
|
|||||||
|
|
||||||
const publisherAccount = accounts[0]
|
const publisherAccount = accounts[0]
|
||||||
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
||||||
await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods,
|
new ServiceAgreementTemplate(new Access(IdGenerator.generateId()))
|
||||||
publisherAccount)
|
|
||||||
assert(serviceAgreementTemplate)
|
assert(serviceAgreementTemplate)
|
||||||
|
|
||||||
|
await serviceAgreementTemplate.register(publisherAccount.getId())
|
||||||
|
|
||||||
const templateStatus = await serviceAgreementTemplate.getStatus()
|
const templateStatus = await serviceAgreementTemplate.getStatus()
|
||||||
assert(templateStatus === true)
|
assert(templateStatus === true)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user