From b6af27a523ff04cb8324905e6653a26377494762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Tue, 16 Apr 2019 14:33:42 +0200 Subject: [PATCH] Use only the agreementId on status method of agreements module. --- integration/ocean/ConsumeAsset.test.ts | 16 ++-------------- src/keeper/Keeper.ts | 19 +++++++++++++++++-- src/ocean/OceanAgreements.ts | 15 ++++----------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/integration/ocean/ConsumeAsset.test.ts b/integration/ocean/ConsumeAsset.test.ts index 4491e85..2d1f34e 100644 --- a/integration/ocean/ConsumeAsset.test.ts +++ b/integration/ocean/ConsumeAsset.test.ts @@ -67,13 +67,7 @@ describe("Consume Asset", () => { }) it("should get the agreement conditions status not fulfilled", async () => { - const accessService = ddo.findServiceByType("Access") - - const status = await ocean.agreements.status( - ddo.id, - serviceAgreementSignatureResult.agreementId, - accessService.serviceDefinitionId, - ) + const status = await ocean.agreements.status(serviceAgreementSignatureResult.agreementId) assert.deepEqual(status, { lockReward: ConditionState.Unfulfilled, @@ -107,13 +101,7 @@ describe("Consume Asset", () => { }) it("should get the agreement conditions status fulfilled", async () => { - const accessService = ddo.findServiceByType("Access") - - const status = await ocean.agreements.status( - ddo.id, - serviceAgreementSignatureResult.agreementId, - accessService.serviceDefinitionId, - ) + const status = await ocean.agreements.status(serviceAgreementSignatureResult.agreementId) assert.deepEqual(status, { lockReward: ConditionState.Fulfilled, diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index d7ce6f3..429b115 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -134,19 +134,34 @@ export class Keeper extends Instantiable { /** * Returns a condition by address. - * @param {string} address Address of deployed condition. - * @return {Condition} Condition instance. + * @param {string} address Address of deployed condition. + * @return {Condition} Condition instance. */ public getConditionByAddress(address: string): Condition { return Object.values(this.conditions) .find((condition) => condition.getAddress() === address) } + /** + * Returns a template by name. + * @param {string} name Template name. + * @return {AgreementTemplate} Agreement template instance. + */ public getTemplateByName(name: string): AgreementTemplate { return Object.values(this.templates) .find((template) => template.contractName === name) } + /** + * Returns a template by address. + * @param {string} address Template address. + * @return {AgreementTemplate} Agreement template instance. + */ + public getTemplateByAddress(address: string): AgreementTemplate { + return Object.values(this.templates) + .find((template) => template.getAddress() === address) + } + /** * Returns network id. * @return {Promise} Network ID. diff --git a/src/ocean/OceanAgreements.ts b/src/ocean/OceanAgreements.ts index a6062cb..54c1a39 100644 --- a/src/ocean/OceanAgreements.ts +++ b/src/ocean/OceanAgreements.ts @@ -137,22 +137,15 @@ export class OceanAgreements extends Instantiable { * @param {boolean} extended Returns a complete status with dependencies. * @return {Promise} */ - // tslint:disable-next-line - public async status(did: string, agreementId: string, serviceDefinitionId: string, extended?: false): Promise<{[condition: string]: ConditionState}> - // tslint:disable-next-line - public async status(did: string, agreementId: string, serviceDefinitionId: string, extended: true): Promise + public async status(agreementId: string, extended?: false): Promise<{[condition: string]: ConditionState}> + public async status(agreementId: string, extended: true): Promise public async status( - did: string, agreementId: string, - serviceDefinitionId: string, extended: boolean = false, ) { - const d: DID = DID.parse(did) - const ddo = await this.ocean.aquarius.retrieveDDO(d) - - const templateName = ddo.findServiceById<"Access">(serviceDefinitionId).serviceAgreementTemplate.contractName + const {templateId} = await this.ocean.keeper.agreementStoreManager.getAgreement(agreementId) const fullStatus = await this.ocean.keeper - .getTemplateByName(templateName) + .getTemplateByAddress(templateId) .getAgreementStatus(agreementId) if (!fullStatus) {