From 233aede5f6f51e77263b17e0d716dbf4b9c6df6a Mon Sep 17 00:00:00 2001 From: ssallam Date: Fri, 14 Dec 2018 13:40:08 +0100 Subject: [PATCH] Generate assetId with 0x prefix, update all references to reflect this. This makes it similar to squid-py and fixes an issue in payAsset where the asset id in the condition param had double 0x prefix when paying a service agreement for an asset created in squid-py. --- src/keeper/contracts/conditions/PaymentConditions.ts | 2 +- src/ocean/Ocean.ts | 5 +++-- src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts | 4 ++-- test/aquarius/Aquarius.test.ts | 4 ++-- test/ocean/ServiceAgreement.test.ts | 2 +- test/ocean/ServiceAgreementTemplate.test.ts | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/keeper/contracts/conditions/PaymentConditions.ts b/src/keeper/contracts/conditions/PaymentConditions.ts index 40656cc..7cc045a 100644 --- a/src/keeper/contracts/conditions/PaymentConditions.ts +++ b/src/keeper/contracts/conditions/PaymentConditions.ts @@ -12,7 +12,7 @@ export default class PaymentConditions extends ContractBase { public async lockPayment(serviceAgreementId: string, assetId: string, price: number, consumerAddress: string) : Promise { return this.send("lockPayment", consumerAddress, [ - serviceAgreementId, "0x" + assetId, price, + serviceAgreementId, assetId, price, ]) } } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 23ee5be..b432ac6 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -67,7 +67,7 @@ export default class Ocean { const aquarius = AquariusProvider.getAquarius() const brizo = BrizoProvider.getBrizo() - const assetId: string = IdGenerator.generateId() + const assetId: string = IdGenerator.generatePrefixedId() const did: string = `did:op:${assetId}` const accessServiceDefinitionId: string = "0" const computeServiceDefintionId: string = "1" @@ -183,7 +183,8 @@ export default class Ocean { event.listenOnce(async (data) => { const sa: ServiceAgreement = new ServiceAgreement(data.returnValues.serviceAgreementId) - await sa.payAsset(id, + await sa.payAsset( + id, metadataService.metadata.base.price, consumer, ) diff --git a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts index a78241c..ae6423d 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts @@ -111,9 +111,9 @@ export default class ServiceAgreementTemplate extends OceanBase { case "price": return metadata.base.price case "assetId": - return "0x" + assetId + return assetId case "documentKeyId": - return "0x" + assetId + return assetId } return null diff --git a/test/aquarius/Aquarius.test.ts b/test/aquarius/Aquarius.test.ts index 8b8a031..cb8d8b8 100644 --- a/test/aquarius/Aquarius.test.ts +++ b/test/aquarius/Aquarius.test.ts @@ -85,7 +85,7 @@ describe("Aquarius", () => { it("should store a ddo", async () => { - const did: string = `did:op:${IdGenerator.generateId()}` + const did: string = `did:op:${IdGenerator.generatePrefixedId()}` const ddo: DDO = new DDO({ id: did, }) @@ -103,7 +103,7 @@ describe("Aquarius", () => { it("should store a ddo", async () => { - const did: string = `did:op:${IdGenerator.generateId()}` + const did: string = `did:op:${IdGenerator.generatePrefixedId()}` const ddo: DDO = new DDO({ id: did, }) diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index a3aef06..c68ba7e 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -44,7 +44,7 @@ describe("ServiceAgreement", () => { accessService = { type: "Access", - serviceDefinitionId: IdGenerator.generateId(), + serviceDefinitionId: "0", templateId: serviceAgreementTemplate.getId(), conditions, } as Service diff --git a/test/ocean/ServiceAgreementTemplate.test.ts b/test/ocean/ServiceAgreementTemplate.test.ts index 8ea80f3..f351f50 100644 --- a/test/ocean/ServiceAgreementTemplate.test.ts +++ b/test/ocean/ServiceAgreementTemplate.test.ts @@ -49,7 +49,7 @@ describe("ServiceAgreementTemplate", () => { new ServiceAgreementTemplate(access) assert(serviceAgreementTemplate) - const conds = await serviceAgreementTemplate.getConditions(new MetaData(), IdGenerator.generateId()) + const conds = await serviceAgreementTemplate.getConditions(new MetaData(), IdGenerator.generatePrefixedId()) assert(conds) }) })