-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
82 lines (68 loc) · 3.07 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const DStorage = artifacts.require('./DStorage.sol')
require('chai')
.use(require('chai-as-promised'))
.should()
contract('DStorage', ([deployer, uploader]) => {
let dstorage
before(async () => {
dstorage = await DStorage.deployed()
})
describe('deployment', async () => {
it('deploys successfully', async () => {
const address = await dstorage.address
assert.notEqual(address, 0x0)
assert.notEqual(address, '')
assert.notEqual(address, null)
assert.notEqual(address, undefined)
})
it('has a name', async () => {
const name = await dstorage.name()
assert.equal(name, 'DStorage')
})
})
describe('file', async () => {
let result, fileCount
const fileHash = 'QmV8cfu6n4NT5xRr2AHdKxFMTZEJrA44qgrBCr739BN9Wb'
const fileSize = '1'
const fileType = 'TypeOfTheFile'
const fileName = 'NameOfTheFile'
const fileDescription = 'DescriptionOfTheFile'
before(async () => {
result = await dstorage.uploadFile(fileHash, fileSize, fileType, fileName, fileDescription, { from: uploader })
fileCount = await dstorage.fileCount()
})
//check event
it('upload file', async () => {
// SUCESS
assert.equal(fileCount, 1)
const event = result.logs[0].args
assert.equal(event.fileId.toNumber(), fileCount.toNumber(), 'Id is correct')
assert.equal(event.fileHash, fileHash, 'Hash is correct')
assert.equal(event.fileSize, fileSize, 'Size is correct')
assert.equal(event.fileType, fileType, 'Type is correct')
assert.equal(event.fileName, fileName, 'Name is correct')
assert.equal(event.fileDescription, fileDescription, 'Description is correct')
assert.equal(event.uploader, uploader, 'Uploader is correct')
// FAILURE: File must have hash
await dstorage.uploadFile('', fileSize, fileType, fileName, fileDescription, { from: uploader }).should.be.rejected;
// FAILURE: File must have size
await dstorage.uploadFile(fileHash, '', fileType, fileName, fileDescription, { from: uploader }).should.be.rejected;
// FAILURE: File must have type
await dstorage.uploadFile(fileHash, fileSize, '', fileName, fileDescription, { from: uploader }).should.be.rejected;
// FAILURE: File must have name
await dstorage.uploadFile(fileHash, fileSize, fileType, '', fileDescription, { from: uploader }).should.be.rejected;
// FAILURE: File must have description
await dstorage.uploadFile(fileHash, fileSize, fileType, fileName, '', { from: uploader }).should.be.rejected;
})
//check from Struct
it('lists file', async () => {
const file = await dstorage.files(fileCount)
assert.equal(file.fileId.toNumber(), fileCount.toNumber(), 'id is correct')
assert.equal(file.fileHash, fileHash, 'Hash is correct')
assert.equal(file.fileSize, fileSize, 'Size is correct')
assert.equal(file.fileName, fileName, 'Size is correct')
assert.equal(file.fileDescription, fileDescription, 'description is correct')
assert.equal(file.uploader, uploader, 'uploader is correct')
})
})
})