Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var assert = require('assert')
- const OrbitDB = require('orbit-db')
- const IPFS = require('ipfs')
- describe('Orbit', function() {
- it('weird behavior', async function() {
- const ipfs = await IPFS.create({
- EXPERIMENTAL: {
- pubsub:true
- }
- })
- const orbitdb = await OrbitDB.createInstance(ipfs, {
- directory: "./orbitdb"
- })
- let store = await orbitdb.open("test-store", {
- type: 'feed',
- create: true
- })
- //Add 10 records
- for (var i=0; i < 10; i++) {
- await store.add({
- content: (i + 10).toString()
- })
- }
- //Close store
- let address = store.address.toString()
- await store.close()
- /**
- * Reopen and load full to verify we have all of them
- */
- store = await orbitdb.open(address)
- await store.load(10)
- assert.equal(Object.keys(store._index._index).length, 10) //all 10 are there. cool.
- //Close store
- await store.close()
- /**
- * Load 1 more than is in there. Only 1 record will be loaded.
- */
- store = await orbitdb.open(address)
- await store.load(11)
- assert.equal(Object.keys(store._index._index).length, 1) // only 1 is in there. huh?
- await store.close()
- /**
- * Load 5 more than is in there. Only 5 will be loaded.
- */
- store = await orbitdb.open(address)
- await store.load(15)
- assert.equal(Object.keys(store._index._index).length, 5) // only 5 are in there now. hmm.
- await store.close()
- /**
- * Load 20 more than is in there. All 10 are back.
- */
- store = await orbitdb.open(address)
- await store.load(30)
- assert.equal(Object.keys(store._index._index).length, 10) // Now all ten are there again.
- await store.close()
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement