Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. var assert = require('assert')
  2. const OrbitDB = require('orbit-db')
  3. const IPFS = require('ipfs')
  4.  
  5.  
  6. describe('Orbit', function() {
  7.  
  8. it('weird behavior', async function() {
  9.  
  10. const ipfs = await IPFS.create({
  11. EXPERIMENTAL: {
  12. pubsub:true
  13. }
  14. })
  15.  
  16. const orbitdb = await OrbitDB.createInstance(ipfs, {
  17. directory: "./orbitdb"
  18. })
  19.  
  20. let store = await orbitdb.open("test-store", {
  21. type: 'feed',
  22. create: true
  23. })
  24.  
  25. //Add 10 records
  26. for (var i=0; i < 10; i++) {
  27. await store.add({
  28. content: (i + 10).toString()
  29. })
  30. }
  31.  
  32. //Close store
  33. let address = store.address.toString()
  34. await store.close()
  35.  
  36.  
  37.  
  38. /**
  39. * Reopen and load full to verify we have all of them
  40. */
  41. store = await orbitdb.open(address)
  42. await store.load(10)
  43.  
  44. assert.equal(Object.keys(store._index._index).length, 10) //all 10 are there. cool.
  45.  
  46. //Close store
  47. await store.close()
  48.  
  49.  
  50.  
  51.  
  52. /**
  53. * Load 1 more than is in there. Only 1 record will be loaded.
  54. */
  55. store = await orbitdb.open(address)
  56. await store.load(11)
  57.  
  58. assert.equal(Object.keys(store._index._index).length, 1) // only 1 is in there. huh?
  59.  
  60. await store.close()
  61.  
  62.  
  63.  
  64. /**
  65. * Load 5 more than is in there. Only 5 will be loaded.
  66. */
  67. store = await orbitdb.open(address)
  68. await store.load(15)
  69.  
  70. assert.equal(Object.keys(store._index._index).length, 5) // only 5 are in there now. hmm.
  71.  
  72. await store.close()
  73.  
  74.  
  75.  
  76.  
  77. /**
  78. * Load 20 more than is in there. All 10 are back.
  79. */
  80. store = await orbitdb.open(address)
  81. await store.load(30)
  82.  
  83. assert.equal(Object.keys(store._index._index).length, 10) // Now all ten are there again.
  84.  
  85. await store.close()
  86.  
  87.  
  88.  
  89. })
  90.  
  91.  
  92. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement