squid-js/test/integration/ocean/Signature.test.ts

92 lines
2.8 KiB
TypeScript

import { assert } from 'chai'
import { config } from '../config'
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)
describe('Signature', () => {
let ocean: Ocean
let consumer: Account
before(async () => {
ocean = await Ocean.getInstance(config)
// Accounts
;[consumer] = await ocean.accounts.list()
})
it('hashServiceAgreement should generate the correct signature', () => {
const templateId = `0x${'f'.repeat(64)}`
const agreementId = `0x${'e'.repeat(64)}`
const accessId = `0x${'a'.repeat(64)}`
const lockId = `0x${'b'.repeat(64)}`
const escrowId = `0x${'c'.repeat(64)}`
const hash = ocean.utils.agreements.hashServiceAgreement(
templateId,
agreementId,
[lockId, accessId, escrowId],
[0, 0, 0],
[0, 0, 0]
)
assert.equal(
hash,
'0x464dac3b79a47f8acad54f67a0f4473249330f025c69687531e58c2e43b36437',
'The signature is not correct.'
)
})
it('signServiceAgreement should generate the correct signature', async () => {
const { templates } = ocean.keeper
const did = `did:op:${'c'.repeat(64)}`
const templateId = `0x${'f'.repeat(64)}`
const agreementId = `0x${'e'.repeat(64)}`
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
const ddo = new DDO({
id: did,
service: [
{
type: 'access',
index: 0,
purchaseEndpoint: undefined,
serviceEndpoint: undefined,
templateId,
attributes: {
serviceAgreementTemplate
}
} as any,
{
type: 'metadata',
index: 1,
attributes: {
main: {
price: 10
}
}
} as any
]
})
const signature = await ocean.utils.agreements.signServiceAgreement(
ddo,
0,
agreementId,
[`0x${'1'.repeat(64)}`, `0x${'2'.repeat(64)}`, `0x${'3'.repeat(64)}`],
consumer
)
assert.equal(
signature,
'0xa04568fccdda7e1594e3e615f8d71b14733705aabe5294af0b7f46f0aedb9d5906a2caa6142ee4de10534a47c5a7083b21b2d3e9a96ac462bc0b9d25070e981e1c',
'The signature is not correct.'
)
})
})