mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import assert from 'assert'
|
|
import DID from '../../src/ocean/DID'
|
|
|
|
describe('DID', () => {
|
|
describe('#generate()', () => {
|
|
it('should generate a new did', () => {
|
|
const did: DID = DID.generate()
|
|
assert(did)
|
|
})
|
|
})
|
|
|
|
describe('#parse()', () => {
|
|
it('should parse a valid did', () => {
|
|
const id = 'a'.repeat(64)
|
|
const did: DID = DID.parse(`did:op:${id}`)
|
|
assert(did)
|
|
|
|
assert(did.getId() === id, did.getId())
|
|
})
|
|
|
|
it('should throw if prefix does not match', done => {
|
|
const id = '1234'
|
|
try {
|
|
const did: DID = DID.parse(`did:xxx:${id}`)
|
|
assert(!did)
|
|
} catch {
|
|
done()
|
|
}
|
|
})
|
|
|
|
it('should throw if id does not match', done => {
|
|
const id = 'xyz'
|
|
try {
|
|
const did: DID = DID.parse(`did:op:${id}`)
|
|
assert(!did)
|
|
} catch {
|
|
done()
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('#getDid()', () => {
|
|
it('should return the full did', () => {
|
|
const did: DID = DID.generate()
|
|
assert(did)
|
|
|
|
assert(did.getDid().startsWith('did:op:'))
|
|
})
|
|
})
|
|
|
|
describe('#getDid()', () => {
|
|
it('should return only the id part of the did', () => {
|
|
const id = 'a'.repeat(64)
|
|
const did: DID = DID.parse(`did:op:${id}`)
|
|
assert(did)
|
|
|
|
assert(did.getId() === id)
|
|
})
|
|
})
|
|
})
|