This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict' | ||
|
||
/* eslint-env mocha */ | ||
const { encodeCID } = require('ipfs-message-port-protocol/src/cid') | ||
const { expect } = require('aegir/utils/chai') | ||
|
||
const CID = require('cids') | ||
const { Query, 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 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 | ||
) | ||
}) | ||
}) | ||
}) |