UNPKG

@ledgerhq/coin-mina

Version:
106 lines 4.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const getAddress_1 = __importDefault(require("./getAddress")); const currencies_1 = require("@ledgerhq/cryptoassets/lib/currencies"); describe("Mina getAddress resolver", () => { // Mock the signer context const mockSigner = { getAddress: jest.fn(), signTransaction: jest.fn(), }; const commonOptions = { currency: (0, currencies_1.getCryptoCurrencyById)("mina"), derivationMode: "minabip44", }; const mockSignerContext = jest.fn(async (deviceId, callback) => { return callback(mockSigner); }); beforeEach(() => { jest.clearAllMocks(); }); it("should call the signer with the correct account number", async () => { const options = { ...commonOptions, path: "44'/12586'/0'/0/0", verify: false, }; // Mock response from signer mockSigner.getAddress.mockResolvedValue({ publicKey: "testPublicKey123", }); const getAddress = (0, getAddress_1.default)(mockSignerContext); await getAddress("device1", options); expect(mockSigner.getAddress).toHaveBeenCalledWith(0, false); }); it("should pass the verify flag correctly", async () => { const options = { path: "44'/12586'/2'/0/0", verify: true, ...commonOptions, }; // Mock response from signer mockSigner.getAddress.mockResolvedValue({ publicKey: "testPublicKey456", }); const getAddress = (0, getAddress_1.default)(mockSignerContext); await getAddress("device1", options); expect(mockSigner.getAddress).toHaveBeenCalledWith(2, true); }); it("should default to verify=false when not provided", async () => { const options = { path: "44'/12586'/1'/0/0", ...commonOptions, }; // Mock response from signer mockSigner.getAddress.mockResolvedValue({ publicKey: "testPublicKey789", }); const getAddress = (0, getAddress_1.default)(mockSignerContext); await getAddress("device1", options); expect(mockSigner.getAddress).toHaveBeenCalledWith(1, false); }); it("should return the correct address format", async () => { const options = { path: "44'/12586'/3'/0/0", ...commonOptions, }; const expectedPublicKey = "minaPublicKeyABC123"; // Mock response from signer mockSigner.getAddress.mockResolvedValue({ publicKey: expectedPublicKey, }); const getAddress = (0, getAddress_1.default)(mockSignerContext); const result = await getAddress("device1", options); expect(result).toEqual({ address: expectedPublicKey, publicKey: expectedPublicKey, path: options.path, }); }); it("should throw an error for invalid path", async () => { const options = { path: "44'/789'/0'/0/0", // Invalid coin type for Mina verify: false, ...commonOptions, }; const getAddress = (0, getAddress_1.default)(mockSignerContext); await expect(getAddress("device1", options)).rejects.toThrow(); }); it("should throw an error when publicKey is undefined", async () => { const options = { path: "44'/12586'/0'/0/0", verify: false, ...commonOptions, }; // Mock response from signer with undefined publicKey mockSigner.getAddress.mockResolvedValue({ publicKey: undefined, }); const getAddress = (0, getAddress_1.default)(mockSignerContext); await expect(getAddress("device1", options)).rejects.toThrow("[mina] getAddress: expected publicKey to be defined"); }); }); //# sourceMappingURL=getAddress.test.js.map