From 5694ae29b581b22d5c8844a990a411c0a9cabf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Wed, 30 Jan 2019 15:35:31 +0100 Subject: [PATCH] changed some methods --- package-lock.json | 6 ++++ .../contracts/ServiceExecutionAgreement.ts | 11 ++----- .../contracts/conditions/AccessConditions.ts | 4 +-- src/ocean/OceanAssets.ts | 4 +-- .../ServiceAgreements/ServiceAgreement.ts | 32 +++++++------------ .../ServiceAgreements/Templates/Access.ts | 4 --- test/ocean/ServiceAgreement.test.ts | 31 ++---------------- 7 files changed, 28 insertions(+), 64 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8dfe9fb..df39855 100644 --- a/package-lock.json +++ b/package-lock.json @@ -130,6 +130,12 @@ "integrity": "sha512-Yo2/9MJC1vlWXGIaU+35naYHWWYGbtzTu2t5dW4Ro1JuIRkzxfM3TSNzPUAgsCrUBUxsCsu9pd/RjvPuE45SGw==", "requires": { "node-fetch": "^2.3.0" + }, + "dependencies": { + "node-fetch": { + "version": "2.3.0", + "bundled": true + } } }, "@types/chai": { diff --git a/src/keeper/contracts/ServiceExecutionAgreement.ts b/src/keeper/contracts/ServiceExecutionAgreement.ts index 57d8bdd..602b5ca 100644 --- a/src/keeper/contracts/ServiceExecutionAgreement.ts +++ b/src/keeper/contracts/ServiceExecutionAgreement.ts @@ -39,12 +39,7 @@ export default class ServiceExecutionAgreement extends ContractBase { return this.call("getTemplateOwner", [templateId]) } - public async getAgreementStatus(serviceDefinitionId: string) { - - return this.call("getAgreementStatus", [serviceDefinitionId]) - } - - public async executeAgreement( + public async initializeAgreement( serviceAgreementTemplateId: string, serviceAgreementSignatureHash: string, consumerAddress: string, @@ -54,8 +49,8 @@ export default class ServiceExecutionAgreement extends ContractBase { did: DID, publisherAddress: string, ): Promise { -console.log({serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes, timeoutValues, serviceAgreementId, did, publisherAddress}) - return this.send("executeAgreement", publisherAddress, [ + + return this.send("initializeAgreement", publisherAddress, [ serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes, timeoutValues, "0x" + serviceAgreementId, "0x" + did.getId(), ]) diff --git a/src/keeper/contracts/conditions/AccessConditions.ts b/src/keeper/contracts/conditions/AccessConditions.ts index 9eacfea..56da001 100644 --- a/src/keeper/contracts/conditions/AccessConditions.ts +++ b/src/keeper/contracts/conditions/AccessConditions.ts @@ -11,10 +11,10 @@ export default class AccessConditions extends ContractBase { // todo add check permissions proxy - public async grantAccess(serviceAgreementId: any, assetId: any, documentKeyId: any, publisherAddress: string) + public async grantAccess(serviceAgreementId: any, documentKeyId: any, publisherAddress: string) : Promise { return this.send("grantAccess", publisherAddress, [ - serviceAgreementId, "0x" + assetId, "0x" + documentKeyId, + serviceAgreementId, "0x" + documentKeyId, ]) } } diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 906e445..4b38632 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -108,11 +108,11 @@ export default class OceanAssets { // the id of the service agreement template templateId: serviceAgreementTemplate.getId(), serviceAgreementContract: { - contractName: "ServiceAgreement", + contractName: "ServiceExecutionAgreement", fulfillmentOperator: template.fulfillmentOperator, events: [ { - name: "ExecuteAgreement", + name: "AgreementInitialized", actorType: "consumer", handler: { moduleName: "payment", diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index c4ceed1..a302bd0 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -62,11 +62,13 @@ export default class ServiceAgreement extends OceanBase { return serviceAgreement } - private static async createSAHashSignature(service: Service, - serviceAgreementId: string, - valueHashes: string[], - timeoutValues: number[], - consumer: Account): Promise { + private static async createSAHashSignature( + service: Service, + serviceAgreementId: string, + valueHashes: string[], + timeoutValues: number[], + consumer: Account, + ): Promise { if (!service.templateId) { throw new Error("TemplateId not found in ddo.") @@ -113,23 +115,20 @@ export default class ServiceAgreement extends OceanBase { const {serviceAgreement} = await Keeper.getInstance() - console.log(1) const service: Service = ddo.findServiceById(serviceDefinitionId) if (!service.templateId) { throw new Error(`TemplateId not found in service "${service.type}" ddo.`) } - console.log(2) const templateActive = await serviceAgreement.getTemplateStatus(service.templateId) if (!templateActive) { throw new Error(`Template with id ${service.templateId} is not active.`) } - console.log(3) const executeAgreementReceipt = await serviceAgreement - .executeAgreement( + .initializeAgreement( service.templateId, serviceAgreementHashSignature, consumerAddress, @@ -140,13 +139,11 @@ export default class ServiceAgreement extends OceanBase { publisher.getId(), ) - console.log(4) - if (executeAgreementReceipt.events.ExecuteAgreement.returnValues.state === false) { + if (!executeAgreementReceipt.status) { throw new Error("executing service agreement failed.") } - return new ServiceAgreement( - executeAgreementReceipt.events.ExecuteAgreement.returnValues.serviceAgreementId, + executeAgreementReceipt.events.AgreementInitialized.returnValues.agreementId, ) } @@ -237,17 +234,12 @@ export default class ServiceAgreement extends OceanBase { return lockPaymentReceipt.status } - public async grantAccess(assetId: string, documentId: string, publisher: Account): Promise { + public async grantAccess(documentId: string, publisher: Account): Promise { const {accessConditions} = await Keeper.getInstance() const grantAccessReceipt = - await accessConditions.grantAccess(this.getId(), assetId, documentId, publisher.getId()) + await accessConditions.grantAccess(this.getId(), documentId, publisher.getId()) return !!grantAccessReceipt.events.AccessGranted } - - public async getStatus() { - const {serviceAgreement} = await Keeper.getInstance() - return serviceAgreement.getAgreementStatus(this.getId()) - } } diff --git a/src/ocean/ServiceAgreements/Templates/Access.ts b/src/ocean/ServiceAgreements/Templates/Access.ts index b96b9bb..5878722 100644 --- a/src/ocean/ServiceAgreements/Templates/Access.ts +++ b/src/ocean/ServiceAgreements/Templates/Access.ts @@ -43,10 +43,6 @@ export default class Access extends TemplateBase { methodName: "grantAccess", timeout: 0, parameters: [ - { - name: "assetId", - type: "bytes32", - } as Parameter, { name: "documentKeyId", type: "bytes32", diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index 3cec4eb..5e86148 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -76,7 +76,7 @@ describe("ServiceAgreement", () => { }) describe("#executeServiceAgreement()", () => { - it("should execute an service agreement", async () => { + it("should execute a service agreement", async () => { const ddo = new DDO({id: did.getDid(), service: [accessService]}) const serviceAgreementId: string = IdGenerator.generateId() @@ -113,29 +113,6 @@ describe("ServiceAgreement", () => { }) }) - describe("#getStatus()", () => { - it("should get the status of a newly created service agreement", async () => { - - const ddo = new DDO({id: did.getDid(), service: [accessService]}) - const serviceAgreementId: string = IdGenerator.generateId() - - // @ts-ignore - WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) - const serviceAgreementSignature: string = - await ServiceAgreement.signServiceAgreement(ddo, accessService.serviceDefinitionId, - serviceAgreementId, consumerAccount) - assert(serviceAgreementSignature) - - const serviceAgreement: ServiceAgreement = - await ServiceAgreement.executeServiceAgreement(did, ddo, accessService.serviceDefinitionId, - serviceAgreementId, serviceAgreementSignature, consumerAccount, publisherAccount) - assert(serviceAgreement) - - const status = await serviceAgreement.getStatus() - assert(status === false) - }) - }) - describe("#payAsset()", () => { it("should lock the payment in that service agreement", async () => { @@ -190,8 +167,7 @@ describe("ServiceAgreement", () => { assert(paid) // todo: use document id - const accessGranted: boolean = await serviceAgreement.grantAccess(did.getId(), did.getId(), - publisherAccount) + const accessGranted: boolean = await serviceAgreement.grantAccess(did.getId(), publisherAccount) assert(accessGranted) }) @@ -213,8 +189,7 @@ describe("ServiceAgreement", () => { assert(serviceAgreement) // todo: use document id - const accessGranted: boolean = await serviceAgreement.grantAccess(did.getId(), did.getId(), - publisherAccount) + const accessGranted: boolean = await serviceAgreement.grantAccess(did.getId(), publisherAccount) assert(!accessGranted) }) })