@ledgerhq/coin-ton
Version:
54 lines • 2.36 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cryptoassets_1 = require("@ledgerhq/cryptoassets");
const hw_getAddress_1 = __importDefault(require("../../hw-getAddress"));
const utils_1 = require("../../utils");
const address = "0xc3f95102d5c8f2c83e49ce3acfb905edfb7f37de";
const publicKey = "mockedPublicKey";
const spyGetAddress = jest.fn().mockImplementation(async () => Promise.resolve({
publicKey,
address: address.toLowerCase(),
}));
const spyValidateAddress = jest.fn().mockImplementation(async () => Promise.resolve({
publicKey,
address: address.toLowerCase(),
}));
const mockSignerFactory = (_, fn) => fn({
getAddress: spyGetAddress,
validateAddress: spyValidateAddress,
signTransaction: jest.fn(),
});
describe("hw-getAddress", () => {
it("should return an encoded address and a public key when verifiy is false", async () => {
const getAddress = (0, hw_getAddress_1.default)(mockSignerFactory);
const response = await getAddress("deviceId", {
path: "44'/607'/0'/0'/0'/0'",
verify: false,
currency: (0, cryptoassets_1.getCryptoCurrencyById)("ton"),
derivationMode: "ton",
});
expect(response.address).toBe(address);
expect(response.publicKey).toBe(publicKey);
expect(spyGetAddress).toHaveBeenCalledWith((0, utils_1.getLedgerTonPath)("44'/607'/0'/0'/0'/0'"), {
bounceable: false,
});
});
it("should return an encoded address and a public key when verifiy is true", async () => {
const getAddress = (0, hw_getAddress_1.default)(mockSignerFactory);
const response = await getAddress("deviceId", {
path: "44'/607'/0'/0'/0'/0'",
verify: true,
currency: (0, cryptoassets_1.getCryptoCurrencyById)("ton"),
derivationMode: "ton",
});
expect(response.address).toBe(address);
expect(response.publicKey).toBe(publicKey);
expect(spyValidateAddress).toHaveBeenCalledWith((0, utils_1.getLedgerTonPath)("44'/607'/0'/0'/0'/0'"), {
bounceable: false,
});
});
});
//# sourceMappingURL=hw-getAddress.unit.test.js.map