Skip to content

Commit

Permalink
add replication test
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jan 6, 2025
1 parent c019139 commit 2895170
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"brittle": "^3.7.0",
"corestore": "^6.18.4",
"hyperblobs": "^2.7.4",
"hyperdht": "^6.20.1",
"hyperdrive": "^11.13.3",
"hyperswarm": "^4.8.4",
"standard": "^17.1.2"
},
"repository": {
Expand Down
43 changes: 43 additions & 0 deletions test/drives.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const test = require('brittle')
const b4a = require('b4a')
const tmp = require('test-tmp')
const Corestore = require('corestore')
const testnet = require('hyperdht/testnet')
const Hyperswarm = require('hyperswarm')
const { testHyperdrive, testBlobServer, request, get } = require('./helpers')

test('can get file from hyperdrive', async function (t) {
Expand Down Expand Up @@ -117,6 +119,47 @@ test('can get encrypted blob from hyperdrive', async function (t) {
const res = await request(server, drive.key, { filename: '/file.txt' })
t.is(res.status, 200)
t.is(res.data, 'Here')

await drive.close()
})

test('can get encrypted blob from hyperdrive while replicating', async function (t) {
const store = new Corestore(await tmp())
const store2 = new Corestore(await tmp())
const { bootstrap } = await testnet(10, t)

const swarm1 = new Hyperswarm({ bootstrap })
const swarm2 = new Hyperswarm({ bootstrap })
const encryptionKey = b4a.alloc(32)

const drive = testHyperdrive(t, store, { encryptionKey })
await drive.put('/file.txt', 'Here')

swarm1.on('connection', c => {
store.replicate(c)
})

swarm2.on('connection', c => {
store2.replicate(c)
})

await swarm1.join(drive.discoveryKey).flushed()
await swarm2.join(drive.discoveryKey).flushed()

const server = testBlobServer(t, store2, {
resolve: function (key) {
return { key, encryptionKey }
}
})
await server.listen()

const res = await request(server, drive.key, { filename: '/file.txt', version: drive.version })
t.is(res.status, 200)
t.is(res.data, 'Here')

await swarm1.destroy()
await swarm2.destroy()
await drive.close()
})

test('can select a file for full download', async function (t) {
Expand Down

0 comments on commit 2895170

Please sign in to comment.