mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
commit
e02a92ffc5
@ -7,6 +7,7 @@
|
||||
import { CID } from 'multiformats/cid'
|
||||
import { base58btc } from 'multiformats/bases/base58'
|
||||
import { TimeoutController } from 'timeout-abort-controller'
|
||||
import drain from 'it-drain'
|
||||
|
||||
const DefaultTimeout = 30000 // 30 seconds
|
||||
|
||||
@ -41,7 +42,7 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => {
|
||||
await ipfs.blockstore.put(cid, data, { signal })
|
||||
|
||||
if (pin && !(await ipfs.pins.isPinned(cid))) {
|
||||
await ipfs.pins.add(cid)
|
||||
await drain(ipfs.pins.add(cid))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,28 @@ describe('IPFSBlockStorage', function () {
|
||||
})
|
||||
|
||||
it('gets a block', async () => {
|
||||
const expected = 'hello world'
|
||||
const { cid, bytes } = await Block.encode({ value: expected, codec, hasher })
|
||||
|
||||
const hash = cid.toString(base58btc)
|
||||
|
||||
await storage.put(hash, bytes)
|
||||
|
||||
const data = await storage.get(hash)
|
||||
const block = await Block.decode({ bytes: data, codec, hasher })
|
||||
const actual = block.value
|
||||
|
||||
strictEqual(actual, expected)
|
||||
})
|
||||
|
||||
it('checks that a block is pinned', async () => {
|
||||
const expected = 'hello world'
|
||||
const block = await Block.encode({ value: expected, codec, hasher })
|
||||
const cid = block.cid.toString(base58btc)
|
||||
|
||||
await storage.put(cid, 'hello world')
|
||||
const actual = await storage.get(cid)
|
||||
await storage.put(cid, block.bytes)
|
||||
|
||||
strictEqual(actual, expected)
|
||||
strictEqual(await ipfs.pins.isPinned(block.cid), true)
|
||||
})
|
||||
|
||||
it('throws an error if a block does not exist', async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user