mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service.git
synced 2026-09-21 16:52:03 -07:00
fix(tests): Back to 100% unit test coverage
This commit is contained in:
Generated
-1
@@ -27,7 +27,6 @@
|
|||||||
"glob": "7.1.6",
|
"glob": "7.1.6",
|
||||||
"helia": "2.1.0",
|
"helia": "2.1.0",
|
||||||
"helia-coord": "1.5.4",
|
"helia-coord": "1.5.4",
|
||||||
"ipfs-unixfs-exporter": "13.5.0",
|
|
||||||
"jsonrpc-lite": "2.2.0",
|
"jsonrpc-lite": "2.2.0",
|
||||||
"jsonwebtoken": "8.5.1",
|
"jsonwebtoken": "8.5.1",
|
||||||
"jwt-bch-lib": "1.3.0",
|
"jwt-bch-lib": "1.3.0",
|
||||||
|
|||||||
@@ -42,7 +42,6 @@
|
|||||||
"glob": "7.1.6",
|
"glob": "7.1.6",
|
||||||
"helia": "2.1.0",
|
"helia": "2.1.0",
|
||||||
"helia-coord": "1.5.4",
|
"helia-coord": "1.5.4",
|
||||||
"ipfs-unixfs-exporter": "13.5.0",
|
|
||||||
"jsonrpc-lite": "2.2.0",
|
"jsonrpc-lite": "2.2.0",
|
||||||
"jsonwebtoken": "8.5.1",
|
"jsonwebtoken": "8.5.1",
|
||||||
"jwt-bch-lib": "1.3.0",
|
"jwt-bch-lib": "1.3.0",
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Global npm libraries
|
// Global npm libraries
|
||||||
import { exporter } from 'ipfs-unixfs-exporter'
|
|
||||||
import fs from 'fs'
|
|
||||||
|
|
||||||
// Local libraries
|
// Local libraries
|
||||||
import wlogger from '../../../adapters/wlogger.js'
|
import wlogger from '../../../adapters/wlogger.js'
|
||||||
@@ -28,7 +26,6 @@ class IpfsRESTControllerLib {
|
|||||||
// Encapsulate dependencies
|
// Encapsulate dependencies
|
||||||
// this.UserModel = this.adapters.localdb.Users
|
// this.UserModel = this.adapters.localdb.Users
|
||||||
// this.userUseCases = this.useCases.user
|
// this.userUseCases = this.useCases.user
|
||||||
this.fs = fs
|
|
||||||
|
|
||||||
// Bind 'this' object to all subfunctions
|
// Bind 'this' object to all subfunctions
|
||||||
this.getStatus = this.getStatus.bind(this)
|
this.getStatus = this.getStatus.bind(this)
|
||||||
@@ -37,7 +34,6 @@ class IpfsRESTControllerLib {
|
|||||||
this.handleError = this.handleError.bind(this)
|
this.handleError = this.handleError.bind(this)
|
||||||
this.connect = this.connect.bind(this)
|
this.connect = this.connect.bind(this)
|
||||||
this.getThisNode = this.getThisNode.bind(this)
|
this.getThisNode = this.getThisNode.bind(this)
|
||||||
this.downloadFile = this.downloadFile.bind(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,77 +125,6 @@ class IpfsRESTControllerLib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadFile (ctx) {
|
|
||||||
try {
|
|
||||||
// const { cid } = ctx.params
|
|
||||||
|
|
||||||
// const multiaddr = ctx.request.body.multiaddr
|
|
||||||
// const getDetails = ctx.request.body.getDetails
|
|
||||||
const { cid, fileName, path } = ctx.request.body
|
|
||||||
|
|
||||||
console.log(`downloadFile() retrieving this CID: ${cid}, with fileName: ${fileName}, and path: ${path}`)
|
|
||||||
|
|
||||||
// const file = await this.adapters.ipfs.ipfs.blockstore.get(cid)
|
|
||||||
// console.log('file: ', file)
|
|
||||||
// return file
|
|
||||||
|
|
||||||
// const ipfsFs = this.adapters.ipfs.ipfs.fs
|
|
||||||
// console.log('ipfsFs: ', ipfsFs)
|
|
||||||
//
|
|
||||||
// const buf = []
|
|
||||||
// for await (const chunk of ipfsFs.cat(cid)) {
|
|
||||||
// // text += decoder.decode(chunk, {
|
|
||||||
// // stream: true
|
|
||||||
// // })
|
|
||||||
//
|
|
||||||
// buf.push(chunk)
|
|
||||||
// }
|
|
||||||
// console.log(`buf: `, buf)
|
|
||||||
|
|
||||||
const blockstore = this.adapters.ipfs.ipfs.blockstore
|
|
||||||
const entry = await exporter(cid, blockstore)
|
|
||||||
|
|
||||||
console.info(entry.cid) // Qmqux
|
|
||||||
console.info(entry.path) // Qmbaz/foo/bar.txt
|
|
||||||
console.info(entry.name) // bar.txt
|
|
||||||
console.log('entry: ', entry)
|
|
||||||
// console.info(entry.unixfs.fileSize()) // 4
|
|
||||||
|
|
||||||
// stream content from unixfs node
|
|
||||||
// const bytes = new Uint8Array(Number(entry.size))
|
|
||||||
// let offset = 0
|
|
||||||
|
|
||||||
const filePath = `${path}/${fileName}`
|
|
||||||
const writableStream = fs.createWriteStream(filePath)
|
|
||||||
|
|
||||||
writableStream.on('error', (error) => {
|
|
||||||
console.log(`An error occured while writing to the file. Error: ${error.message}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
writableStream.on('finish', () => {
|
|
||||||
console.log(`CID ${cid} downloaded to ${filePath}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
for await (const buf of entry.content()) {
|
|
||||||
// bytes.set(buf, offset)
|
|
||||||
// offset += buf.length
|
|
||||||
|
|
||||||
writableStream.write(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
writableStream.end()
|
|
||||||
|
|
||||||
// console.info(bytes) // 0, 1, 2, 3
|
|
||||||
|
|
||||||
ctx.body = {
|
|
||||||
success: true
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
wlogger.error('Error in ipfs/controller.js/downloadFile(): ', err)
|
|
||||||
this.handleError(ctx, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DRY error handler
|
// DRY error handler
|
||||||
handleError (ctx, err) {
|
handleError (ctx, err) {
|
||||||
// If an HTTP status is specified by the buisiness logic, use that.
|
// If an HTTP status is specified by the buisiness logic, use that.
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ class IpfsRouter {
|
|||||||
this.router.post('/relays', this.ipfsRESTController.getRelays)
|
this.router.post('/relays', this.ipfsRESTController.getRelays)
|
||||||
this.router.post('/connect', this.ipfsRESTController.connect)
|
this.router.post('/connect', this.ipfsRESTController.connect)
|
||||||
this.router.get('/node', this.ipfsRESTController.getThisNode)
|
this.router.get('/node', this.ipfsRESTController.getThisNode)
|
||||||
// this.router.get('/download/:cid', this.ipfsRESTController.downloadFile)
|
|
||||||
this.router.post('/download', this.ipfsRESTController.downloadFile)
|
|
||||||
|
|
||||||
// Attach the Controller routes to the Koa app.
|
// Attach the Controller routes to the Koa app.
|
||||||
app.use(this.router.routes())
|
app.use(this.router.routes())
|
||||||
|
|||||||
@@ -177,12 +177,12 @@ describe('#IPFS-adapter', () => {
|
|||||||
createKey: async () => {}
|
createKey: async () => {}
|
||||||
})
|
})
|
||||||
sandbox.stub(uut, 'createLibp2p').resolves()
|
sandbox.stub(uut, 'createLibp2p').resolves()
|
||||||
sandbox.stub(uut, 'createHelia').resolves(true)
|
sandbox.stub(uut, 'createHelia').resolves({})
|
||||||
|
|
||||||
const result = await uut.createNode()
|
const result = await uut.createNode()
|
||||||
// console.log('result: ', result)
|
// console.log('result: ', result)
|
||||||
|
|
||||||
assert.equal(result, true)
|
assert.property(result, 'fs')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not use circuit relay when CONNECT_PREF is set to direct', async () => {
|
it('should not use circuit relay when CONNECT_PREF is set to direct', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user