1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/test/integration/ocean/Signature.test.ts

92 lines
2.8 KiB
TypeScript
Raw Normal View History

2019-06-20 00:20:09 +02:00
import { assert } from 'chai'
2019-06-20 00:20:09 +02:00
import { config } from '../config'
2020-01-31 00:15:55 +01:00
import { Ocean, Account, DDO } from '../../../src' // @oceanprotocol/squid
// 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', () => {
let ocean: Ocean
let consumer: Account
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
2019-06-24 13:06:38 +02:00
;[consumer] = await ocean.accounts.list()
})
2019-10-30 17:33:46 +01:00
it('hashServiceAgreement should generate the correct signature', () => {
const templateId = `0x${'f'.repeat(64)}`
2019-06-20 00:20:09 +02:00
const agreementId = `0x${'e'.repeat(64)}`
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-10-30 17:33:46 +01:00
const hash = ocean.utils.agreements.hashServiceAgreement(
templateId,
agreementId,
2020-01-17 15:35:11 +01:00
[lockId, accessId, escrowId],
[0, 0, 0],
2019-06-20 00:20:09 +02:00
[0, 0, 0]
)
2019-06-20 00:20:09 +02:00
assert.equal(
hash,
'0x464dac3b79a47f8acad54f67a0f4473249330f025c69687531e58c2e43b36437',
2019-10-30 17:33:46 +01:00
'The signature is not correct.'
2019-06-20 00:20:09 +02: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-06-20 00:20:09 +02:00
const did = `did:op:${'c'.repeat(64)}`
const templateId = `0x${'f'.repeat(64)}`
2019-06-20 00:20:09 +02:00
const agreementId = `0x${'e'.repeat(64)}`
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,
purchaseEndpoint: undefined,
serviceEndpoint: undefined,
templateId,
2019-09-13 13:38:23 +02:00
attributes: {
serviceAgreementTemplate
}
} 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
]
})
const signature = await ocean.utils.agreements.signServiceAgreement(
ddo,
2019-08-16 16:12:42 +02:00
0,
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
)
assert.equal(
signature,
'0xa04568fccdda7e1594e3e615f8d71b14733705aabe5294af0b7f46f0aedb9d5906a2caa6142ee4de10534a47c5a7083b21b2d3e9a96ac462bc0b9d25070e981e1c',
2019-10-30 17:33:46 +01:00
'The signature is not correct.'
)
})
})