From 26cadb1cf9aba4f0b4c2e7a1466e99090ab58b70 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Tue, 22 Oct 2024 13:06:39 +0100 Subject: [PATCH] fix: Reintroduce putting entry to entries to trigger pin on replica. --- src/oplog/log.js | 3 ++ test/orbitdb-replication-pins.test.js | 57 --------------------------- test/orbitdb-replication.test.js | 25 +++++++++++- 3 files changed, 27 insertions(+), 58 deletions(-) delete mode 100644 test/orbitdb-replication-pins.test.js diff --git a/src/oplog/log.js b/src/oplog/log.js index 4c5fff6..dd76c8c 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -312,6 +312,9 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora await _heads.remove(hash) } + /* 6. Add new entry to entries (for pinning) */ + await _entries.put(entry.hash, entry.bytes) + /* 6. Add the new entry to heads (=union with current heads) */ await _heads.add(entry) diff --git a/test/orbitdb-replication-pins.test.js b/test/orbitdb-replication-pins.test.js deleted file mode 100644 index e8a7cd0..0000000 --- a/test/orbitdb-replication-pins.test.js +++ /dev/null @@ -1,57 +0,0 @@ -import { strictEqual } from 'assert' -import { rimraf } from 'rimraf' -import { createOrbitDB } from '../src/index.js' -import connectPeers from './utils/connect-nodes.js' -import waitFor from './utils/wait-for.js' -import createHelia from './utils/create-helia.js' -import { CID } from 'multiformats/cid' -import { base58btc } from 'multiformats/bases/base58' - -describe.skip('Replicating databases', function () { - this.timeout(10000) - - let ipfs1, ipfs2 - let orbitdb1, orbitdb2 - - before(async () => { - ipfs1 = await createHelia({ directory: './ipfs1' }) - ipfs2 = await createHelia({ directory: './ipfs2' }) - await connectPeers(ipfs1, ipfs2) - - orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) - orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) - }) - - after(async () => { - await orbitdb1.stop() - await orbitdb2.stop() - await ipfs1.stop() - await ipfs2.stop() - - await rimraf('./orbitdb1') - await rimraf('./orbitdb2') - await rimraf('./ipfs1') - await rimraf('./ipfs2') - }) - - it('pins all entries in the replicated database', async () => { - const db1 = await orbitdb1.open('helloworld', { referencesCount: 0 }) - const hash = await db1.add('hello world') - - let replicated = false - - const onJoin = async (peerId, heads) => { - replicated = true - } - - const db2 = await orbitdb2.open(db1.address) - - db2.events.on('join', onJoin) - - await waitFor(() => replicated, () => true) - - const cid = CID.parse(hash, base58btc) - strictEqual(await ipfs1.pins.isPinned(cid), true) - strictEqual(await ipfs2.pins.isPinned(cid), false) - }) -}) diff --git a/test/orbitdb-replication.test.js b/test/orbitdb-replication.test.js index a2c3e74..916854a 100644 --- a/test/orbitdb-replication.test.js +++ b/test/orbitdb-replication.test.js @@ -1,9 +1,11 @@ -import { deepStrictEqual } from 'assert' +import { deepStrictEqual, strictEqual } from 'assert' import { rimraf } from 'rimraf' import { createOrbitDB } from '../src/index.js' import connectPeers from './utils/connect-nodes.js' import waitFor from './utils/wait-for.js' import createHelia from './utils/create-helia.js' +import { CID } from 'multiformats/cid' +import { base58btc } from 'multiformats/bases/base58' describe('Replicating databases', function () { this.timeout(10000) @@ -167,5 +169,26 @@ describe('Replicating databases', function () { console.log('events:', amount) }) + + it('pins all entries in the replicated database', async () => { + const db1 = await orbitdb1.open('helloworld', { referencesCount: 0 }) + const hash = await db1.add('hello world') + + let replicated = false + + const onJoin = async (peerId, heads) => { + replicated = true + } + + const db2 = await orbitdb2.open(db1.address) + + db2.events.on('join', onJoin) + + await waitFor(() => replicated, () => true) + + const cid = CID.parse(hash, base58btc) + strictEqual(await ipfs1.pins.isPinned(cid), true) + strictEqual(await ipfs2.pins.isPinned(cid), true) + }) }) })