@ledgerhq/coin-casper
Version:
Ledger Casper integration
58 lines • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
describe("Casper utils", () => {
describe("isNoErrorReturnCode", () => {
test("should return true for code 0x9000", () => {
expect((0, utils_1.isNoErrorReturnCode)(0x9000)).toBe(true);
});
test("should return false for other codes", () => {
expect((0, utils_1.isNoErrorReturnCode)(0x6984)).toBe(false);
expect((0, utils_1.isNoErrorReturnCode)(0x6a80)).toBe(false);
expect((0, utils_1.isNoErrorReturnCode)(0)).toBe(false);
});
});
describe("getPath", () => {
test("should add m/ prefix if not present", () => {
expect((0, utils_1.getPath)("44'/506'/0'/0/0")).toBe("m/44'/506'/0'/0/0");
});
test("should not modify path if m/ prefix is already present", () => {
expect((0, utils_1.getPath)("m/44'/506'/0'/0/0")).toBe("m/44'/506'/0'/0/0");
});
test("should handle empty path", () => {
expect((0, utils_1.getPath)("")).toBe("");
});
});
describe("isError", () => {
test("should not throw for successful return code", () => {
expect(() => (0, utils_1.isError)({ returnCode: 0x9000, errorMessage: "Success" })).not.toThrow();
});
test("should throw for error return codes", () => {
expect(() => (0, utils_1.isError)({ returnCode: 0x6a80, errorMessage: "Bad data" })).toThrow("27264 - Bad data");
});
});
describe("methodToString", () => {
test("should return 'Token transfer' for method 0", () => {
expect((0, utils_1.methodToString)(0)).toBe("Token transfer");
});
test("should return 'Unknown' for other methods", () => {
expect((0, utils_1.methodToString)(1)).toBe("Unknown");
expect((0, utils_1.methodToString)(999)).toBe("Unknown");
});
});
describe("getRandomTransferID", () => {
test("should return a string containing a number", () => {
const result = (0, utils_1.getRandomTransferID)();
expect(typeof result).toBe("string");
expect(Number.isNaN(parseInt(result, 10))).toBe(false);
});
test("should generate different IDs on multiple calls", () => {
const id1 = (0, utils_1.getRandomTransferID)();
const id2 = (0, utils_1.getRandomTransferID)();
const id3 = (0, utils_1.getRandomTransferID)();
// There's a very small chance these could be the same, but it's extremely unlikely
expect(new Set([id1, id2, id3]).size).toBeGreaterThan(0);
});
});
});
//# sourceMappingURL=utils.additional.test.js.map