2019-06-20 00:20:09 +02:00
|
|
|
import { assert } from 'chai'
|
2019-03-11 22:52:53 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
import { config } from '../config'
|
2019-03-11 22:52:53 +01:00
|
|
|
|
2020-01-30 22:08:18 +01:00
|
|
|
import { Ocean, Account, DDO } from '../../../src' // @oceanprotocol/squid
|
2019-03-11 22:52:53 +01:00
|
|
|
|
|
|
|
// WARN: not integration test. It has been done here because constant values
|
|
|
|
// depends on the first account on spree (only accessible from integration test)
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('Signature', () => {
|
2019-03-21 03:02:05 +01:00
|
|
|
let ocean: Ocean
|
2019-03-11 22:52:53 +01:00
|
|
|
let consumer: Account
|
|
|
|
|
|
|
|
before(async () => {
|
2019-04-01 12:40:45 +02:00
|
|
|
ocean = await Ocean.getInstance(config)
|
2019-03-11 22:52:53 +01:00
|
|
|
|
|
|
|
// Accounts
|
2019-06-24 13:06:38 +02:00
|
|
|
;[consumer] = await ocean.accounts.list()
|
2019-03-11 22:52:53 +01:00
|
|
|
})
|
|
|
|
|
2019-10-30 17:33:46 +01:00
|
|
|
it('hashServiceAgreement should generate the correct signature', () => {
|
2020-01-20 11:44:13 +01:00
|
|
|
const templateId = `0x${'f'.repeat(64)}`
|
2019-06-20 00:20:09 +02:00
|
|
|
const agreementId = `0x${'e'.repeat(64)}`
|
2019-03-11 22:52:53 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
const accessId = `0x${'a'.repeat(64)}`
|
|
|
|
const lockId = `0x${'b'.repeat(64)}`
|
|
|
|
const escrowId = `0x${'c'.repeat(64)}`
|
2019-03-11 22:52:53 +01:00
|
|
|
|
2019-10-30 17:33:46 +01:00
|
|
|
const hash = ocean.utils.agreements.hashServiceAgreement(
|
2019-03-11 22:52:53 +01:00
|
|
|
templateId,
|
|
|
|
agreementId,
|
2020-01-17 15:35:11 +01:00
|
|
|
[lockId, accessId, escrowId],
|
2019-03-11 22:52:53 +01:00
|
|
|
[0, 0, 0],
|
2019-06-20 00:20:09 +02:00
|
|
|
[0, 0, 0]
|
2019-03-11 22:52:53 +01:00
|
|
|
)
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert.equal(
|
|
|
|
hash,
|
2020-01-20 11:44:13 +01:00
|
|
|
'0x464dac3b79a47f8acad54f67a0f4473249330f025c69687531e58c2e43b36437',
|
2019-10-30 17:33:46 +01:00
|
|
|
'The signature is not correct.'
|
2019-06-20 00:20:09 +02:00
|
|
|
)
|
2019-03-11 22:52:53 +01:00
|
|
|
})
|
|
|
|
|
2019-10-30 17:33:46 +01:00
|
|
|
it('signServiceAgreement should generate the correct signature', async () => {
|
2019-06-20 00:20:09 +02:00
|
|
|
const { templates } = ocean.keeper
|
2019-03-11 22:52:53 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
const did = `did:op:${'c'.repeat(64)}`
|
2020-01-20 11:44:13 +01:00
|
|
|
const templateId = `0x${'f'.repeat(64)}`
|
2019-06-20 00:20:09 +02:00
|
|
|
const agreementId = `0x${'e'.repeat(64)}`
|
2019-03-11 22:52:53 +01:00
|
|
|
|
|
|
|
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
|
|
|
|
|
|
|
const ddo = new DDO({
|
|
|
|
id: did,
|
|
|
|
service: [
|
|
|
|
{
|
2019-08-16 14:12:31 +02:00
|
|
|
type: 'access',
|
2019-08-16 16:12:42 +02:00
|
|
|
index: 0,
|
2019-03-11 22:52:53 +01:00
|
|
|
purchaseEndpoint: undefined,
|
|
|
|
serviceEndpoint: undefined,
|
|
|
|
templateId,
|
2019-09-13 13:38:23 +02:00
|
|
|
attributes: {
|
|
|
|
serviceAgreementTemplate
|
|
|
|
}
|
2019-03-11 22:52:53 +01:00
|
|
|
} as any,
|
2019-03-14 16:57:28 +01:00
|
|
|
{
|
2019-08-16 14:12:31 +02:00
|
|
|
type: 'metadata',
|
2019-08-16 16:12:42 +02:00
|
|
|
index: 1,
|
|
|
|
attributes: {
|
2019-08-15 13:23:56 +02:00
|
|
|
main: {
|
2019-06-20 00:20:09 +02:00
|
|
|
price: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} as any
|
|
|
|
]
|
2019-03-11 22:52:53 +01:00
|
|
|
})
|
|
|
|
|
2019-03-28 12:20:22 +01:00
|
|
|
const signature = await ocean.utils.agreements.signServiceAgreement(
|
2019-03-11 22:52:53 +01:00
|
|
|
ddo,
|
2019-08-16 16:12:42 +02:00
|
|
|
0,
|
2019-03-11 22:52:53 +01:00
|
|
|
agreementId,
|
2019-09-09 12:18:54 +02:00
|
|
|
[`0x${'1'.repeat(64)}`, `0x${'2'.repeat(64)}`, `0x${'3'.repeat(64)}`],
|
2019-06-20 00:20:09 +02:00
|
|
|
consumer
|
2019-03-11 22:52:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
signature,
|
2020-01-20 11:44:13 +01:00
|
|
|
'0xa04568fccdda7e1594e3e615f8d71b14733705aabe5294af0b7f46f0aedb9d5906a2caa6142ee4de10534a47c5a7083b21b2d3e9a96ac462bc0b9d25070e981e1c',
|
2019-10-30 17:33:46 +01:00
|
|
|
'The signature is not correct.'
|
2019-03-11 22:52:53 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|