-
Notifications
You must be signed in to change notification settings - Fork 0
/
files-mfs.test.js
37 lines (31 loc) · 1.51 KB
/
files-mfs.test.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
const ipfsCrypto = require('../')
const ipfsc = ipfsCrypto({ host: 'localhost', port: '5001', protocol: 'http' })
const cryptoOpts = ipfsc.generateBrainWallet("seed for entropy")
const sampleData = "this is some random data"
const FOLDER_NAME = "/myFolder", FILE_NAME = "/myFile.txt"
const assert = require('chai').assert
describe('files-mfs', () => {
describe('symmetric encryption & decryption' , () => {
it('creates a directory', () => {
ipfsc.files.mkdir(FOLDER_NAME, (err) => {
assert.equal(err, null, `throws error while creating a directory: ${err}`)
})
})
it('encrypts & writes data in a file', () => {
ipfsc.files.write(`${FOLDER_NAME}${FILE_NAME}`, sampleData, { create: true, crypto: cryptoOpts }, (err) => {
assert.equal(err, null, `throws error while encrypting & writing to a file: ${err}`)
})
})
it('reads & decrypts data from a file', () => {
ipfsc.files.read(`${FOLDER_NAME}${FILE_NAME}`, { crypto: cryptoOpts }, (err, buf) => {
assert.equal(err, null, `throws error while reading & decrypting from a file: ${err}`)
assert.equal(buf, sampleData, `error while decrypting`)
})
})
it('removes a directory', () => {
ipfsc.files.rm(`${FOLDER_NAME}`, { recursive: true }, (err) => {
assert.equal(err, null, `throws error while removing a directory: ${err}`)
})
})
})
})