mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
adapt changes from keeper 0.3.18
This commit is contained in:
parent
c52762c877
commit
2194ae59c3
@ -10,12 +10,13 @@ export default class ServiceAgreement extends ContractBase {
|
||||
return serviceAgreement
|
||||
}
|
||||
|
||||
public async setupAgreementTemplate(methodReflections: MethodReflection[], dependencyMatrix: number[], name: any,
|
||||
ownerAddress: string): Promise<Receipt> {
|
||||
public async setupAgreementTemplate(templateId: string, methodReflections: MethodReflection[],
|
||||
dependencyMatrix: number[], name: any, ownerAddress: string)
|
||||
: Promise<Receipt> {
|
||||
|
||||
return this.send("setupAgreementTemplate", ownerAddress, [
|
||||
methodReflections.map((r) => r.address), methodReflections.map((r) => r.signature),
|
||||
dependencyMatrix, name, [0], 0,
|
||||
templateId, methodReflections.map((r) => r.address),
|
||||
methodReflections.map((r) => r.signature), dependencyMatrix, name, [0], 0,
|
||||
])
|
||||
}
|
||||
|
||||
|
@ -5,4 +5,8 @@ export default class IdGenerator {
|
||||
const id = `${v4()}${v4()}`
|
||||
return id.replace(/-/g, "")
|
||||
}
|
||||
|
||||
public static generatePrefixedId() {
|
||||
return "0x" + this.generateId()
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ export default class Ocean {
|
||||
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?",
|
||||
// the id of the service agreement?
|
||||
serviceDefinitionId: "0x" + IdGenerator.generateId(),
|
||||
serviceDefinitionId: IdGenerator.generatePrefixedId(),
|
||||
// the id of the service agreement template
|
||||
templateId: serviceAgreementTemplate.getId(),
|
||||
conditions: ddoConditions,
|
||||
|
@ -33,7 +33,7 @@ export default class ServiceAgreementTemplate extends OceanBase {
|
||||
}
|
||||
|
||||
const receipt = await serviceAgreement.setupAgreementTemplate(
|
||||
methodReflections, dependencyMatrix,
|
||||
this.template.id, methodReflections, dependencyMatrix,
|
||||
Web3Provider.getWeb3().utils.fromAscii(this.template.templateName),
|
||||
templateOwnerAddress)
|
||||
|
||||
|
@ -4,8 +4,4 @@ export default abstract class TemplateBase {
|
||||
public Methods: Method[]
|
||||
public templateName: string
|
||||
public id: string = "0x00000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
constructor(id?: string) {
|
||||
this.id = id
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,31 @@ describe("IdGenerator", () => {
|
||||
assert(id.indexOf("-") === -1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#generatePrefixedId()", () => {
|
||||
|
||||
it("should generate an id", async () => {
|
||||
|
||||
const id = IdGenerator.generatePrefixedId()
|
||||
assert(id)
|
||||
})
|
||||
|
||||
it("should generate an id that is 64 chars long", async () => {
|
||||
|
||||
const id: string = IdGenerator.generatePrefixedId()
|
||||
assert(id.length === 66, id)
|
||||
})
|
||||
|
||||
it("should be prefixed", async () => {
|
||||
|
||||
const id: string = IdGenerator.generatePrefixedId()
|
||||
assert(id.startsWith("0x"))
|
||||
})
|
||||
|
||||
it("should not contain -", async () => {
|
||||
|
||||
const id: string = IdGenerator.generatePrefixedId()
|
||||
assert(id.indexOf("-") === -1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -6,6 +6,7 @@ import IdGenerator from "../../src/ocean/IdGenerator"
|
||||
import Ocean from "../../src/ocean/Ocean"
|
||||
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
|
||||
import Access from "../../src/ocean/ServiceAgreements/Templates/Access"
|
||||
import TemplateBase from "../../src/ocean/ServiceAgreements/Templates/TemplateBase"
|
||||
import config from "../config"
|
||||
|
||||
let ocean: Ocean
|
||||
@ -24,11 +25,14 @@ describe("ServiceAgreementTemplate", () => {
|
||||
it("should setup an Access agreement template correctly", async () => {
|
||||
|
||||
const templateOwner = accounts[0]
|
||||
const access: TemplateBase = new Access()
|
||||
access.id = IdGenerator.generatePrefixedId()
|
||||
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
||||
new ServiceAgreementTemplate(new Access(IdGenerator.generateId()))
|
||||
new ServiceAgreementTemplate(access)
|
||||
assert(serviceAgreementTemplate)
|
||||
|
||||
await serviceAgreementTemplate.register(templateOwner.getId())
|
||||
const registered: boolean = await serviceAgreementTemplate.register(templateOwner.getId())
|
||||
assert(registered)
|
||||
|
||||
assert(serviceAgreementTemplate.getId())
|
||||
assert((await serviceAgreementTemplate.getOwner()).getId() === templateOwner.getId())
|
||||
@ -39,11 +43,14 @@ describe("ServiceAgreementTemplate", () => {
|
||||
it("should get the status of a newly deployed agreement template", async () => {
|
||||
|
||||
const publisherAccount = accounts[0]
|
||||
const access: TemplateBase = new Access()
|
||||
access.id = IdGenerator.generatePrefixedId()
|
||||
const serviceAgreementTemplate: ServiceAgreementTemplate =
|
||||
new ServiceAgreementTemplate(new Access(IdGenerator.generateId()))
|
||||
new ServiceAgreementTemplate(access)
|
||||
assert(serviceAgreementTemplate)
|
||||
|
||||
await serviceAgreementTemplate.register(publisherAccount.getId())
|
||||
const registered: boolean = await serviceAgreementTemplate.register(publisherAccount.getId())
|
||||
assert(registered)
|
||||
|
||||
const templateStatus = await serviceAgreementTemplate.getStatus()
|
||||
assert(templateStatus === true)
|
||||
|
Loading…
Reference in New Issue
Block a user