@psf/bch-js 5.3.2 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.on-save.json +8 -0
- package/LICENSE.md +1 -2
- package/package.json +8 -10
- package/src/bch-js.js +0 -2
- package/src/psf-slp-indexer.js +9 -9
- package/src/slp/utils.js +0 -1241
- package/src/utxo.js +0 -270
- package/test/integration/chains/bchn/utxo-integration.js +9 -124
- package/test/integration/slp.js +0 -470
- package/test/unit/slp-utils.js +0 -724
- package/test/unit/utxo-unit.js +0 -131
- package/src/ipfs.js +0 -454
- package/test/integration/chains/abc/slp.js +0 -226
- package/test/integration/chains/bchn-no-wl-slpdb/rawtransaction.js +0 -71
- package/test/integration/chains/bchn-no-wl-slpdb/slp.js +0 -273
- package/test/integration/chains/bchn-no-wl-slpdb/utxo-integration.js +0 -105
- package/test/unit/ipfs.js +0 -443
package/test/unit/ipfs.js
DELETED
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Unit tests for the IPFS Class.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const assert = require('chai').assert
|
|
6
|
-
const sinon = require('sinon')
|
|
7
|
-
const BCHJS = require('../../src/bch-js')
|
|
8
|
-
let bchjs
|
|
9
|
-
|
|
10
|
-
const mockData = require('./fixtures/ipfs-mock')
|
|
11
|
-
|
|
12
|
-
describe('#IPFS', () => {
|
|
13
|
-
let sandbox
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
sandbox = sinon.createSandbox()
|
|
17
|
-
|
|
18
|
-
bchjs = new BCHJS()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
afterEach(() => sandbox.restore())
|
|
22
|
-
|
|
23
|
-
describe('#initUppy', () => {
|
|
24
|
-
it('should initialize uppy', () => {
|
|
25
|
-
bchjs.IPFS.initUppy()
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('#createFileModelServer', () => {
|
|
30
|
-
it('should throw an error if file does not exist', async () => {
|
|
31
|
-
try {
|
|
32
|
-
const path = '/non-existant-file'
|
|
33
|
-
|
|
34
|
-
await bchjs.IPFS.createFileModelServer(path)
|
|
35
|
-
|
|
36
|
-
assert.equal(true, false, 'Unexpected result')
|
|
37
|
-
} catch (err) {
|
|
38
|
-
// console.log(`err.message: ${err.message}`)
|
|
39
|
-
assert.include(err.message, 'Could not find this file')
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('should create a new file model', async () => {
|
|
44
|
-
const path = `${__dirname.toString()}/ipfs.js`
|
|
45
|
-
|
|
46
|
-
sandbox
|
|
47
|
-
.stub(bchjs.IPFS.axios, 'post')
|
|
48
|
-
.resolves({ data: mockData.mockNewFileModel })
|
|
49
|
-
|
|
50
|
-
const result = await bchjs.IPFS.createFileModelServer(path)
|
|
51
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
52
|
-
|
|
53
|
-
assert.property(result, 'success')
|
|
54
|
-
assert.equal(result.success, true)
|
|
55
|
-
|
|
56
|
-
assert.property(result, 'hostingCostBCH')
|
|
57
|
-
assert.property(result, 'hostingCostUSD')
|
|
58
|
-
assert.property(result, 'file')
|
|
59
|
-
|
|
60
|
-
assert.property(result.file, 'payloadLink')
|
|
61
|
-
assert.property(result.file, 'hasBeenPaid')
|
|
62
|
-
assert.property(result.file, '_id')
|
|
63
|
-
assert.property(result.file, 'schemaVersion')
|
|
64
|
-
assert.property(result.file, 'size')
|
|
65
|
-
assert.property(result.file, 'fileName')
|
|
66
|
-
assert.property(result.file, 'fileExtension')
|
|
67
|
-
assert.property(result.file, 'createdTimestamp')
|
|
68
|
-
assert.property(result.file, 'hostingCost')
|
|
69
|
-
assert.property(result.file, 'walletIndex')
|
|
70
|
-
assert.property(result.file, 'bchAddr')
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('#uploadFileServer', () => {
|
|
75
|
-
it('should throw an error if file does not exist', async () => {
|
|
76
|
-
try {
|
|
77
|
-
const path = '/non-existant-file'
|
|
78
|
-
|
|
79
|
-
await bchjs.IPFS.uploadFileServer(path)
|
|
80
|
-
|
|
81
|
-
assert.equal(true, false, 'Unexpected result')
|
|
82
|
-
} catch (err) {
|
|
83
|
-
// console.log(`err.message: ${err.message}`)
|
|
84
|
-
assert.include(err.message, 'Could not find this file')
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('should throw an error if modelId is not included', async () => {
|
|
89
|
-
try {
|
|
90
|
-
const path = `${__dirname.toString()}/ipfs.js`
|
|
91
|
-
|
|
92
|
-
await bchjs.IPFS.uploadFileServer(path)
|
|
93
|
-
|
|
94
|
-
assert.equal(true, false, 'Unexpected result')
|
|
95
|
-
} catch (err) {
|
|
96
|
-
// console.log(`err.message: ${err.message}`)
|
|
97
|
-
assert.include(err.message, 'Must include a file model ID')
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('Should throw error if the file was not uploaded', async () => {
|
|
102
|
-
try {
|
|
103
|
-
const mock = {
|
|
104
|
-
successful: [],
|
|
105
|
-
failed: [
|
|
106
|
-
{
|
|
107
|
-
id: 'file id'
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mock)
|
|
112
|
-
|
|
113
|
-
const path = `${__dirname.toString()}/ipfs.js`
|
|
114
|
-
await bchjs.IPFS.uploadFileServer(path, '5ec562319bfacc745e8d8a52')
|
|
115
|
-
|
|
116
|
-
assert.equal(true, false, 'Unexpected result')
|
|
117
|
-
} catch (err) {
|
|
118
|
-
// console.log(err)
|
|
119
|
-
assert.include(err.message, 'The file could not be uploaded')
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('should return file object if the file is uploaded', async () => {
|
|
124
|
-
try {
|
|
125
|
-
sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mockData.uploadData)
|
|
126
|
-
|
|
127
|
-
const path = `${__dirname.toString()}/ipfs.js`
|
|
128
|
-
const result = await bchjs.IPFS.uploadFileServer(
|
|
129
|
-
path,
|
|
130
|
-
'5ec562319bfacc745e8d8a52'
|
|
131
|
-
)
|
|
132
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
133
|
-
|
|
134
|
-
assert.property(result, 'schemaVersion')
|
|
135
|
-
assert.property(result, 'size')
|
|
136
|
-
assert.property(result, 'fileId')
|
|
137
|
-
assert.property(result, 'fileName')
|
|
138
|
-
assert.property(result, 'fileExtension')
|
|
139
|
-
} catch (err) {
|
|
140
|
-
// console.log(err)
|
|
141
|
-
assert.equal(true, false, 'Unexpected result')
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
describe('#getStatus', () => {
|
|
147
|
-
it('should throw an error if modelId is not included', async () => {
|
|
148
|
-
try {
|
|
149
|
-
await bchjs.IPFS.getStatus()
|
|
150
|
-
|
|
151
|
-
assert.equal(true, false, 'Unexpected result')
|
|
152
|
-
} catch (err) {
|
|
153
|
-
// console.log(`err.message: ${err.message}`)
|
|
154
|
-
assert.include(err.message, 'Must include a file model ID')
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
it('should get data on an unpaid file', async () => {
|
|
159
|
-
const modelId = '5ec7392c2acfe57aa62e945a'
|
|
160
|
-
|
|
161
|
-
sandbox
|
|
162
|
-
.stub(bchjs.IPFS.axios, 'get')
|
|
163
|
-
.resolves({ data: mockData.unpaidFileData })
|
|
164
|
-
|
|
165
|
-
const result = await bchjs.IPFS.getStatus(modelId)
|
|
166
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
167
|
-
|
|
168
|
-
assert.property(result, 'hasBeenPaid')
|
|
169
|
-
assert.property(result, 'satCost')
|
|
170
|
-
assert.property(result, 'bchAddr')
|
|
171
|
-
assert.property(result, 'ipfsHash')
|
|
172
|
-
assert.property(result, 'fileId')
|
|
173
|
-
assert.property(result, 'fileName')
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
it('should get data on an unpaid file', async () => {
|
|
177
|
-
const modelId = '5ec7392c2acfe57aa62e945a'
|
|
178
|
-
|
|
179
|
-
sandbox
|
|
180
|
-
.stub(bchjs.IPFS.axios, 'get')
|
|
181
|
-
.resolves({ data: mockData.paidFileData })
|
|
182
|
-
|
|
183
|
-
const result = await bchjs.IPFS.getStatus(modelId)
|
|
184
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
185
|
-
|
|
186
|
-
assert.property(result, 'hasBeenPaid')
|
|
187
|
-
assert.property(result, 'satCost')
|
|
188
|
-
assert.property(result, 'bchAddr')
|
|
189
|
-
assert.property(result, 'ipfsHash')
|
|
190
|
-
assert.property(result, 'fileId')
|
|
191
|
-
assert.property(result, 'fileName')
|
|
192
|
-
})
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
describe('#createFileModelWeb', () => {
|
|
196
|
-
it('should throw an error if file is undefined', async () => {
|
|
197
|
-
try {
|
|
198
|
-
let file
|
|
199
|
-
|
|
200
|
-
await bchjs.IPFS.createFileModelWeb(file)
|
|
201
|
-
|
|
202
|
-
assert.equal(true, false, 'Unexpected result')
|
|
203
|
-
} catch (err) {
|
|
204
|
-
// console.log(`err.message: ${err.message}`)
|
|
205
|
-
assert.include(err.message, 'File is required')
|
|
206
|
-
}
|
|
207
|
-
})
|
|
208
|
-
it('should throw an error if file is empty', async () => {
|
|
209
|
-
try {
|
|
210
|
-
const file = {}
|
|
211
|
-
|
|
212
|
-
await bchjs.IPFS.createFileModelWeb(file)
|
|
213
|
-
|
|
214
|
-
assert.equal(true, false, 'Unexpected result')
|
|
215
|
-
} catch (err) {
|
|
216
|
-
// console.log(`err.message: ${err.message}`)
|
|
217
|
-
assert.include(
|
|
218
|
-
err.message,
|
|
219
|
-
'File should have the property \'name\' of string type'
|
|
220
|
-
)
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
it("should throw an error if 'name' property is not included", async () => {
|
|
224
|
-
try {
|
|
225
|
-
const file = {
|
|
226
|
-
size: 5000
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
await bchjs.IPFS.createFileModelWeb(file)
|
|
230
|
-
|
|
231
|
-
assert.equal(true, false, 'Unexpected result')
|
|
232
|
-
} catch (err) {
|
|
233
|
-
// console.log(`err.message: ${err.message}`)
|
|
234
|
-
assert.include(
|
|
235
|
-
err.message,
|
|
236
|
-
'File should have the property \'name\' of string type'
|
|
237
|
-
)
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
it("should throw an error if 'size' property is not included", async () => {
|
|
242
|
-
try {
|
|
243
|
-
const file = {
|
|
244
|
-
name: 'ipfs.js'
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
await bchjs.IPFS.createFileModelWeb(file)
|
|
248
|
-
|
|
249
|
-
assert.equal(true, false, 'Unexpected result')
|
|
250
|
-
} catch (err) {
|
|
251
|
-
// console.log(`err.message: ${err.message}`)
|
|
252
|
-
assert.include(
|
|
253
|
-
err.message,
|
|
254
|
-
'File should have the property \'size\' of number type'
|
|
255
|
-
)
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
it('should create a new file model', async () => {
|
|
260
|
-
const file = {
|
|
261
|
-
name: 'ipfs.js',
|
|
262
|
-
size: 5000,
|
|
263
|
-
type: 'text/plain'
|
|
264
|
-
}
|
|
265
|
-
sandbox
|
|
266
|
-
.stub(bchjs.IPFS.axios, 'post')
|
|
267
|
-
.resolves({ data: mockData.mockNewFileModel })
|
|
268
|
-
|
|
269
|
-
const result = await bchjs.IPFS.createFileModelWeb(file)
|
|
270
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
271
|
-
|
|
272
|
-
assert.property(result, 'success')
|
|
273
|
-
assert.equal(result.success, true)
|
|
274
|
-
|
|
275
|
-
assert.property(result, 'hostingCostBCH')
|
|
276
|
-
assert.property(result, 'hostingCostUSD')
|
|
277
|
-
assert.property(result, 'file')
|
|
278
|
-
|
|
279
|
-
assert.property(result.file, 'payloadLink')
|
|
280
|
-
assert.property(result.file, 'hasBeenPaid')
|
|
281
|
-
assert.property(result.file, '_id')
|
|
282
|
-
assert.property(result.file, 'schemaVersion')
|
|
283
|
-
assert.property(result.file, 'size')
|
|
284
|
-
assert.property(result.file, 'fileName')
|
|
285
|
-
assert.property(result.file, 'fileExtension')
|
|
286
|
-
assert.property(result.file, 'createdTimestamp')
|
|
287
|
-
assert.property(result.file, 'hostingCost')
|
|
288
|
-
assert.property(result.file, 'walletIndex')
|
|
289
|
-
assert.property(result.file, 'bchAddr')
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
describe('#uploadFileWeb', () => {
|
|
294
|
-
it('should throw an error if file is undefined', async () => {
|
|
295
|
-
try {
|
|
296
|
-
let file
|
|
297
|
-
|
|
298
|
-
await bchjs.IPFS.uploadFileWeb(file)
|
|
299
|
-
|
|
300
|
-
assert.equal(true, false, 'Unexpected result')
|
|
301
|
-
} catch (err) {
|
|
302
|
-
// console.log(`err.message: ${err.message}`)
|
|
303
|
-
assert.include(err.message, 'File is required')
|
|
304
|
-
}
|
|
305
|
-
})
|
|
306
|
-
it('should throw an error if file is empty', async () => {
|
|
307
|
-
try {
|
|
308
|
-
const file = {}
|
|
309
|
-
|
|
310
|
-
await bchjs.IPFS.uploadFileWeb(file)
|
|
311
|
-
|
|
312
|
-
assert.equal(true, false, 'Unexpected result')
|
|
313
|
-
} catch (err) {
|
|
314
|
-
// console.log(`err.message: ${err.message}`)
|
|
315
|
-
assert.include(
|
|
316
|
-
err.message,
|
|
317
|
-
'File should have the property \'name\' of string type'
|
|
318
|
-
)
|
|
319
|
-
}
|
|
320
|
-
})
|
|
321
|
-
it("should throw an error if 'name' property is not included", async () => {
|
|
322
|
-
try {
|
|
323
|
-
const file = {
|
|
324
|
-
size: 5000,
|
|
325
|
-
type: 'text/plain'
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
await bchjs.IPFS.uploadFileWeb(file)
|
|
329
|
-
|
|
330
|
-
assert.equal(true, false, 'Unexpected result')
|
|
331
|
-
} catch (err) {
|
|
332
|
-
// console.log(`err.message: ${err.message}`)
|
|
333
|
-
assert.include(
|
|
334
|
-
err.message,
|
|
335
|
-
'File should have the property \'name\' of string type'
|
|
336
|
-
)
|
|
337
|
-
}
|
|
338
|
-
})
|
|
339
|
-
it("should throw an error if 'size' property is not included", async () => {
|
|
340
|
-
try {
|
|
341
|
-
const file = {
|
|
342
|
-
name: 'ipfs.js',
|
|
343
|
-
type: 'text/plain'
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
await bchjs.IPFS.uploadFileWeb(file)
|
|
347
|
-
|
|
348
|
-
assert.equal(true, false, 'Unexpected result')
|
|
349
|
-
} catch (err) {
|
|
350
|
-
// console.log(`err.message: ${err.message}`)
|
|
351
|
-
assert.include(
|
|
352
|
-
err.message,
|
|
353
|
-
'File should have the property \'size\' of number type'
|
|
354
|
-
)
|
|
355
|
-
}
|
|
356
|
-
})
|
|
357
|
-
it("should throw an error if 'type' property is not included", async () => {
|
|
358
|
-
try {
|
|
359
|
-
const file = {
|
|
360
|
-
name: 'ipfs.js',
|
|
361
|
-
size: 5000
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
await bchjs.IPFS.uploadFileWeb(file)
|
|
365
|
-
|
|
366
|
-
assert.equal(true, false, 'Unexpected result')
|
|
367
|
-
} catch (err) {
|
|
368
|
-
// console.log(`err.message: ${err.message}`)
|
|
369
|
-
assert.include(
|
|
370
|
-
err.message,
|
|
371
|
-
'File should have the property \'type\' of string type'
|
|
372
|
-
)
|
|
373
|
-
}
|
|
374
|
-
})
|
|
375
|
-
it('should throw an error if modelId is not included', async () => {
|
|
376
|
-
try {
|
|
377
|
-
const file = {
|
|
378
|
-
name: 'ipfs.js',
|
|
379
|
-
size: 5000,
|
|
380
|
-
type: 'text/plain'
|
|
381
|
-
}
|
|
382
|
-
await bchjs.IPFS.uploadFileWeb(file)
|
|
383
|
-
|
|
384
|
-
assert.equal(true, false, 'Unexpected result')
|
|
385
|
-
} catch (err) {
|
|
386
|
-
// console.log(`err.message: ${err.message}`)
|
|
387
|
-
assert.include(err.message, 'Must include a file model ID')
|
|
388
|
-
}
|
|
389
|
-
})
|
|
390
|
-
|
|
391
|
-
it('Should throw error if the file was not uploaded', async () => {
|
|
392
|
-
try {
|
|
393
|
-
const mock = {
|
|
394
|
-
successful: [],
|
|
395
|
-
failed: [
|
|
396
|
-
{
|
|
397
|
-
id: 'file id'
|
|
398
|
-
}
|
|
399
|
-
]
|
|
400
|
-
}
|
|
401
|
-
sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mock)
|
|
402
|
-
|
|
403
|
-
const file = {
|
|
404
|
-
name: 'ipfs.js',
|
|
405
|
-
size: 5000,
|
|
406
|
-
type: 'text/plain'
|
|
407
|
-
}
|
|
408
|
-
await bchjs.IPFS.uploadFileWeb(file, '5ec562319bfacc745e8d8a52')
|
|
409
|
-
|
|
410
|
-
assert.equal(true, false, 'Unexpected result')
|
|
411
|
-
} catch (err) {
|
|
412
|
-
// console.log(err)
|
|
413
|
-
assert.include(err.message, 'The file could not be uploaded')
|
|
414
|
-
}
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
it('should return file object if the file is uploaded', async () => {
|
|
418
|
-
try {
|
|
419
|
-
sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mockData.uploadData)
|
|
420
|
-
|
|
421
|
-
const file = {
|
|
422
|
-
name: 'ipfs.js',
|
|
423
|
-
size: 5000,
|
|
424
|
-
type: 'text/plain'
|
|
425
|
-
}
|
|
426
|
-
const result = await bchjs.IPFS.uploadFileWeb(
|
|
427
|
-
file,
|
|
428
|
-
'5ec562319bfacc745e8d8a52'
|
|
429
|
-
)
|
|
430
|
-
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
|
|
431
|
-
|
|
432
|
-
assert.property(result, 'schemaVersion')
|
|
433
|
-
assert.property(result, 'size')
|
|
434
|
-
assert.property(result, 'fileId')
|
|
435
|
-
assert.property(result, 'fileName')
|
|
436
|
-
assert.property(result, 'fileExtension')
|
|
437
|
-
} catch (err) {
|
|
438
|
-
// console.log(err)
|
|
439
|
-
assert.equal(true, false, 'Unexpected result')
|
|
440
|
-
}
|
|
441
|
-
})
|
|
442
|
-
})
|
|
443
|
-
})
|