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
1 parent
050e84b
commit dc9d91e
Showing
51 changed files
with
588 additions
and
1,520 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
const { isWebWorker } = require('ipfs-utils/src/env') | ||
const CID = require('cids') | ||
const randomBytes = require('iso-random-stream/src/random') | ||
const Block = require('ipld-block') | ||
const concat = require('it-concat') | ||
const { nanoid } = require('nanoid') | ||
const uint8ArrayFromString = require('uint8arrays/from-string') | ||
const pmap = require('p-map') | ||
const multihashing = require('multihashing-async') | ||
|
||
const makeBlock = async () => { | ||
const d = uint8ArrayFromString(`IPFS is awesome ${nanoid()}`) | ||
const h = await multihashing(d, 'sha2-256') | ||
|
||
return new Block(d, new CID(h)) | ||
} | ||
|
||
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ | ||
/** | ||
* @param {Factory} factory | ||
* @param {Object} options | ||
*/ | ||
module.exports = (factory, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
|
||
describe('transfer blocks', function () { | ||
this.timeout(60 * 1000) | ||
|
||
afterEach(() => factory.clean()) | ||
|
||
describe('transfer a block between', () => { | ||
it('2 peers', async function () { | ||
// webworkers are not dialable because webrtc is not available | ||
const remote = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api | ||
const local = (await factory.spawn()).api | ||
await local.swarm.connect(remote.peerId.addresses[0]) | ||
const block = await makeBlock() | ||
|
||
await local.block.put(block) | ||
const b = await remote.block.get(block.cid) | ||
|
||
expect(b.data).to.eql(block.data) | ||
}) | ||
|
||
it('3 peers', async () => { | ||
const blocks = await Promise.all([...Array(6).keys()].map(() => makeBlock())) | ||
const remote1 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api | ||
const remote2 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api | ||
const local = (await factory.spawn()).api | ||
await local.swarm.connect(remote1.peerId.addresses[0]) | ||
await local.swarm.connect(remote2.peerId.addresses[0]) | ||
await remote1.swarm.connect(remote2.peerId.addresses[0]) | ||
|
||
await remote1.block.put(blocks[0]) | ||
await remote1.block.put(blocks[1]) | ||
await remote2.block.put(blocks[2]) | ||
await remote2.block.put(blocks[3]) | ||
await local.block.put(blocks[4]) | ||
await local.block.put(blocks[5]) | ||
|
||
await pmap(blocks, async (block) => { | ||
expect(await remote1.block.get(block.cid)).to.eql(block) | ||
expect(await remote2.block.get(block.cid)).to.eql(block) | ||
expect(await local.block.get(block.cid)).to.eql(block) | ||
}, { concurrency: 3 }) | ||
}) | ||
}) | ||
|
||
describe('transfer a file between', () => { | ||
it('2 peers', async () => { | ||
const content = randomBytes(1024 * 1024 * 10) | ||
const remote = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api | ||
const local = (await factory.spawn()).api | ||
local.swarm.connect(remote.peerId.addresses[0]) | ||
|
||
const file = await remote.add({ path: 'awesome.txt', content }) | ||
const data = await concat(local.cat(file.cid)) | ||
expect(data.slice()).to.eql(content) | ||
}) | ||
}) | ||
}) | ||
} |
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,31 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
|
||
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ | ||
/** | ||
* @param {Factory} factory | ||
* @param {Object} options | ||
*/ | ||
module.exports = (factory, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
|
||
describe('.bitswap.unwant', function () { | ||
this.timeout(60 * 1000) | ||
|
||
after(() => factory.clean()) | ||
|
||
it('should throw error for invalid CID input', async () => { | ||
const ipfs = (await factory.spawn()).api | ||
|
||
try { | ||
await ipfs.bitswap.unwant('INVALID CID') | ||
} catch (err) { | ||
expect(err).to.exist() | ||
expect(err.code).to.equal('ERR_INVALID_CID') | ||
} | ||
}) | ||
}) | ||
} |
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
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,41 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
const uint8ArrayFromString = require('uint8arrays/from-string') | ||
|
||
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */ | ||
/** | ||
* @param {Factory} factory | ||
* @param {Object} options | ||
*/ | ||
module.exports = (factory, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
|
||
describe('disabled', function () { | ||
this.timeout(80 * 1000) | ||
|
||
let ipfs | ||
|
||
before(async () => { | ||
ipfs = (await factory.spawn({ | ||
ipfsOptions: { | ||
config: { | ||
Routing: { | ||
Type: 'none' | ||
} | ||
} | ||
} | ||
})).api | ||
}) | ||
|
||
after(() => factory.clean()) | ||
|
||
it('should error when DHT not available', async () => { | ||
await expect(ipfs.dht.put(uint8ArrayFromString('a'), uint8ArrayFromString('b'))) | ||
.to.eventually.be.rejected() | ||
.and.to.have.property('code', 'ERR_NOT_ENABLED') | ||
}) | ||
}) | ||
} |
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
Oops, something went wrong.