Skip to content

Instantly share code, notes, and snippets.

@telamon
Last active November 19, 2019 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telamon/55a75fd81f4a8196c94248a806e2efd7 to your computer and use it in GitHub Desktop.
Save telamon/55a75fd81f4a8196c94248a806e2efd7 to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment