forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransfer.spec.js
46 lines (38 loc) · 1.28 KB
/
transfer.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict'
/* eslint-env mocha */
const { encodeCID } = require('ipfs-message-port-protocol/src/cid')
const globalThis = require('ipfs-utils/src/globalthis')
const CID = require('cids')
const { Server } = require('../src/server')
const { IPFSService } = require('../src/index')
describe('Server', function () {
this.timeout(10 * 1000)
it('should be able to transfer multiple of the same CID instances', () => {
const cid = new CID('QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D')
return new Promise((resolve, reject) => {
const channel = process.browser
? new globalThis.MessageChannel()
: new (require('worker_threads').MessageChannel)()
channel.port1.onmessageerror = reject
channel.port1.onmessage = event => {
const result = event.data.result
result.ok ? resolve(result.value) : reject(new Error(result.error.message))
}
const service = new IPFSService()
const server = new Server(service)
const transfer = []
server.run = a => a
server.handleQuery(
'',
{
result: {
value: [encodeCID(cid, transfer), encodeCID(cid, transfer)],
transfer: transfer
},
signal: { aborted: false }
},
channel.port2
)
})
})
})