ffjavascript/test/scalar.js
Oleksandr Brezhniev d5dae76856
Release 0.3.1 prep (#162)
* Bump deps and package version. Rebuild

* Update chai
2024-10-12 17:12:41 +01:00

30 lines
1.0 KiB
JavaScript

import * as chai from "chai";
import * as Scalar from "../src/scalar.js";
const assert = chai.assert;
describe("Basic scalar convertions", () => {
it("Should convertion Native", () => {
assert(Scalar.eq(Scalar.e("0x12"), 18));
assert(Scalar.eq(Scalar.e("0x12", 16), 18));
assert(Scalar.eq(Scalar.e("12", 16), 18));
assert(Scalar.eq(Scalar.e("18"), 18));
assert(Scalar.eq(Scalar.e("18", 10), 18));
assert(Scalar.eq(Scalar.e(18, 10), 18));
assert(Scalar.eq(Scalar.e(18n, 10), 18));
assert(Scalar.eq(Scalar.e(0x12, 10), 18));
assert(Scalar.eq(Scalar.e(0x12n, 10), 18));
});
it("Should convert to js Number Native", () => {
const maxJsNum = Number.MAX_SAFE_INTEGER;
const maxToScalar = Scalar.e(maxJsNum);
const backToNum = Scalar.toNumber(maxToScalar);
assert(backToNum, maxJsNum);
const overMaxJsNum = Scalar.add(maxToScalar, 1);
assert.throws(() => Scalar.toNumber(overMaxJsNum));
});
});