Skip to content

Instantly share code, notes, and snippets.

@ptoner
Created October 2, 2019 00:35
Show Gist options
  • Save ptoner/b9bf6f0e2c1bfb672fd035b8c15cf520 to your computer and use it in GitHub Desktop.
Save ptoner/b9bf6f0e2c1bfb672fd035b8c15cf520 to your computer and use it in GitHub Desktop.
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, 6) // 6 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()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment