Last active
September 30, 2019 04:22
-
-
Save ptoner/bd6340adab01add1740194109311b16d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require('assert') | |
const OrbitDB = require('orbit-db') | |
const IPFS = require('ipfs') | |
describe('Orbit', function() { | |
it('should post without needing to call load on the store', 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 100 records | |
for (var i=0; i < 100; 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() | |
assert.equal(Object.keys(store._index._index).length, 100) | |
//Close store | |
await store.close() | |
//Reopen and don't load | |
store = await orbitdb.open(address) | |
//await store.load(1) //uncommenting this line makes the test pass. loading even 1 record seems to keep them | |
//Add another one | |
await store.add({ | |
content: 101 | |
}) | |
//Close store | |
await store.close() | |
//Reopen and load full to verify we have all of them | |
store = await orbitdb.open(address) | |
await store.load() | |
assert.equal(Object.keys(store._index._index).length, 101) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment