From eaac2f4f68bcf1970e635f382e365143bfb143e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Thu, 14 Mar 2019 21:28:51 +0100 Subject: [PATCH] Fix linter errors. --- integration/ocean/ConsumeAsset.test.ts | 6 +- integration/ocean/ConsumeAssetBrizo.test.ts | 19 +- ...terEscrowAccessSecretStoreTemplate.test.ts | 21 +- integration/ocean/SearchAsset.test.ts | 10 +- integration/ocean/Signature.test.ts | 7 +- package.json | 4 +- src/ddo/ServiceAgreementTemplate.ts | 2 +- src/keeper/Keeper.ts | 4 +- src/keeper/contracts/ContractBase.ts | 4 +- .../conditions/AccessSecretStoreCondition.ts | 6 +- .../conditions/Condition.abstract.ts | 19 +- .../contracts/conditions/EscrowReward.ts | 4 +- .../conditions/LockRewardCondition.ts | 4 +- src/keeper/contracts/conditions/index.ts | 8 +- .../managers/AgreementStoreManager.ts | 2 +- .../managers/ConditionStoreManager.ts | 2 +- .../managers/TemplateStoreManager.ts | 2 +- src/keeper/contracts/managers/index.ts | 6 +- .../templates/AgreementTemplate.abstract.ts | 38 ++-- ...tStoreTemplate.serviceAgreementTemplate.ts | 214 +++++++++--------- .../EscrowAccessSecretStoreTemplate.ts | 9 +- src/keeper/contracts/templates/index.ts | 4 +- src/ocean/OceanAgreementsConditions.ts | 1 - src/ocean/OceanAssets.ts | 10 +- .../ServiceAgreements/ServiceAgreement.ts | 3 +- src/utils/ConversionTypeHelpers.ts | 10 +- src/utils/DDOHelpers.ts | 10 +- src/utils/Logger.ts | 2 +- src/utils/SignatureHelpers.ts | 2 +- src/utils/index.ts | 10 +- test/keeper/TestContractHandler.ts | 1 - test/ocean/ServiceAgreement.test.ts | 1 - test/utils/ConversionTypeHelpers.test.ts | 2 +- tslint.json | 3 +- 34 files changed, 222 insertions(+), 228 deletions(-) diff --git a/integration/ocean/ConsumeAsset.test.ts b/integration/ocean/ConsumeAsset.test.ts index c5a0d78..589c429 100644 --- a/integration/ocean/ConsumeAsset.test.ts +++ b/integration/ocean/ConsumeAsset.test.ts @@ -1,8 +1,8 @@ -import { assert } from 'chai' +import { assert } from "chai" import { config } from "../config" -import { Ocean, MetaData, DDO, DID, Account/*, ServiceAgreement*/ } from '../../src' // @oceanprotocol/squid +import { Ocean, MetaData, DDO, DID, Account/*, ServiceAgreement*/ } from "../../src" // @oceanprotocol/squid describe("Consume Asset", () => { let ocean: Ocean @@ -71,7 +71,7 @@ describe("Consume Asset", () => { }) it("should be able to request tokens for consumer", async () => { - const initialBalance = (await consumer.getBalance()).ocn; + const initialBalance = (await consumer.getBalance()).ocn await consumer.requestTokens(metadata.base.price) assert.equal((await consumer.getBalance()).ocn, initialBalance + metadata.base.price, "OCN Tokens not delivered") diff --git a/integration/ocean/ConsumeAssetBrizo.test.ts b/integration/ocean/ConsumeAssetBrizo.test.ts index d78f471..4e186de 100644 --- a/integration/ocean/ConsumeAssetBrizo.test.ts +++ b/integration/ocean/ConsumeAssetBrizo.test.ts @@ -1,6 +1,6 @@ import { assert } from "chai" -import * as Web3 from "web3"; -import * as fs from "fs"; +import * as Web3 from "web3" +import * as fs from "fs" import { config } from "../config" @@ -17,7 +17,7 @@ describe("Consume Asset (Brizo)", () => { const testHash = Math.random().toString(36).substr(2) let metadata: Partial - let metadataGenerator = (name: string) => ({ + const metadataGenerator = (name: string) => ({ ...metadata, base: { ...metadata.base, @@ -28,7 +28,8 @@ describe("Consume Asset (Brizo)", () => { before(async () => { ocean = await Ocean.getInstance({ ...config, - web3Provider: new Web3.providers.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), + web3Provider: new Web3.providers + .HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), }) // Accounts @@ -76,7 +77,7 @@ describe("Consume Asset (Brizo)", () => { }) it("should regiester an asset", async () => { - ddo = await ocean.assets.create(metadataGenerator("ToBeConsumed") as any, publisher); + ddo = await ocean.assets.create(metadataGenerator("ToBeConsumed") as any, publisher) assert.instanceOf(ddo, DDO) }) @@ -99,10 +100,10 @@ describe("Consume Asset (Brizo)", () => { assert.include(path, folder, "The storage path is not correct.") - const files = await new Promise(resolve => { - fs.readdir(path, (err, files) => { - resolve(files) - }); + const files = await new Promise((resolve) => { + fs.readdir(path, (err, fileList) => { + resolve(fileList) + }) }) assert.deepEqual(files, ["README.md", "testzkp.pdf"], "Stored files are not correct.") diff --git a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts index 177b233..5b26c7e 100644 --- a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts +++ b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts @@ -1,8 +1,8 @@ -import { assert } from 'chai' +import { assert } from "chai" import { config } from "../config" -import { Ocean, templates, conditions, utils, Keeper, Account } from '../../src' // @oceanprotocol/squid +import { Ocean, templates, conditions, utils, Keeper, Account } from "../../src" // @oceanprotocol/squid const { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } = conditions const { EscrowAccessSecretStoreTemplate } = templates @@ -13,7 +13,7 @@ describe("Register Escrow Access Secret Store Template", () => { let template: templates.EscrowAccessSecretStoreTemplate - const url = 'https://example.com/did/ocean/test-attr-example.txt' + const url = "https://example.com/did/ocean/test-attr-example.txt" const checksum = "b".repeat(32) const escrowAmount = 12 @@ -46,13 +46,13 @@ describe("Register Escrow Access Secret Store Template", () => { it("should propose the template", async () => { await keeper.templateStoreManager.proposeTemplate(template.getAddress(), consumer.getId(), true) // TODO: Use a event to detect template mined - await new Promise(_ => setTimeout(_, 6 * 1000)) + await new Promise((_) => setTimeout(_, 6 * 1000)) }) it("should approve the template", async () => { await keeper.templateStoreManager.approveTemplate(template.getAddress(), templateManagerOwner.getId(), true) // TODO: Use a event to detect template mined - await new Promise(_ => setTimeout(_, 6 * 1000)) + await new Promise((_) => setTimeout(_, 6 * 1000)) }) }) @@ -93,16 +93,15 @@ describe("Register Escrow Access Secret Store Template", () => { }) it("should have condition instances asociated", async () => { - const conditions = await template.getConditions() - - assert.equal(conditions.length, 3, "Expected 3 conditions.") + const conditionInstances = await template.getConditions() + assert.equal(conditionInstances.length, 3, "Expected 3 conditions.") const conditionClasses = [AccessSecretStoreCondition, EscrowReward, LockRewardCondition] conditionClasses - .forEach(conditionClass => { - if (!conditions.find(condition => condition instanceof conditionClass)) { - throw `${conditionClass.name} is not part of the conditions.`; + .forEach((conditionClass) => { + if (!conditionInstances.find((condition) => condition instanceof conditionClass)) { + throw new Error(`${conditionClass.name} is not part of the conditions.`) } }) }) diff --git a/integration/ocean/SearchAsset.test.ts b/integration/ocean/SearchAsset.test.ts index 1f21eee..7cffa89 100644 --- a/integration/ocean/SearchAsset.test.ts +++ b/integration/ocean/SearchAsset.test.ts @@ -1,8 +1,8 @@ -import { assert } from 'chai' +import { assert } from "chai" import { config } from "../config" -import { Ocean, MetaData, Account, DDO } from '../../src' // @oceanprotocol/squid +import { Ocean, MetaData, Account, DDO } from "../../src" // @oceanprotocol/squid describe("Search Asset", () => { let ocean: Ocean @@ -11,7 +11,7 @@ describe("Search Asset", () => { const testHash = Math.random().toString(36).substr(2) let metadata: Partial - let metadataGenerator = (name: string) => ({ + const metadataGenerator = (name: string) => ({ ...metadata, base: { ...metadata.base, @@ -95,7 +95,7 @@ describe("Search Asset", () => { const ddos: DDO[] = await ocean.assets.search(`Test1${testHash}`) assert.equal(ddos.length - test1length, 1, "Something was wrong searching the assets") - ddos.map(ddo => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO")) + ddos.map((ddo) => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO")) }) it("should be able to do a query to get a list of DDOs", async () => { @@ -112,6 +112,6 @@ describe("Search Asset", () => { }) assert.equal(ddos.length, 1, "Something was wrong searching the assets") - ddos.map(ddo => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO")) + ddos.map((ddo) => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO")) }) }) diff --git a/integration/ocean/Signature.test.ts b/integration/ocean/Signature.test.ts index 89229fc..6f787e3 100644 --- a/integration/ocean/Signature.test.ts +++ b/integration/ocean/Signature.test.ts @@ -16,7 +16,8 @@ describe("Signature", () => { before(async () => { await Ocean.getInstance({ ...config, - web3Provider: new (Web3 as any).providers.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), + web3Provider: new (Web3 as any).providers + .HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"), }) // Accounts @@ -69,8 +70,8 @@ describe("Signature", () => { metadata: { base: { price: 10, - } - } + }, + }, } as any, ], }) diff --git a/package.json b/package.json index 39b753c..ce01810 100644 --- a/package.json +++ b/package.json @@ -15,13 +15,13 @@ "integration:cover": "nyc --report-dir coverage/integration mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts", "examples": "./src/examples/fire_lazers.sh", "clean": "rm -rf ./dist/ ./doc/ ./coverage ./.nyc_output", - "lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts' 'integration/**/*.ts'", "start": "npm link @oceanprotocol/keeper-contracts @oceanprotocol/secret-store-client && npm run build:watch", "build": "npm run clean && npm run build:tsc && npm run build:dist", "build:tsc": "tsc --sourceMap", "build:dist": "cross-env NODE_ENV=production webpack", "build:watch": "tsc -w", - "doc": "typedoc --mode modules --out ./doc/ ./src/", + "doc": "typedoc --mode modules --exclude \"**/examples/**\" --out ./doc/ ./src/", "report-coverage": "cat ./coverage/unit/lcov.info | codacy-coverage --token 71ef0d15f6f04ac29b31d704b28f866a", "run": "ts-node", "release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive", diff --git a/src/ddo/ServiceAgreementTemplate.ts b/src/ddo/ServiceAgreementTemplate.ts index 2985066..44fe7e0 100644 --- a/src/ddo/ServiceAgreementTemplate.ts +++ b/src/ddo/ServiceAgreementTemplate.ts @@ -10,7 +10,7 @@ export interface ServiceAgreementTemplateEvent { handler: { moduleName: string functionName: string - version: string + version: string, } } diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index 40de5f5..d1d33a8 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -101,12 +101,12 @@ export class Keeper { */ public getConditionByAddress(address: string): Condition { return Object.values(this.conditions) - .find(condition => condition.getAddress() === address) + .find((condition) => condition.getAddress() === address) } public getTemplateByName(name: string): AgreementTemplate { return Object.values(this.templates) - .find(template => template.contractName === name) + .find((template) => template.contractName === name) } /** diff --git a/src/keeper/contracts/ContractBase.ts b/src/keeper/contracts/ContractBase.ts index 9abea11..69a2df3 100644 --- a/src/keeper/contracts/ContractBase.ts +++ b/src/keeper/contracts/ContractBase.ts @@ -7,9 +7,9 @@ import Web3Provider from "../Web3Provider" export default abstract class ContractBase { protected static instance = null + public contractName: string private contract: Contract = null - contractName: string constructor(contractName) { this.contractName = contractName @@ -101,7 +101,7 @@ export default abstract class ContractBase { private searchMethod(methodName: string, args: any[] = []) { const methods = this.contract.options.jsonInterface - .map(method => ({...method, signature: (method as any).signature})) + .map((method) => ({...method, signature: (method as any).signature})) .filter((method: any) => method.name === methodName) const foundMethod = methods.find(({inputs}) => inputs.length === args.length) || methods[0] if (!foundMethod) { diff --git a/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts b/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts index 06e7da8..9f67d5c 100644 --- a/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts +++ b/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts @@ -7,15 +7,15 @@ export class AccessSecretStoreCondition extends Condition { return Condition.getInstance("AccessSecretStoreCondition", AccessSecretStoreCondition) } - hashValues(did: string, grantee: string) { + public hashValues(did: string, grantee: string) { return super.hashValues(zeroX(did), zeroX(grantee)) } - fulfill(agreementId: string, did: string, grantee: string, from?: string) { + public fulfill(agreementId: string, did: string, grantee: string, from?: string) { return super.fulfill(agreementId, [didZeroX(did), grantee].map(zeroX), from) } - checkPermissions(grantee: string, did: string, from?: string) { + public checkPermissions(grantee: string, did: string, from?: string) { return this.call("checkPermissions", [grantee, didZeroX(did)].map(zeroX), from) } } diff --git a/src/keeper/contracts/conditions/Condition.abstract.ts b/src/keeper/contracts/conditions/Condition.abstract.ts index 595e909..d5bcff8 100644 --- a/src/keeper/contracts/conditions/Condition.abstract.ts +++ b/src/keeper/contracts/conditions/Condition.abstract.ts @@ -14,35 +14,34 @@ export const conditionStateNames = ["Uninitialized", "Unfulfilled", "Fulfilled", export abstract class Condition extends ContractBase { - protected constructor(contractName: string) { - super(contractName) - } - public static async getInstance(conditionName: string, conditionsClass: any): Promise { const condition: Condition = new (conditionsClass as any)(conditionName) await condition.init() return condition } + protected constructor(contractName: string) { + super(contractName) + } - hashValues(...args: any[]): Promise { + public hashValues(...args: any[]): Promise { return this.call("hashValues", args) } - fulfill(agreementId: string, ...args: any[]) - fulfill(agreementId: string, args: any[], from?: string) { + public fulfill(agreementId: string, ...args: any[]) + public fulfill(agreementId: string, args: any[], from?: string) { return this.sendFrom("fulfill", [zeroX(agreementId), ...args], from) } - async generateIdHash(agreementId: string, ...values: any[]) { + public async generateIdHash(agreementId: string, ...values: any[]) { return this.generateId(agreementId, await this.hashValues(...values)) } - generateId(agreementId: string, valueHash: string) { + public generateId(agreementId: string, valueHash: string) { return this.call("generateId", [zeroX(agreementId), valueHash]) } - abortByTimeOut(agreementId: string, from?: string) { + public abortByTimeOut(agreementId: string, from?: string) { return this.sendFrom("abortByTimeOut", [zeroX(agreementId)], from) } diff --git a/src/keeper/contracts/conditions/EscrowReward.ts b/src/keeper/contracts/conditions/EscrowReward.ts index 50ab4aa..6b8f7bc 100644 --- a/src/keeper/contracts/conditions/EscrowReward.ts +++ b/src/keeper/contracts/conditions/EscrowReward.ts @@ -7,11 +7,11 @@ export class EscrowReward extends Condition { return Condition.getInstance("EscrowReward", EscrowReward) } - hashValues(amount: number, receiver: string, sender: string, lockCondition: string, releaseCondition: string) { + public hashValues(amount: number, receiver: string, sender: string, lockCondition: string, releaseCondition: string) { return super.hashValues(amount, ...[receiver, sender, lockCondition, releaseCondition].map(zeroX)) } - fulfill( + public fulfill( agreementId: string, amount: number, receiver: string, diff --git a/src/keeper/contracts/conditions/LockRewardCondition.ts b/src/keeper/contracts/conditions/LockRewardCondition.ts index 3e99509..0b608df 100644 --- a/src/keeper/contracts/conditions/LockRewardCondition.ts +++ b/src/keeper/contracts/conditions/LockRewardCondition.ts @@ -7,11 +7,11 @@ export class LockRewardCondition extends Condition { return Condition.getInstance("LockRewardCondition", LockRewardCondition) } - hashValues(rewardAddress: string, amount: number) { + public hashValues(rewardAddress: string, amount: number) { return super.hashValues(zeroX(rewardAddress), amount) } - fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) { + public fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) { return super.fulfill(agreementId, [zeroX(rewardAddress), amount], from) } } diff --git a/src/keeper/contracts/conditions/index.ts b/src/keeper/contracts/conditions/index.ts index aac7d24..d74ffa8 100644 --- a/src/keeper/contracts/conditions/index.ts +++ b/src/keeper/contracts/conditions/index.ts @@ -1,4 +1,4 @@ -export * from './Condition.abstract' -export { AccessSecretStoreCondition } from './AccessSecretStoreCondition' -export { EscrowReward } from './EscrowReward' -export { LockRewardCondition } from './LockRewardCondition' +export * from "./Condition.abstract" +export { AccessSecretStoreCondition } from "./AccessSecretStoreCondition" +export { EscrowReward } from "./EscrowReward" +export { LockRewardCondition } from "./LockRewardCondition" diff --git a/src/keeper/contracts/managers/AgreementStoreManager.ts b/src/keeper/contracts/managers/AgreementStoreManager.ts index 7390f3b..742a34f 100644 --- a/src/keeper/contracts/managers/AgreementStoreManager.ts +++ b/src/keeper/contracts/managers/AgreementStoreManager.ts @@ -19,7 +19,7 @@ export class AgreementStoreManager extends ContractBase { return templateStoreManeger } - getOwner(): Promise { + public getOwner(): Promise { return this.call("owner", []) } diff --git a/src/keeper/contracts/managers/ConditionStoreManager.ts b/src/keeper/contracts/managers/ConditionStoreManager.ts index ba31430..a9ae324 100644 --- a/src/keeper/contracts/managers/ConditionStoreManager.ts +++ b/src/keeper/contracts/managers/ConditionStoreManager.ts @@ -21,7 +21,7 @@ export class ConditionStoreManager extends ContractBase { return templateStoreManeger } - getOwner(): Promise { + public getOwner(): Promise { return this.call("owner", []) } diff --git a/src/keeper/contracts/managers/TemplateStoreManager.ts b/src/keeper/contracts/managers/TemplateStoreManager.ts index 74510f4..4f2fb4a 100644 --- a/src/keeper/contracts/managers/TemplateStoreManager.ts +++ b/src/keeper/contracts/managers/TemplateStoreManager.ts @@ -24,7 +24,7 @@ export class TemplateStoreManager extends ContractBase { return templateStoreManeger } - getOwner(): Promise { + public getOwner(): Promise { return this.call("owner", []) } diff --git a/src/keeper/contracts/managers/index.ts b/src/keeper/contracts/managers/index.ts index f5c247d..85903dd 100644 --- a/src/keeper/contracts/managers/index.ts +++ b/src/keeper/contracts/managers/index.ts @@ -1,3 +1,3 @@ -export * from './AgreementStoreManager' -export * from './ConditionStoreManager' -export * from './TemplateStoreManager' +export * from "./AgreementStoreManager" +export * from "./ConditionStoreManager" +export * from "./TemplateStoreManager" diff --git a/src/keeper/contracts/templates/AgreementTemplate.abstract.ts b/src/keeper/contracts/templates/AgreementTemplate.abstract.ts index de9e092..9e1055a 100644 --- a/src/keeper/contracts/templates/AgreementTemplate.abstract.ts +++ b/src/keeper/contracts/templates/AgreementTemplate.abstract.ts @@ -2,24 +2,24 @@ import ContractBase from "../ContractBase" import { AgreementStoreManager, ConditionStoreManager } from "../managers" import { Condition, ConditionState, conditionStateNames } from "../conditions/Condition.abstract" import Keeper from "../../Keeper" -import { DDO } from '../../../ddo/DDO' -import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate' +import { DDO } from "../../../ddo/DDO" +import { ServiceAgreementTemplate } from "../../../ddo/ServiceAgreementTemplate" import { zeroX, Logger } from "../../../utils" import EventListener from "../../../keeper/EventListener" import Event from "../../../keeper/Event" export abstract class AgreementTemplate extends ContractBase { - protected constructor(contractName: string) { - super(contractName) - } - public static async getInstance(conditionName: string, templateClass: any): Promise { const condition: AgreementTemplate = new (templateClass as any)(conditionName) await condition.init() return condition } + protected constructor(contractName: string) { + super(contractName) + } + // tslint:disable-next-line public createAgreement(agreementId: string, did: string, conditionIds: string[], timeLocks: number[], timeOuts: number[], ...args: any[]) public createAgreement( @@ -60,7 +60,7 @@ export abstract class AgreementTemplate extends ContractBase { public async getConditions(): Promise { const keeper = await Keeper.getInstance() return (await this.getConditionTypes()) - .map(address => keeper.getConditionByAddress(address)) + .map((address) => keeper.getConditionByAddress(address)) } /** @@ -70,7 +70,7 @@ export abstract class AgreementTemplate extends ContractBase { * @param {string} from Consumer address. * @return {Promise} Condition IDs. */ - abstract getAgreementIdsFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise + public abstract getAgreementIdsFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise /** * Create a new agreement using the data of a DDO. @@ -79,9 +79,9 @@ export abstract class AgreementTemplate extends ContractBase { * @param {string} from Creator address. * @return {Promise} Success. */ - abstract createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise + public abstract createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise - abstract async getServiceAgreementTemplate(): Promise + public abstract async getServiceAgreementTemplate(): Promise public async getServiceAgreementTemplateConditions() { const serviceAgreementTemplate = await this.getServiceAgreementTemplate() @@ -93,7 +93,7 @@ export abstract class AgreementTemplate extends ContractBase { .find(({name: conditionRef}) => conditionRef === ref) .contractName return (await this.getConditions()) - .find(condition => condition.contractName === name) + .find((condition) => condition.contractName === name) } public async getServiceAgreementTemplateDependencies() { @@ -107,15 +107,15 @@ export abstract class AgreementTemplate extends ContractBase { * @return {Promise} Conditions status. */ public async getAgreementStatus( - agreementId: string + agreementId: string, ): Promise<{ [condition: string]: { condition: string, contractName: string, state: ConditionState, blocked: boolean, - blockedBy: string[] - } + blockedBy: string[], + }, } | false> { const agreementStore = await AgreementStoreManager.getInstance() const conditionStore = await ConditionStoreManager.getInstance() @@ -137,7 +137,7 @@ export abstract class AgreementTemplate extends ContractBase { return { ref, contractName, - state: (await conditionStore.getCondition(conditionIdByConddition[contractName])).state + state: (await conditionStore.getCondition(conditionIdByConddition[contractName])).state, } }) const states = await Promise.all(statesPromises) @@ -145,8 +145,8 @@ export abstract class AgreementTemplate extends ContractBase { return states .reduce((acc, {contractName, ref, state}) => { const blockers = dependencies[ref] - .map(dependency => states.find(({ref}) => ref === dependency)) - .filter(condition => condition.state !== ConditionState.Fulfilled) + .map((dependency) => states.find((_) => _.ref === dependency)) + .filter((condition) => condition.state !== ConditionState.Fulfilled) return { ...acc, [ref]: { @@ -154,8 +154,8 @@ export abstract class AgreementTemplate extends ContractBase { contractName, state, blocked: !!blockers.length, - blockedBy: blockers.map(_ => _.ref), - } + blockedBy: blockers.map((_) => _.ref), + }, } }, {}) } diff --git a/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts index 5615b40..533d2a6 100644 --- a/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts +++ b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.serviceAgreementTemplate.ts @@ -1,145 +1,145 @@ -import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate' +import { ServiceAgreementTemplate } from "../../../ddo/ServiceAgreementTemplate" export const escrowAccessSecretStoreTemplateServiceAgreementTemplate: ServiceAgreementTemplate = { - "contractName": "EscrowAccessSecretStoreTemplate", - "events": [ + contractName: "EscrowAccessSecretStoreTemplate", + events: [ { - "name": "AgreementCreated", - "actorType": "consumer", - "handler": { - "moduleName": "escrowAccessSecretStoreTemplate", - "functionName": "fulfillLockRewardCondition", - "version": "0.1" - } - } + name: "AgreementCreated", + actorType: "consumer", + handler: { + moduleName: "escrowAccessSecretStoreTemplate", + functionName: "fulfillLockRewardCondition", + version: "0.1", + }, + }, ], - "fulfillmentOrder": [ + fulfillmentOrder: [ "lockReward.fulfill", "accessSecretStore.fulfill", - "escrowReward.fulfill" + "escrowReward.fulfill", ], - "conditionDependency": { - "lockReward": [], - "accessSecretStore": [], - "escrowReward": [ + conditionDependency: { + lockReward: [], + accessSecretStore: [], + escrowReward: [ "lockReward", - "accessSecretStore" - ] + "accessSecretStore", + ], }, - "conditions": [ + conditions: [ { - "name": "lockReward", - "timelock": 0, - "timeout": 0, - "contractName": "LockRewardCondition", - "functionName": "fulfill", - "parameters": [ + name: "lockReward", + timelock: 0, + timeout: 0, + contractName: "LockRewardCondition", + functionName: "fulfill", + parameters: [ { - "name": "_rewardAddress", - "type": "address", - "value": "" + name: "_rewardAddress", + type: "address", + value: "", }, { - "name": "_amount", - "type": "uint256", - "value": "" - } + name: "_amount", + type: "uint256", + value: "", + }, ], - "events": [ + events: [ { - "name": "Fulfilled", - "actorType": "publisher", - "handler": { - "moduleName": "lockRewardCondition", - "functionName": "fulfillAccessSecretStoreCondition", - "version": "0.1" - } - } - ] + name: "Fulfilled", + actorType: "publisher", + handler: { + moduleName: "lockRewardCondition", + functionName: "fulfillAccessSecretStoreCondition", + version: "0.1", + }, + }, + ], }, { - "name": "accessSecretStore", - "timelock": 0, - "timeout": 0, - "contractName": "AccessSecretStoreCondition", - "functionName": "fulfill", - "parameters": [ + name: "accessSecretStore", + timelock: 0, + timeout: 0, + contractName: "AccessSecretStoreCondition", + functionName: "fulfill", + parameters: [ { - "name": "_documentId", - "type": "bytes32", - "value": "" + name: "_documentId", + type: "bytes32", + value: "", }, { - "name": "_grantee", - "type": "address", - "value": "" - } + name: "_grantee", + type: "address", + value: "", + }, ], - "events": [ + events: [ { - "name": "Fulfilled", - "actorType": "publisher", - "handler": { - "moduleName": "accessSecretStore", - "functionName": "fulfillEscrowRewardCondition", - "version": "0.1" - } + name: "Fulfilled", + actorType: "publisher", + handler: { + moduleName: "accessSecretStore", + functionName: "fulfillEscrowRewardCondition", + version: "0.1", + }, }, { - "name": "TimedOut", - "actorType": "consumer", - "handler": { - "moduleName": "accessSecretStore", - "functionName": "fulfillEscrowRewardCondition", - "version": "0.1" - } - } - ] + name: "TimedOut", + actorType: "consumer", + handler: { + moduleName: "accessSecretStore", + functionName: "fulfillEscrowRewardCondition", + version: "0.1", + }, + }, + ], }, { - "name": "escrowReward", - "timelock": 0, - "timeout": 0, - "contractName": "EscrowReward", - "functionName": "fulfill", - "parameters": [ + name: "escrowReward", + timelock: 0, + timeout: 0, + contractName: "EscrowReward", + functionName: "fulfill", + parameters: [ { - "name": "_amount", - "type": "uint256", - "value": "" + name: "_amount", + type: "uint256", + value: "", }, { - "name": "_receiver", - "type": "address", - "value": "" + name: "_receiver", + type: "address", + value: "", }, { - "name": "_sender", - "type": "address", - "value": "" + name: "_sender", + type: "address", + value: "", }, { - "name": "_lockCondition", - "type": "bytes32", - "value": "" + name: "_lockCondition", + type: "bytes32", + value: "", }, { - "name": "_releaseCondition", - "type": "bytes32", - "value": "" - } + name: "_releaseCondition", + type: "bytes32", + value: "", + }, ], - "events": [ + events: [ { - "name": "Fulfilled", - "actorType": "publisher", - "handler": { - "moduleName": "escrowRewardCondition", - "functionName": "verifyRewardTokens", - "version": "0.1" - } - } - ] - } - ] + name: "Fulfilled", + actorType: "publisher", + handler: { + moduleName: "escrowRewardCondition", + functionName: "verifyRewardTokens", + version: "0.1", + }, + }, + ], + }, + ], } diff --git a/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts index a599ce8..79fdb6d 100644 --- a/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts +++ b/src/keeper/contracts/templates/EscrowAccessSecretStoreTemplate.ts @@ -1,8 +1,8 @@ import { AgreementTemplate } from "./AgreementTemplate.abstract" -import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from '../conditions' -import DIDRegistry from '../DIDRegistry' -import { DDO } from '../../../ddo/DDO' -import { generateId, zeroX } from '../../../utils' +import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from "../conditions" +import DIDRegistry from "../DIDRegistry" +import { DDO } from "../../../ddo/DDO" +import { generateId, zeroX } from "../../../utils" import { escrowAccessSecretStoreTemplateServiceAgreementTemplate } from "./EscrowAccessSecretStoreTemplate.serviceAgreementTemplate" @@ -47,7 +47,6 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate { ) } - public async createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string) { return !!await this.createFullAgreement( ddo.shortId(), diff --git a/src/keeper/contracts/templates/index.ts b/src/keeper/contracts/templates/index.ts index c2d719d..8341b65 100644 --- a/src/keeper/contracts/templates/index.ts +++ b/src/keeper/contracts/templates/index.ts @@ -1,2 +1,2 @@ -export * from './AgreementTemplate.abstract' -export { EscrowAccessSecretStoreTemplate } from './EscrowAccessSecretStoreTemplate' +export * from "./AgreementTemplate.abstract" +export { EscrowAccessSecretStoreTemplate } from "./EscrowAccessSecretStoreTemplate" diff --git a/src/ocean/OceanAgreementsConditions.ts b/src/ocean/OceanAgreementsConditions.ts index 416a56d..97d0676 100644 --- a/src/ocean/OceanAgreementsConditions.ts +++ b/src/ocean/OceanAgreementsConditions.ts @@ -43,7 +43,6 @@ export default class OceanAgreementsConditions { return !!receipt.events.Fulfilled } - /** * Authorize the consumer defined in the agreement to access (consume) this asset. * @param {string} agreementId Agreement ID. diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index a0108bd..cdaaf54 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -4,16 +4,14 @@ import BrizoProvider from "../brizo/BrizoProvider" import ConfigProvider from "../ConfigProvider" import { DDO } from "../ddo/DDO" import { MetaData } from "../ddo/MetaData" -import { ServiceAgreementTemplate, ServiceAgreementTemplateCondition } from "../ddo/ServiceAgreementTemplate" +import { ServiceAgreementTemplateCondition } from "../ddo/ServiceAgreementTemplate" import { Service, ServiceAuthorization } from "../ddo/Service" -import EventListener from "../keeper/EventListener" import Keeper from "../keeper/Keeper" import SecretStoreProvider from "../secretstore/SecretStoreProvider" import { Logger, fillConditionsWithDDO } from "../utils" import Account from "./Account" import DID from "./DID" import OceanAgreements from "./OceanAgreements" -import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" /** * Assets submodule of Ocean Protocol. @@ -70,7 +68,7 @@ export default class OceanAssets { const encryptedFiles = await SecretStoreProvider.getSecretStore(secretStoreConfig).encryptDocument(did.getId(), metadata.base.files) - const serviceAgreementTemplate: ServiceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate() + const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate() const serviceEndpoint = aquarius.getServiceEndpoint(did) @@ -145,8 +143,8 @@ export default class OceanAssets { }) // Overwritte initial service agreement conditions - const rawConditions: ServiceAgreementTemplateCondition[] = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions() - const conditions: ServiceAgreementTemplateCondition[] = fillConditionsWithDDO(rawConditions, ddo) + const rawConditions = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions() + const conditions = fillConditionsWithDDO(rawConditions, ddo) serviceAgreementTemplate.conditions = conditions ddo.addChecksum() diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index c933ade..bf6fa78 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -7,7 +7,6 @@ import Logger from "../../utils/Logger" import Account from "../Account" import { signText, zeroX } from "../../utils" - // TODO: move this class to helpers, it only contains pure functions export default class ServiceAgreement { @@ -58,7 +57,7 @@ export default class ServiceAgreement { timeoutValues, ) - let serviceAgreementHashSignature = await signText(serviceAgreementHash, consumer.getId(), consumer.getPassword()) + const serviceAgreementHashSignature = await signText(serviceAgreementHash, consumer.getId(), consumer.getPassword()) return serviceAgreementHashSignature } diff --git a/src/utils/ConversionTypeHelpers.ts b/src/utils/ConversionTypeHelpers.ts index 50cee05..f3e717f 100644 --- a/src/utils/ConversionTypeHelpers.ts +++ b/src/utils/ConversionTypeHelpers.ts @@ -1,4 +1,4 @@ -import { Logger } from './Logger' +import { Logger } from "./Logger" // Ox transformer export const zeroX = (input: string) => zeroXTransformer(input, true) @@ -24,12 +24,12 @@ function inputMatch(input: string, regexp: RegExp, conversorName: string): {vali if (typeof input !== "string") { Logger.debug("Not input string:") Logger.debug(input) - throw new Error(`[${conversorName}] Expected string, input type: ${typeof input}`); + throw new Error(`[${conversorName}] Expected string, input type: ${typeof input}`) } - const match = input.match(regexp) - if (!match) { + const match = input.match(regexp) + if (!match) { Logger.warn(`[${conversorName}] Input transformation failed.`) return {valid: false, output: input} } - return {valid: true, output: match[1]} + return {valid: true, output: match[1]} } diff --git a/src/utils/DDOHelpers.ts b/src/utils/DDOHelpers.ts index c1b7b1d..bc9917a 100644 --- a/src/utils/DDOHelpers.ts +++ b/src/utils/DDOHelpers.ts @@ -2,7 +2,7 @@ import { DDO } from "../ddo/DDO" import { ServiceAgreementTemplateCondition, ServiceAgreementTemplateParameter } from "../ddo/ServiceAgreementTemplate" function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo: DDO): ServiceAgreementTemplateParameter { - const getValue = name => { + const getValue = (name) => { switch (name) { case "amount": case "price": @@ -28,11 +28,11 @@ function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo: */ export function fillConditionsWithDDO(conditions: ServiceAgreementTemplateCondition[], ddo: DDO): ServiceAgreementTemplateCondition[] { return conditions - .map(condition => ({ + .map((condition) => ({ ...condition, parameters: condition.parameters - .map(parameter => ({ - ...fillParameterWithDDO(parameter, ddo) - })) + .map((parameter) => ({ + ...fillParameterWithDDO(parameter, ddo), + })), })) } diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index a902880..0a4896b 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -13,7 +13,7 @@ export class Logger { } public static bypass(...args: any[]) { - Logger.dispatch("log", -Infinity, ...args) + Logger.dispatch("log", -Infinity as any, ...args) } public static debug(...args: any[]) { diff --git a/src/utils/SignatureHelpers.ts b/src/utils/SignatureHelpers.ts index 1e2ee0c..d16f7f9 100644 --- a/src/utils/SignatureHelpers.ts +++ b/src/utils/SignatureHelpers.ts @@ -11,7 +11,7 @@ export async function signText(text: string, publicKey: string, password?: strin Logger.error(e) try { return await web3.eth.sign(text, publicKey, password) - } catch(e2) { + } catch (e2) { Logger.error("Error on sign.") Logger.error(e2) throw new Error("Error executing personal sign") diff --git a/src/utils/index.ts b/src/utils/index.ts index 6328e8e..16e8341 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,5 @@ -export { Logger, LogLevel } from './Logger' -export * from './SignatureHelpers' -export * from './ConversionTypeHelpers' -export * from './GeneratorHelpers' -export * from './DDOHelpers' +export { Logger, LogLevel } from "./Logger" +export * from "./SignatureHelpers" +export * from "./ConversionTypeHelpers" +export * from "./GeneratorHelpers" +export * from "./DDOHelpers" diff --git a/test/keeper/TestContractHandler.ts b/test/keeper/TestContractHandler.ts index 534961e..939f45d 100644 --- a/test/keeper/TestContractHandler.ts +++ b/test/keeper/TestContractHandler.ts @@ -62,7 +62,6 @@ export default class TestContractHandler extends ContractHandler { deployerAddress, conditionStoreManager.options.address, token.options.address, ]) - // Templates await TestContractHandler.deployContract("EscrowAccessSecretStoreTemplate", deployerAddress, [ deployerAddress, diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index e52c239..54bde3a 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -9,7 +9,6 @@ import { generateId } from "../../src/utils/GeneratorHelpers" import config from "../config" import TestContractHandler from "../keeper/TestContractHandler" - const did: DID = DID.generate() describe("ServiceAgreement", () => { diff --git a/test/utils/ConversionTypeHelpers.test.ts b/test/utils/ConversionTypeHelpers.test.ts index 9bb0fa3..8ef7a35 100644 --- a/test/utils/ConversionTypeHelpers.test.ts +++ b/test/utils/ConversionTypeHelpers.test.ts @@ -20,7 +20,7 @@ describe("ConversionTypeHelpers", () => { it("should return the value without 0x prefix", async () => { const result1 = noZeroX("0x1234") const result2 = noZeroX("1234") - assert.equal(result1, "1234",) + assert.equal(result1, "1234") assert.equal(result2, "1234") }) }) diff --git a/tslint.json b/tslint.json index bf5d0d2..0371ac2 100644 --- a/tslint.json +++ b/tslint.json @@ -11,7 +11,8 @@ "semicolon": [ true, "never" - ] + ], + "ordered-imports": false }, "rulesDirectory": [] }