mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00

Fix sync Fix linter Fix tests Clean up Set default references count to 0 Fix sync Use address instead of databaseId Sync protocol Keep references to open databases in OrbitDB Fix append benchmark Initial version of heads exchange Remove Feed Fix KeyValuePersisted iterator Refactor OrbitDBAddress a bit more Add rest of the database types Refactor OrbitDB addresses Initial version for the full circle Initial structure and tests for new OrbitDB Make sure KeyStore is open when a Database is created Re-organize OrbitDB Use new databases and Log More clean up Add 'drop' event to Database Clean up OrbitDB Remove id from OrbitDB Use new KeyStore and Identities Remove storage from OrbitDB Remove migrations from OrbitDB Remove caches from OrbitDB Remove pubsub from OrbitDB
150 lines
5.1 KiB
JavaScript
150 lines
5.1 KiB
JavaScript
import { strictEqual, notStrictEqual } from 'assert'
|
|
import { OrbitDBAddress, isValidAddress, parseAddress } from '../src/index.js'
|
|
|
|
describe('OrbitDB Address', function () {
|
|
describe('Creating an address from full address string', () => {
|
|
it('creates an address from full address string', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
notStrictEqual(addr, undefined)
|
|
})
|
|
|
|
it('has a protocol prefix', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
strictEqual(addr.protocol, 'orbitdb')
|
|
})
|
|
|
|
it('has a path', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
strictEqual(addr.path, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
|
})
|
|
})
|
|
|
|
describe('Creating an address from hash string', () => {
|
|
it('creates an address', () => {
|
|
const address = 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
notStrictEqual(addr, undefined)
|
|
})
|
|
|
|
it('has a protocol prefix', () => {
|
|
const address = 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
strictEqual(addr.protocol, 'orbitdb')
|
|
})
|
|
|
|
it('has a path', () => {
|
|
const address = 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
strictEqual(addr.path, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
|
})
|
|
})
|
|
|
|
describe('Converting address to a string', () => {
|
|
it('outputs a valid address string', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
const result = addr.toString()
|
|
strictEqual(result, address)
|
|
})
|
|
})
|
|
|
|
describe('isValid Address', () => {
|
|
it('is not valid if address is an empty string', () => {
|
|
const result = isValidAddress('')
|
|
strictEqual(result, false)
|
|
})
|
|
|
|
it('is a valid address', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const result = isValidAddress(address)
|
|
strictEqual(result, true)
|
|
})
|
|
|
|
it('is a valid address if it\'s another instance of OrbitDBAddress', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const addr = OrbitDBAddress(address)
|
|
const result = isValidAddress(addr)
|
|
strictEqual(result, true)
|
|
})
|
|
|
|
it('is not valid address if it\'s missing the /orbitdb prefix', () => {
|
|
const address = 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const result = isValidAddress(address)
|
|
|
|
strictEqual(result, false)
|
|
})
|
|
|
|
it('is not a valid address if the multihash is invalid - v0', () => {
|
|
const address = '/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzc'
|
|
const result = isValidAddress(address)
|
|
|
|
strictEqual(result, false)
|
|
})
|
|
|
|
it('is not a valid address if the multihash is invalid - v2', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw133333'
|
|
const result = isValidAddress(address)
|
|
|
|
strictEqual(result, false)
|
|
})
|
|
|
|
it('is a valid address in win32 format', () => {
|
|
const address = '\\orbitdb\\Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC'
|
|
const result = isValidAddress(address)
|
|
|
|
strictEqual(result, true)
|
|
})
|
|
})
|
|
|
|
describe('Parsing an address', () => {
|
|
it('parses a valid address', () => {
|
|
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
|
const result = parseAddress(address)
|
|
|
|
strictEqual(result.protocol, 'orbitdb')
|
|
strictEqual(result.path, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
|
|
|
strictEqual(result.toString().indexOf('/orbitdb'), 0)
|
|
strictEqual(result.toString().indexOf('zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'), 9)
|
|
})
|
|
|
|
it('parses a valid address in win32 format', () => {
|
|
const address = '\\orbitdb\\Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC'
|
|
const result = parseAddress(address)
|
|
|
|
strictEqual(result.protocol, 'orbitdb')
|
|
strictEqual(result.path, 'Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC')
|
|
|
|
strictEqual(result.toString().indexOf('/orbitdb'), 0)
|
|
strictEqual(result.toString().indexOf('Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC'), 9)
|
|
})
|
|
|
|
it('throws an error if address is empty', () => {
|
|
let err
|
|
try {
|
|
parseAddress('')
|
|
} catch (e) {
|
|
err = e.toString()
|
|
}
|
|
strictEqual(err, 'Error: Not a valid OrbitDB address: ')
|
|
})
|
|
|
|
it('throws an error if address contains too many parts', () => {
|
|
const address = '/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzc/this-should-not-be-here'
|
|
|
|
let err
|
|
try {
|
|
parseAddress(address)
|
|
} catch (e) {
|
|
err = e
|
|
}
|
|
|
|
notStrictEqual(err, undefined)
|
|
strictEqual(err.message, `Not a valid OrbitDB address: ${address}`)
|
|
})
|
|
})
|
|
})
|