Failing test:
test('encoding fault', t => {
t.plan(2)
const f1 = hypercore(ram)
const dummyExt = {
encoding: {
encode: () => t.ok('encoder was invoked'), // encoder is not invoked.
decode: () => t.ok('decode was invoked')
},
onerror: t.error
}
const inst1 = f1.registerExtension(dummyExt)
f1.ready(() => {
const f2 = hypercore(ram, f1.key)
f2.ready(() => {
const inst2 = f2.registerExtension(dummyExt)
// create replication stream
const stream = f1.replicate(true, { live: true })
stream.pipe(f2.replicate(false, { live: true })).pipe(stream)
// The following message is never sent due to
inst1.broadcast({ hello: 'world' })
t.end()
})
})
})
Test result:
tape test.js
TAP version 13
# encoding fault
buffer.js:324
throw new ERR_INVALID_OPT_VALUE.RangeError('size', size);
^
RangeError [ERR_INVALID_OPT_VALUE]: The value "NaN" is invalid for option "size"
at Function.allocUnsafe (buffer.js:346:3)
at SimpleProtocol.extension (/node_modules/simple-hypercore-protocol/index.js:119:24)
Inspection:
break in node_modules/simple-hypercore-protocol/index.js:119
117
118 extension (ch, id, message) {
>119 const buf = Buffer.allocUnsafe(varint.encodingLength(id) + message.length)
120
121 varint.encode(id, buf, 0)
debug> repl
Press Ctrl + C to leave debug repl
> message
{ hello: 'world' }
> message.length
undefined