-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathutils.js
More file actions
60 lines (46 loc) · 1.82 KB
/
Copy pathutils.js
File metadata and controls
60 lines (46 loc) · 1.82 KB
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
import assert from "assert";
import * as ScalarN from "../src/scalar.js";
import * as utilsN from "../src/utils.js";
describe("Utils native", () => {
const num = ScalarN.e("21888242871839275222246405745257275088614511777268538073601725287587578984328");
it("Should convert integer to buffer little-endian", () => {
const buff = utilsN.leInt2Buff(num, 32);
const numFromBuff = utilsN.leBuff2int(buff);
assert(ScalarN.eq(num, numFromBuff), true);
});
it("Should convert integer to buffer big-endian", () => {
const buff = utilsN.beInt2Buff(num, 32);
const numFromBuff = utilsN.beBuff2int(buff);
assert(ScalarN.eq(num, numFromBuff), true);
});
it("Should stringify bigInt", () => {
const str = utilsN.stringifyBigInts(num);
const numFromStr = utilsN.unstringifyBigInts(str);
assert(ScalarN.eq(num, numFromStr), true);
});
it("Should stringify bigInt & null", () => {
const obj = {
num: num,
other: null
};
const strObj = utilsN.stringifyBigInts(obj);
const objFromStr = utilsN.unstringifyBigInts(strObj);
assert.deepStrictEqual(obj, objFromStr);
});
it("Should generate buffer little-endian without trailing non-zero element", () => {
for (let i = 1; i < 33; i++) {
var buff = utilsN.leInt2Buff(BigInt(42), i);
for (let t = 1; t < buff.length; t++){
assert(buff[t] === 0, true);
}
}
});
it("Should generate buffer big-endian without trailing non-zero element", () => {
for (let i = 1; i < 33; i++) {
var buff = utilsN.beInt2Buff(BigInt(42), i);
for (let t = 0; t < buff.length - 1; t++){
assert(buff[t] === 0, true);
}
}
});
});