From 2df3a68abf672007b125c3495e5a185c7e2e8fd3 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 9 Nov 2018 11:16:22 +0100 Subject: [PATCH] fix 500 on aquarius, hardened tests, avoided loading contracts more than once per chain and item --- src/brizo/Brizo.ts | 7 +++- src/ddo/DDO.ts | 4 +- src/ocean/Ocean.ts | 37 +++++++++++++++---- .../ServiceAgreementTemplate.ts | 9 ++--- test/keeper/TestContractHandler.ts | 2 +- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index fba6f82..c7ab4fa 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -12,7 +12,12 @@ export default class Brizo { return `${this.url}/api/v1/brizo/services/access/purchase?` } - public getServiceEndpoint(pubKey: string, serviceId: string, url: string) { + public getConsumeEndpoint(pubKey: string, serviceId: string, url: string) { return `${this.url}/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}` } + + public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) { + // tslint:disable-next-line + return `${this.url}/api/v1/brizo/services/compute?pubKey=${pubKey}&serviceId=${serviceId}&algo=${algo}&container=${container}"` + } } diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 4682f28..fa9434d 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -25,13 +25,13 @@ export default class DDO { public constructor(ddo?: { id?: string, - publicKey?: PublicKey[], + publicKey?: any[], authentication?: Authentication[], service?: Service[], }) { + this.authentication = ddo ? ddo.authentication ? ddo.authentication : [] : [] this.id = ddo ? ddo.id ? ddo.id : null : null this.publicKey = ddo ? ddo.publicKey ? ddo.publicKey : [] : [] - this.authentication = ddo ? ddo.authentication ? ddo.authentication : [] : [] this.service = ddo ? ddo.service ? ddo.service : [] : [] } } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index e857842..edc494a 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -95,16 +95,28 @@ export default class Ocean { // create ddo itself const ddo: DDO = new DDO({ - id: did, authentication: [{ - publicKey: publisher.getId(), + type: "RsaSignatureAuthentication2018", + publicKey: did + "#keys-1", } as Authentication], + id: did, + publicKey: [ + { + id: did + "#keys-1", + }, + { + type: "Ed25519VerificationKey2018", + }, + { + owner: did, + }, + { + publicKeyBase58: publisher.getId(), + }, + ], service: [ { type: template.templateName, - // tslint:disable-next-line - serviceEndpoint: this.brizo.getServiceEndpoint(publisher.getId(), - serviceDefinitionId, metadata.base.contentUrls[0]), purchaseEndpoint: this.brizo.getPurchaseEndpoint(), // the id of the service agreement? serviceDefinitionId, @@ -113,14 +125,23 @@ export default class Ocean { conditions: ddoConditions, } as Service, { - serviceEndpoint, + serviceEndpoint: this.brizo.getConsumeEndpoint(publisher.getId(), + serviceDefinitionId, metadata.base.contentUrls[0]), + type: "Consume", + } as Service, + { + serviceEndpoint: this.brizo.getComputeEndpoint(publisher.getId(), + serviceDefinitionId, "xxx", "xxx"), + type: "Consume", + } as Service, + { + type: "Metadata", metadata, + serviceEndpoint, } as Service, ], }) - // Logger.log(JSON.stringify(ddo, null, 2)) - const storedDdo = await this.aquarius.storeDDO(ddo) await didRegistry.registerAttribute(id, ValueType.DID, "Metadata", serviceEndpoint, diff --git a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts index 9db4ad8..14e9f27 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts @@ -95,11 +95,10 @@ export default class ServiceAgreementTemplate extends OceanBase { } private async getMethodReflections(): Promise { - const methodReflections: MethodReflection[] = - await Promise.all(this.template.Methods.map(async (method: Method) => { - const methodReflection = await ContractReflector.reflectContractMethod(method.path) - return methodReflection - })) + const methodReflections: MethodReflection[] = [] + for (const method of this.template.Methods) { + methodReflections.push(await ContractReflector.reflectContractMethod(method.path)) + } return methodReflections } } diff --git a/test/keeper/TestContractHandler.ts b/test/keeper/TestContractHandler.ts index 6743051..3da33e3 100644 --- a/test/keeper/TestContractHandler.ts +++ b/test/keeper/TestContractHandler.ts @@ -78,7 +78,7 @@ export default class TestContractHandler extends ContractHandler { // dont redeploy if there is already something loaded if (ContractHandler.has(name)) { - return ContractHandler.get(name) + return await ContractHandler.get(name) } const web3 = Web3Provider.getWeb3()