From c57121e45bd8788f61c7ce22dbb90a22d75821c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Mon, 4 Mar 2019 14:34:24 +0100 Subject: [PATCH] checking the 0x prefix on all the interaction with contracts --- .../RegisterEscrowAccessSecretStoreTemplate.test.ts | 2 +- src/keeper/contracts/DIDRegistry.ts | 7 ++++--- .../contracts/conditions/AccessSecretStoreCondition.ts | 7 ++++--- src/keeper/contracts/conditions/Condition.abstract.ts | 7 ++++--- src/keeper/contracts/conditions/EscrowReward.ts | 5 +++-- src/keeper/contracts/conditions/LockRewardCondition.ts | 5 +++-- src/keeper/contracts/managers/TemplateStoreManager.ts | 9 +++++---- .../contracts/templates/AgreementTemplate.abstract.ts | 7 ++++--- 8 files changed, 28 insertions(+), 21 deletions(-) diff --git a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts index 10506fb..fb11115 100644 --- a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts +++ b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts @@ -65,7 +65,7 @@ describe("Register Escrow Access Secret Store Template", () => { let conditionIdEscrow: string it("should register a DID", async () => { - await keeper.didRegistry.registerAttribute(did.replace("0x", ""), checksum, url, publisher.getId()) + await keeper.didRegistry.registerAttribute(did, checksum, url, publisher.getId()) }) it("should generate the condition IDs", async () => { diff --git a/src/keeper/contracts/DIDRegistry.ts b/src/keeper/contracts/DIDRegistry.ts index 705bb5f..d23bc60 100644 --- a/src/keeper/contracts/DIDRegistry.ts +++ b/src/keeper/contracts/DIDRegistry.ts @@ -1,5 +1,6 @@ import Web3Provider from "../Web3Provider" import ContractBase from "./ContractBase" +import { zeroX } from "../../utils" export default class DIDRegistry extends ContractBase { @@ -10,14 +11,14 @@ export default class DIDRegistry extends ContractBase { } public async registerAttribute(did: string, checksum: string, value: string, ownerAddress: string) { - return this.send("registerAttribute", ownerAddress, ["0x" + did, Web3Provider.getWeb3().utils.fromAscii(checksum), value]) + return this.send("registerAttribute", ownerAddress, [zeroX(did), Web3Provider.getWeb3().utils.fromAscii(checksum), value]) } public async getDIDOwner(did: string): Promise { - return this.call("getDIDOwner", [did]) + return this.call("getDIDOwner", [zeroX(did)]) } public async getBlockNumberUpdated(did: string): Promise { - return +await this.call("getBlockNumberUpdated", [did]) + return +await this.call("getBlockNumberUpdated", [zeroX(did)]) } } diff --git a/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts b/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts index 5ef4775..d20854e 100644 --- a/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts +++ b/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts @@ -1,4 +1,5 @@ import { Condition } from "./Condition.abstract" +import { zeroX } from "../../../utils" export class AccessSecretStoreCondition extends Condition { @@ -7,14 +8,14 @@ export class AccessSecretStoreCondition extends Condition { } hashValues(did: string, grantee: string) { - return super.hashValues(did, grantee) + return super.hashValues(did, zeroX(grantee)) } fulfill(agreementId: string, did: string, grantee: string, from?: string) { - return super.fulfill(agreementId, [did, grantee], from) + return super.fulfill(agreementId, [did, grantee].map(zeroX), from) } checkPermissions(grantee: string, did: string, from?: string) { - return this.call("checkPermissions", [grantee, did], from) + return this.call("checkPermissions", [grantee, did].map(zeroX), from) } } diff --git a/src/keeper/contracts/conditions/Condition.abstract.ts b/src/keeper/contracts/conditions/Condition.abstract.ts index 94b7348..3f7c900 100644 --- a/src/keeper/contracts/conditions/Condition.abstract.ts +++ b/src/keeper/contracts/conditions/Condition.abstract.ts @@ -1,4 +1,5 @@ import ContractBase from "../ContractBase" +import { zeroX } from "../../../utils" export enum ConditionState { Uninitialized = 0, @@ -26,7 +27,7 @@ export abstract class Condition extends ContractBase { fulfill(agreementId: string, ...args: any[]) fulfill(agreementId: string, args: any[], from?: string) { - return this.sendFrom("fulfill", [agreementId, ...args], from) + return this.sendFrom("fulfill", [zeroX(agreementId), ...args], from) } async generateIdHash(agreementId: string, ...values: any[]) { @@ -34,10 +35,10 @@ export abstract class Condition extends ContractBase { } generateId(agreementId: string, valueHash: string) { - return this.call("generateId", [agreementId, valueHash]) + return this.call("generateId", [zeroX(agreementId), valueHash]) } abortByTimeOut(agreementId: string, from?: string) { - return this.sendFrom("requestTokens", [agreementId], from) + return this.sendFrom("requestTokens", [zeroX(agreementId)], from) } } diff --git a/src/keeper/contracts/conditions/EscrowReward.ts b/src/keeper/contracts/conditions/EscrowReward.ts index f4f293f..50ab4aa 100644 --- a/src/keeper/contracts/conditions/EscrowReward.ts +++ b/src/keeper/contracts/conditions/EscrowReward.ts @@ -1,4 +1,5 @@ import { Condition } from "./Condition.abstract" +import { zeroX } from "../../../utils" export class EscrowReward extends Condition { @@ -7,7 +8,7 @@ export class EscrowReward extends Condition { } hashValues(amount: number, receiver: string, sender: string, lockCondition: string, releaseCondition: string) { - return super.hashValues(amount, receiver, sender, lockCondition, releaseCondition) + return super.hashValues(amount, ...[receiver, sender, lockCondition, releaseCondition].map(zeroX)) } fulfill( @@ -19,6 +20,6 @@ export class EscrowReward extends Condition { releaseCondition: string, from?: string, ) { - return super.fulfill(agreementId, [amount, receiver, sender, lockCondition, releaseCondition], from) + return super.fulfill(agreementId, [amount, ...[receiver, sender, lockCondition, releaseCondition].map(zeroX)], from) } } diff --git a/src/keeper/contracts/conditions/LockRewardCondition.ts b/src/keeper/contracts/conditions/LockRewardCondition.ts index 0f02c82..3e99509 100644 --- a/src/keeper/contracts/conditions/LockRewardCondition.ts +++ b/src/keeper/contracts/conditions/LockRewardCondition.ts @@ -1,4 +1,5 @@ import { Condition } from "./Condition.abstract" +import { zeroX } from "../../../utils" export class LockRewardCondition extends Condition { @@ -7,10 +8,10 @@ export class LockRewardCondition extends Condition { } hashValues(rewardAddress: string, amount: number) { - return super.hashValues(rewardAddress, amount) + return super.hashValues(zeroX(rewardAddress), amount) } fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) { - return super.fulfill(agreementId, [rewardAddress, amount], from) + return super.fulfill(agreementId, [zeroX(rewardAddress), amount], from) } } diff --git a/src/keeper/contracts/managers/TemplateStoreManager.ts b/src/keeper/contracts/managers/TemplateStoreManager.ts index 9e1d6bc..74510f4 100644 --- a/src/keeper/contracts/managers/TemplateStoreManager.ts +++ b/src/keeper/contracts/managers/TemplateStoreManager.ts @@ -1,5 +1,6 @@ import Logger from "../../../utils/Logger" import ContractBase from "../ContractBase" +import { zeroX } from "../../../utils" export enum TemplateState { Uninitialized = 0, @@ -35,7 +36,7 @@ export class TemplateStoreManager extends ContractBase { throw new Error("Template already exist.") } } else { - return this.sendFrom("proposeTemplate", [address], from) + return this.sendFrom("proposeTemplate", [zeroX(address)], from) } } @@ -47,16 +48,16 @@ export class TemplateStoreManager extends ContractBase { throw new Error(`Template not in "proposed" state.`) } } else { - return this.sendFrom("approveTemplate", [address], from) + return this.sendFrom("approveTemplate", [zeroX(address)], from) } } public revokeTemplate(address: string, from?: string) { - return this.sendFrom("revokeTemplate", [address], from) + return this.sendFrom("revokeTemplate", [zeroX(address)], from) } public async getTemplate(address: string) { - const {state, owner, lastUpdatedBy, blockNumberUpdated} = await this.call("getTemplate", [address]) + const {state, owner, lastUpdatedBy, blockNumberUpdated} = await this.call("getTemplate", [zeroX(address)]) return {state: +state, owner, lastUpdatedBy, blockNumberUpdated: +blockNumberUpdated} as TemplateMetadata } } diff --git a/src/keeper/contracts/templates/AgreementTemplate.abstract.ts b/src/keeper/contracts/templates/AgreementTemplate.abstract.ts index daa1e14..081ad12 100644 --- a/src/keeper/contracts/templates/AgreementTemplate.abstract.ts +++ b/src/keeper/contracts/templates/AgreementTemplate.abstract.ts @@ -1,6 +1,7 @@ import ContractBase from "../ContractBase" import { Condition } from "../conditions/Condition.abstract" import Keeper from "../../Keeper" +import { zeroX } from "../../../utils" export abstract class AgreementTemplate extends ContractBase { @@ -28,9 +29,9 @@ export abstract class AgreementTemplate extends ContractBase { return this.sendFrom( "createAgreement", [ - agreementId, - did, - conditionIds, + zeroX(agreementId), + zeroX(did), + conditionIds.map(zeroX), timeLocks, timeOuts, ...extraArgs,