-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
39 lines (31 loc) · 1.27 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
const keccak = require(".").default;
function mustEqual(a, b) {
if (a != b) {
throw new Error(`${a} did not equal ${b}`);
}
}
describe("sanity tests", () => {
let instance = null;
it("creates the instance", async () => {
instance = await keccak();
});
it("test empty strings", () => {
mustEqual(instance.digest(), "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
instance.update("");
mustEqual(instance.digest(), "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
mustEqual(instance.digest(), "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
});
it("test full string", () => {
instance.update("juanca");
mustEqual(instance.digest(), "2a898529bc7ae0f14d153006cfd0a9107141696da0af85c8f1c3a7edcae831b6");
// digest resets the state
mustEqual(instance.digest(), "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
});
it("test partial updates for streams", () => {
instance.update("jua");
instance.update("nca");
mustEqual(instance.digest(), "2a898529bc7ae0f14d153006cfd0a9107141696da0af85c8f1c3a7edcae831b6");
// digest resets the state
mustEqual(instance.digest(), "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
});
});