-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecc.test.js
62 lines (52 loc) · 1.63 KB
/
ecc.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
/*
* Copyright (c) 2021, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/
import libecc_module from "./libecc.js";
import assert from "assert";
describe("ecc_randombytes", () => {
it("fills an array of 128 bytes", async () => {
const libecc = await libecc_module();
let buf = new Uint8Array(128);
libecc.ecc_randombytes(buf);
});
});
describe("ecc_compare", () => {
it("compare a == b", async () => {
const libecc = await libecc_module();
let a = Uint8Array.of(1, 2, 3);
let b = Uint8Array.of(1, 2, 3);
let r = libecc.ecc_compare(a, b, 3);
assert.equal(r, 0);
});
it("compare a < b", async () => {
const libecc = await libecc_module();
let a = Uint8Array.of(1, 2, 3);
let b = Uint8Array.of(1, 4, 3);
let r = libecc.ecc_compare(a, b, 3);
assert.equal(r, -1);
});
it("compare a > b", async () => {
const libecc = await libecc_module();
let a = Uint8Array.of(1, 4, 3);
let b = Uint8Array.of(1, 3, 3);
let r = libecc.ecc_compare(a, b, 3);
assert.equal(r, 1);
});
});
describe("ecc_is_zero", () => {
it("test a zero vector", async () => {
const libecc = await libecc_module();
let n = Uint8Array.of(0, 0, 0);
let r = libecc.ecc_is_zero(n, 3);
assert.ok(r);
});
it("test a non zero vector", async () => {
const libecc = await libecc_module();
let n = Uint8Array.of(1, 2, 3);
let r = libecc.ecc_is_zero(n, 3);
assert.ok(!r);
});
});