-
Notifications
You must be signed in to change notification settings - Fork 31
/
IPFSStorage.test.js
71 lines (54 loc) · 2.1 KB
/
IPFSStorage.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
import { expect } from 'chai';
import { getBytes32FromMultiash, getMultihashFromContractResponse } from '../src/multihash';
import assertRevert from './helpers/assertRevert';
import expectEvent from './helpers/expectEvent';
const IPFSStorage = artifacts.require('./IPFSStorage.sol');
contract('IPFSStorage', (accounts) => {
let ipfsStorage;
beforeEach(async () => {
ipfsStorage = await IPFSStorage.new();
});
const ipfsHashes = [
'QmahqCsAUAw7zMv6P6Ae8PjCTck7taQA6FgGQLnWdKG7U8',
'Qmb4atcgbbN5v4CDJ8nz5QG5L2pgwSTLd3raDrnyhLjnUH',
];
async function setIPFSHash(account, hash) {
const { digest, hashFunction, size } = getBytes32FromMultiash(hash);
return ipfsStorage.setEntry(digest, hashFunction, size, { from: account });
}
async function getIPFSHash(account) {
return getMultihashFromContractResponse(await ipfsStorage.getEntry(account));
}
it('should get IPFS hash after setting', async () => {
await setIPFSHash(accounts[0], ipfsHashes[0]);
expect(await getIPFSHash(accounts[0])).to.equal(ipfsHashes[0]);
});
it('should fire event when new has is set', async () => {
await expectEvent(
setIPFSHash(accounts[0], ipfsHashes[0]),
'EntrySet',
);
});
it('should set IPFS hash for each address', async () => {
await setIPFSHash(accounts[0], ipfsHashes[0]);
await setIPFSHash(accounts[1], ipfsHashes[1]);
expect(await getIPFSHash(accounts[0])).to.equal(ipfsHashes[0]);
expect(await getIPFSHash(accounts[1])).to.equal(ipfsHashes[1]);
});
it('should clear IPFS hash after set', async () => {
await setIPFSHash(accounts[0], ipfsHashes[0]);
expect(await getIPFSHash(accounts[0])).to.equal(ipfsHashes[0]);
await ipfsStorage.clearEntry();
expect(await getIPFSHash(accounts[0])).to.be.a('null');
});
it('should fire event when entry is cleared', async () => {
await setIPFSHash(accounts[0], ipfsHashes[0]);
await expectEvent(
ipfsStorage.clearEntry(),
'EntryDeleted',
);
});
it('should prevent clearing non-exists entry', async () => {
await assertRevert(ipfsStorage.clearEntry());
});
});