This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/test/unit/helpers/bytes.test.ts

44 lines
1.3 KiB
TypeScript
Raw Normal View History

import {expect} from "chai";
import {concatUint8Arrays, isZeroUint8Array} from "../../../src/helpers/utils";
import {hexToBytesNode} from "../../util";
describe("helpers / bytes", () => {
describe("isZeroUint8Array", () => {
const testCases: {isZero: boolean; hex: string}[] = [
{hex: "0x00", isZero: true},
{hex: "0x" + "00".repeat(32), isZero: true},
{hex: "0x" + "00".repeat(96), isZero: true},
{hex: "0x" + "00".repeat(31) + "01", isZero: false},
{
hex: "0xb6f21199594b56d77670564bf422cb331d5281ca2c1f9a45588a56881d8287ef8619efa6456d6cd2ef61306aa5b21311",
isZero: false,
},
];
for (const {hex, isZero} of testCases) {
it(`${hex} isZero = ${isZero}`, () => {
const bytes = hexToBytesNode(hex);
expect(isZeroUint8Array(bytes)).to.equal(isZero);
});
}
});
describe("concatUint8Arrays", () => {
it("Should merge multiple Uint8Array", () => {
const bytesArr = [
new Uint8Array([1, 2, 3]),
new Uint8Array([4, 5]),
new Uint8Array([6]),
new Uint8Array([7, 8]),
new Uint8Array([9, 10, 11]),
];
const expectedBytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
const bytes = concatUint8Arrays(bytesArr);
expect(bytes.toString()).to.equal(expectedBytes.toString());
});
});
});