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/hex.test.ts

30 lines
821 B
TypeScript

import {expect} from "chai";
import {hexToBytes, bytesToHex} from "../../../src/helpers/hex";
describe("helpers / hex", () => {
const testCases: {id: string; hex: string}[] = [
{
id: "pubkey",
hex: "0xb6f21199594b56d77670564bf422cb331d5281ca2c1f9a45588a56881d8287ef8619efa6456d6cd2ef61306aa5b21311",
},
];
for (const {id, hex} of testCases) {
it(`${id} hexToBytes`, () => {
const expectedBytes = hexToBytesNode(hex);
const bytes = hexToBytes(hex);
expect(expectedBytes.equals(bytes)).to.be.true;
});
it(`${id} bytesToHex`, () => {
const bytes = hexToBytesNode(hex);
const _hex = bytesToHex(bytes);
expect(_hex).to.equal(hex);
});
}
});
function hexToBytesNode(hex: string): Buffer {
return Buffer.from(hex.replace("0x", ""), "hex");
}