2019-06-20 00:20:09 +02:00
|
|
|
import { assert } from 'chai'
|
|
|
|
import { EscrowReward } from '../../../src/keeper/contracts/conditions'
|
|
|
|
import { Ocean } from '../../../src/ocean/Ocean'
|
|
|
|
import config from '../../config'
|
|
|
|
import TestContractHandler from '../TestContractHandler'
|
2019-03-06 15:58:15 +01:00
|
|
|
|
|
|
|
let condition: EscrowReward
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('EscrowReward', () => {
|
|
|
|
const agreementId = `0x${'a'.repeat(64)}`
|
|
|
|
const did = `0x${'a'.repeat(64)}`
|
2019-03-06 15:58:15 +01:00
|
|
|
const amount = 15
|
2019-06-20 00:20:09 +02:00
|
|
|
const publisher = `0x${'a'.repeat(40)}`
|
|
|
|
const consumer = `0x${'b'.repeat(40)}`
|
2019-03-06 15:58:15 +01:00
|
|
|
let lockCondition
|
|
|
|
let releaseCondition
|
|
|
|
|
|
|
|
before(async () => {
|
2019-08-15 14:13:21 +02:00
|
|
|
const { keeper } = await Ocean.getInstance(config)
|
2019-03-21 02:56:58 +01:00
|
|
|
|
2019-03-06 15:58:15 +01:00
|
|
|
await TestContractHandler.prepareContracts()
|
|
|
|
condition = keeper.conditions.escrowReward
|
|
|
|
|
2019-09-09 12:18:54 +02:00
|
|
|
lockCondition = await keeper.conditions.lockRewardCondition.generateIdHash(agreementId, publisher, amount)
|
|
|
|
releaseCondition = await keeper.conditions.accessSecretStoreCondition.generateIdHash(agreementId, did, consumer)
|
2019-03-06 15:58:15 +01:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#hashValues()', () => {
|
|
|
|
it('should hash the values', async () => {
|
2019-09-09 12:18:54 +02:00
|
|
|
const hash = await condition.hashValues(amount, consumer, publisher, lockCondition, releaseCondition)
|
2019-03-06 15:58:15 +01:00
|
|
|
|
|
|
|
assert.match(hash, /^0x[a-f0-9]{64}$/i)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#generateId()', () => {
|
|
|
|
it('should generate an ID', async () => {
|
2019-09-09 12:18:54 +02:00
|
|
|
const hash = await condition.hashValues(amount, consumer, publisher, lockCondition, releaseCondition)
|
2019-03-06 15:58:15 +01:00
|
|
|
const id = await condition.generateId(agreementId, hash)
|
|
|
|
|
|
|
|
assert.match(id, /^0x[a-f0-9]{64}$/i)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|