|
1 |
| -/* eslint-disable prettier/prettier */ |
2 |
| -import fs from 'fs' |
3 |
| -import path from 'path' |
| 1 | +jest.useFakeTimers(); |
4 | 2 |
|
5 |
| -import axios from 'axios' |
6 |
| -import Web3 from 'web3' |
| 3 | +import fs from "fs"; |
| 4 | +import path from "path"; |
7 | 5 |
|
8 |
| -import { |
9 |
| - multihashFile, |
10 |
| - validMultihash |
11 |
| -} from '../../src/utils/hashing' |
| 6 | +import axios from "axios"; |
| 7 | +import Web3 from "web3"; |
12 | 8 |
|
13 |
| -describe('Hashing and Validation', () => { |
14 |
| - it('Custom hash function', async () => { |
15 |
| - const hashedText = '12345' |
| 9 | +import { multihashFile, validMultihash } from "../../src/utils/hashing"; |
| 10 | + |
| 11 | +describe("Hashing and Validation", () => { |
| 12 | + it("Custom hash function", async () => { |
| 13 | + const hashedText = "12345"; |
16 | 14 |
|
17 | 15 | const nonStandardSha3Hash = multihashFile(
|
18 | 16 | hashedText,
|
19 |
| - 0x1B, // keccak-256 |
| 17 | + 0x1b, // keccak-256 |
20 | 18 | Web3.utils.soliditySha3 // custom hash function
|
21 |
| - ) |
| 19 | + ); |
22 | 20 |
|
23 | 21 | // Use the standard keccak-256 hashing algorithm
|
24 |
| - expect(validMultihash(nonStandardSha3Hash, hashedText)).toBeFalsy() // false |
| 22 | + expect(validMultihash(nonStandardSha3Hash, hashedText)).toBeFalsy(); // false |
25 | 23 |
|
26 | 24 | // Use the solidity sha3 implementation
|
27 |
| - expect( |
28 |
| - validMultihash(nonStandardSha3Hash, hashedText, Web3.utils.soliditySha3) |
29 |
| - ).toBeTruthy() // true |
30 |
| - }) |
31 |
| - it('Hash from a file', async () => { |
32 |
| - const fileContents = JSON.parse(fs.readFileSync(path.resolve(__dirname, "./exampleMetaEvidenceBasic.json")).toString()) |
| 25 | + expect(validMultihash(nonStandardSha3Hash, hashedText, Web3.utils.soliditySha3)).toBeTruthy(); // true |
| 26 | + }); |
| 27 | + it("Hash from a file", async () => { |
| 28 | + const fileContents = JSON.parse( |
| 29 | + fs.readFileSync(path.resolve(__dirname, "./exampleMetaEvidenceBasic.json")).toString() |
| 30 | + ); |
33 | 31 |
|
34 |
| - const evidenceHash = multihashFile( |
35 |
| - JSON.stringify(fileContents), |
36 |
| - 0x16 |
37 |
| - ) |
| 32 | + const evidenceHash = multihashFile(JSON.stringify(fileContents), 0x16); |
38 | 33 |
|
39 |
| - expect(validMultihash( |
40 |
| - evidenceHash, |
41 |
| - JSON.stringify(fileContents) |
42 |
| - )).toBeTruthy() // true |
43 |
| - }) |
44 |
| - it('Hash from a file selfHash', async () => { |
45 |
| - const fileContents = fs.readFileSync(path.resolve(__dirname, "./exampleMetaEvidenceBasicSelfHash.json")).toString() |
| 34 | + expect(validMultihash(evidenceHash, JSON.stringify(fileContents))).toBeTruthy(); // true |
| 35 | + }); |
| 36 | + it("Hash from a file selfHash", async () => { |
| 37 | + const fileContents = fs.readFileSync(path.resolve(__dirname, "./exampleMetaEvidenceBasicSelfHash.json")).toString(); |
46 | 38 |
|
47 |
| - const { selfHash, ...fileJSON } = JSON.parse(fileContents) |
| 39 | + const { selfHash, ...fileJSON } = JSON.parse(fileContents); |
48 | 40 |
|
49 |
| - expect(validMultihash( |
50 |
| - selfHash, |
51 |
| - fileJSON |
52 |
| - )).toBeTruthy() // true |
53 |
| - }) |
54 |
| - it('Hash display interface', async () => { |
55 |
| - const pageContents = (await axios.get('https://kleros-t2cr-evidence.netlify.com/')).data |
| 41 | + expect(validMultihash(selfHash, fileJSON)).toBeTruthy(); // true |
| 42 | + }); |
| 43 | + it("Hash display interface", async () => { |
| 44 | + const pageContents = (await axios.get("https://kleros-t2cr-evidence.netlify.com/")).data; |
56 | 45 |
|
57 |
| - const multiHash = multihashFile(pageContents, 0x1B) |
| 46 | + const multiHash = multihashFile(pageContents, 0x1b); |
58 | 47 |
|
59 |
| - expect(validMultihash( |
60 |
| - multiHash, |
61 |
| - pageContents |
62 |
| - )).toBeTruthy() |
63 |
| - }) |
64 |
| -}) |
| 48 | + expect(validMultihash(multiHash, pageContents)).toBeTruthy(); |
| 49 | + }); |
| 50 | +}); |
0 commit comments