Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
add fetch entries test
Browse files Browse the repository at this point in the history
  • Loading branch information
shamb0t committed Nov 4, 2019
1 parent 4237fda commit d2c8c80
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/fetch-entries.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict'

const assert = require('assert')
const rmrf = require('rimraf')
const IPFSRepo = require('ipfs-repo')
const DatastoreLevel = require('datastore-level')
const Log = require('../src/log')
const EntryIO = require('../src/entry-io')
const IdentityProvider = require('orbit-db-identity-provider')
const Keystore = require('orbit-db-keystore')

// Test utils
const {
config,
testAPIs,
startIpfs,
stopIpfs
} = require('orbit-db-test-utils')

let ipfs, ipfsDaemon, testIdentity

const last = arr => arr[arr.length - 1]

Object.keys(testAPIs).forEach((IPFS) => {
describe('Fetch entries', function() {
this.timeout(config.timeout)

const { identityKeyFixtures, signingKeyFixtures, identityKeysPath, signingKeysPath } = config
const ipfsConfig = Object.assign({}, config.defaultIpfsConfig, {
repo: config.defaultIpfsConfig.repo + '-log-append' + new Date().getTime()
})

let keystore, signingKeystore

before(async () => {
rmrf.sync(ipfsConfig.repo)
rmrf.sync(identityKeysPath)
rmrf.sync(signingKeysPath)

keystore = new Keystore(identityKeysPath)
signingKeystore = new Keystore(signingKeysPath)

testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore })
ipfs = await startIpfs(IPFS, ipfsConfig)
})

after(async () => {
if (ipfs)
await ipfs.stop()
await keystore.close()
await signingKeystore.close()
})

it('log with 10 entries', async () => {
const count = 100
let log = new Log(ipfs, testIdentity, 'X', )

for (let i = 1; i < count + 1; i ++)
await log.append('hello' + i, 8)

const result = await EntryIO.fetchAll(ipfs, log.heads.map(e => e.hash), -1, [], 2000, () => {})
assert.equal(result.length, count)
})
})
})

0 comments on commit d2c8c80

Please sign in to comment.