Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('fetch()', t => {
t.plan(3)
const wire1 = new Protocol()
const wire2 = new Protocol()
wire1.pipe(wire2).pipe(wire1)
wire1.use(utMetadata(leavesMetadata.torrent)) // wire1 already has metadata
wire2.use(utMetadata()) // wire2 does not
wire2.ut_metadata.fetch()
wire2.ut_metadata.on('metadata', _metadata => {
// got metadata!
t.equal(
_metadata.toString('hex'),
bencode.encode({
info: bencode.decode(leavesMetadata.torrent).info
}).toString('hex')
)
})
wire2.on('handshake', (infoHash, peerId, extensions) => {
wire2.handshake(leavesMetadata.parsedTorrent.infoHash, id2)
wire2.ut_metadata.on('metadata', _metadata => {
// got metadata!
t.equal(
_metadata.toString('hex'),
bencode.encode({
info: bencode.decode(leavesMetadata.torrent).info
}).toString('hex')
)
})
test('wire.use(utMetadata(metadata))', t => {
const wire = new Protocol()
wire.pipe(wire)
wire.use(utMetadata(leavesMetadata.torrent))
t.ok(wire.ut_metadata)
t.ok(wire.ut_metadata.fetch)
t.ok(wire.ut_metadata.cancel)
t.equal(
wire.ut_metadata.metadata.toString('hex'),
bencode.encode(bencode.decode(leavesMetadata.torrent).info).toString('hex')
)
t.end()
})
test('wire.use(utMetadata(metadata))', t => {
const wire = new Protocol()
wire.pipe(wire)
wire.use(utMetadata(leavesMetadata.torrent))
t.ok(wire.ut_metadata)
t.ok(wire.ut_metadata.fetch)
t.ok(wire.ut_metadata.cancel)
t.equal(
wire.ut_metadata.metadata.toString('hex'),
bencode.encode(bencode.decode(leavesMetadata.torrent).info).toString('hex')
)
t.end()
})