Skip to content

Commit a963ad2

Browse files
committed
Basic test
1 parent 2a8dbd2 commit a963ad2

File tree

2 files changed

+14
-52
lines changed

2 files changed

+14
-52
lines changed

test/basic.js

+13
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,16 @@ test('append above the max suggested block size', async function (t) {
428428
t.pass('should throw')
429429
}
430430
})
431+
432+
test('get undefined block is not allowed', async function (t) {
433+
t.plan(1)
434+
435+
const core = new Hypercore(RAM)
436+
437+
try {
438+
await core.get(undefined)
439+
t.fail()
440+
} catch (err) {
441+
t.pass(err.code, 'ERR_ASSERTION')
442+
}
443+
})

test/replicate.js

+1-52
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const test = require('brittle')
22
const b4a = require('b4a')
33
const RAM = require('random-access-memory')
44
const NoiseSecretStream = require('@hyperswarm/secret-stream')
5-
const { create, replicate, unreplicate, eventFlush, createStored } = require('./helpers')
5+
const { create, replicate, unreplicate, eventFlush } = require('./helpers')
66
const { makeStreamPair } = require('./helpers/networking.js')
77
const Hypercore = require('../')
88

@@ -1486,57 +1486,6 @@ test('replication updates on core copy', async function (t) {
14861486
await t.execution(promise)
14871487
})
14881488

1489-
test('get undefined block should not fail', async function (t) {
1490-
const a = await create()
1491-
const b = await create(a.key)
1492-
1493-
await a.append('Hello') // Strictly one value is required for this
1494-
1495-
replicate(a, b, t)
1496-
1497-
t.alike(await b.get(0), b4a.from('Hello'))
1498-
1499-
try {
1500-
await b.get(undefined)
1501-
} catch (err) {
1502-
console.error(err) // Error: Could not satisfy length (EPARTIALREAD when using RAF)
1503-
t.fail()
1504-
}
1505-
})
1506-
1507-
test.skip('get undefined block should not allow corruption on the writer', async function (t) {
1508-
const createWriter = createStored()
1509-
1510-
const a = createWriter()
1511-
await a.append(['Hello', 'World']) // Strictly two values is required for this
1512-
1513-
const b = await create(a.key)
1514-
1515-
replicate(a, b, t)
1516-
1517-
await b.update({ wait: true })
1518-
1519-
t.alike(await b.get(0), b4a.from('Hello'))
1520-
1521-
await b.get(undefined) // This triggers 100% CPU usage
1522-
1523-
// TODO: Check that writer can still write two values without corrupting itself? (unfinished due the glitch above)
1524-
/* await a.close()
1525-
await b.close()
1526-
1527-
const core = createWriter()
1528-
await core.append(['Hello', 'World']) // Strictly two values is required for this
1529-
1530-
const clone = await create(core.key)
1531-
1532-
replicate(core, clone, t)
1533-
1534-
await clone.update({ wait: true })
1535-
1536-
t.alike(await b.get(0), b4a.from('Hello'))
1537-
await b.get(undefined) // TODO: Over here triggers "Error: Could not load node: X" */
1538-
})
1539-
15401489
async function waitForRequestBlock (core) {
15411490
while (true) {
15421491
const reqBlock = core.replicator._inflight._requests.find(req => req && req.block)

0 commit comments

Comments
 (0)