From c7d743f589891459bfe26e8e1d7d843da5be28b7 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Wed, 13 Sep 2023 17:37:40 +0300 Subject: [PATCH] test that feed holes are also cleaned up --- test/feed-holes.test.js | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/feed-holes.test.js diff --git a/test/feed-holes.test.js b/test/feed-holes.test.js new file mode 100644 index 0000000..50cd3d4 --- /dev/null +++ b/test/feed-holes.test.js @@ -0,0 +1,66 @@ +const test = require('node:test') +const assert = require('node:assert') +const p = require('node:util').promisify +const { createPeer } = require('./util') + +function getTexts(msgs) { + return msgs.filter((msg) => msg.data?.text).map((msg) => msg.data.text) +} + +test('feed holes', async (t) => { + const alice = createPeer({ + name: 'alice', + gc: { maxLogBytes: 100 * 1024 * 1024 }, + }) + + await alice.db.loaded() + + // Alice creates her own account + const aliceID = await p(alice.db.account.create)({ + domain: 'account', + _nonce: 'alice', + }) + + const posts = [] + for (let i = 0; i < 10; i++) { + const rec = await p(alice.db.feed.publish)({ + account: aliceID, + domain: 'post', + data: { text: 'A' + i }, + }) + posts.push(rec.id) + } + + assert.deepEqual( + getTexts([...alice.db.msgs()]), + ['A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9'], + 'alice has the whole feed' + ) + + await p(alice.db.del)(posts[3]) + await p(alice.db.del)(posts[4]) + await p(alice.db.del)(posts[5]) + await p(alice.db.del)(posts[6]) + assert('alice deleted the middle part of the feed') + + assert.deepEqual( + getTexts([...alice.db.msgs()]), + ['A0', 'A1', 'A2', 'A7', 'A8', 'A9'], + 'alice has the beginning and the end of the feed' + ) + + alice.goals.set(aliceID, 'all') // alice wants her account tangle + const postFeedID = alice.db.feed.getID(aliceID, 'post') + alice.goals.set(postFeedID, 'newest-3') + assert('alice set a goal for newest-3 of post feed') + + await p(alice.gc.forceImmediately)() + + assert.deepEqual( + getTexts([...alice.db.msgs()]), + ['A7', 'A8', 'A9'], + 'alice has only the end of the feed' + ) + + await p(alice.close)(true) +})