diff --git a/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts b/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts index d20854e..bd9f71c 100644 --- a/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts +++ b/src/keeper/contracts/conditions/AccessSecretStoreCondition.ts @@ -8,7 +8,7 @@ export class AccessSecretStoreCondition extends Condition { } hashValues(did: string, grantee: string) { - return super.hashValues(did, zeroX(grantee)) + return super.hashValues(zeroX(did), zeroX(grantee)) } fulfill(agreementId: string, did: string, grantee: string, from?: string) { diff --git a/test/keeper/conditions/AccessSecretStoreCondition.test.ts b/test/keeper/conditions/AccessSecretStoreCondition.test.ts new file mode 100644 index 0000000..6e4ce7a --- /dev/null +++ b/test/keeper/conditions/AccessSecretStoreCondition.test.ts @@ -0,0 +1,40 @@ +import {assert} from "chai" +import ConfigProvider from "../../../src/ConfigProvider" +import { AccessSecretStoreCondition } from "../../../src/keeper/contracts/conditions" +import Keeper from "../../../src/keeper/Keeper" +import config from "../../config" +import TestContractHandler from "../TestContractHandler" + +let condition: AccessSecretStoreCondition + +describe("AccessSecretStoreCondition", () => { + + const agreementId = `0x${"a".repeat(64)}` + const did = `0x${"a".repeat(64)}` + const address = `0x${"a".repeat(40)}` + + before(async () => { + ConfigProvider.setConfig(config) + await TestContractHandler.prepareContracts() + condition = (await Keeper.getInstance()).conditions.accessSecretStoreCondition + + }) + + describe("#hashValues()", () => { + it("should hash the values", async () => { + const hash = await condition.hashValues(did, address) + + assert.match(hash, /^0x[a-f0-9]{64}$/i) + assert.equal(hash, "0x1abbd7e58bc32bff739ee1e756a4108882322f2ec939d5e2f251e6b8424947fb", "The hash is not the expected.") + }) + }) + + describe("#generateId()", () => { + it("should generate an ID", async () => { + const hash = await condition.hashValues(did, address) + const id = await condition.generateId(agreementId, hash) + + assert.match(id, /^0x[a-f0-9]{64}$/i) + }) + }) +}) diff --git a/test/keeper/conditions/EscrowReward.test.ts b/test/keeper/conditions/EscrowReward.test.ts new file mode 100644 index 0000000..6959dd3 --- /dev/null +++ b/test/keeper/conditions/EscrowReward.test.ts @@ -0,0 +1,46 @@ +import {assert} from "chai" +import ConfigProvider from "../../../src/ConfigProvider" +import { EscrowReward } from "../../../src/keeper/contracts/conditions" +import Keeper from "../../../src/keeper/Keeper" +import config from "../../config" +import TestContractHandler from "../TestContractHandler" + +let condition: EscrowReward + +describe("EscrowReward", () => { + + const agreementId = `0x${"a".repeat(64)}` + const did = `0x${"a".repeat(64)}` + const amount = 15 + const publisher = `0x${"a".repeat(40)}` + const consumer = `0x${"b".repeat(40)}` + let lockCondition + let releaseCondition + + before(async () => { + ConfigProvider.setConfig(config) + await TestContractHandler.prepareContracts() + const keeper = await Keeper.getInstance() + condition = keeper.conditions.escrowReward + + lockCondition = await keeper.conditions.lockRewardCondition.generateIdHash(agreementId, publisher, amount) + releaseCondition = await keeper.conditions.accessSecretStoreCondition.generateIdHash(agreementId, did, consumer) + }) + + describe("#hashValues()", () => { + it("should hash the values", async () => { + const hash = await condition.hashValues(amount, consumer, publisher, lockCondition, releaseCondition) + + assert.match(hash, /^0x[a-f0-9]{64}$/i) + }) + }) + + describe("#generateId()", () => { + it("should generate an ID", async () => { + const hash = await condition.hashValues(amount, consumer, publisher, lockCondition, releaseCondition) + const id = await condition.generateId(agreementId, hash) + + assert.match(id, /^0x[a-f0-9]{64}$/i) + }) + }) +}) diff --git a/test/keeper/conditions/LockRewardCondition.test.ts b/test/keeper/conditions/LockRewardCondition.test.ts new file mode 100644 index 0000000..1b273d1 --- /dev/null +++ b/test/keeper/conditions/LockRewardCondition.test.ts @@ -0,0 +1,40 @@ +import {assert} from "chai" +import ConfigProvider from "../../../src/ConfigProvider" +import { LockRewardCondition } from "../../../src/keeper/contracts/conditions" +import Keeper from "../../../src/keeper/Keeper" +import config from "../../config" +import TestContractHandler from "../TestContractHandler" + +let condition: LockRewardCondition + +describe("LockRewardCondition", () => { + + const agreementId = `0x${"a".repeat(64)}` + const address = `0x${"a".repeat(40)}` + const amount = 15 + + before(async () => { + ConfigProvider.setConfig(config) + await TestContractHandler.prepareContracts() + condition = (await Keeper.getInstance()).conditions.lockRewardCondition + + }) + + describe("#hashValues()", () => { + it("should hash the values", async () => { + const hash = await condition.hashValues(address, amount) + + assert.match(hash, /^0x[a-f0-9]{64}$/i) + assert.equal(hash, "0x2543c2ea4b9403bb3e5df1145c70731454748e72a37acc80d025f85e03267973", "The hash is not the expected.") + }) + }) + + describe("#generateId()", () => { + it("should generate an ID", async () => { + const hash = await condition.hashValues(address, amount) + const id = await condition.generateId(agreementId, hash) + + assert.match(id, /^0x[a-f0-9]{64}$/i) + }) + }) +})