@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
83 lines • 2.89 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = __importDefault(require("bignumber.js"));
require("../__tests__/test-helpers/setup");
const converters_1 = require("./converters");
const evmBridge = jest.fn();
const bitcoinBridge = jest.fn();
jest.mock("../generated/walletApiAdapter", () => {
return {
evm: {
getWalletAPITransactionSignFlowInfos: function () {
return evmBridge();
},
},
bitcoin: {
getWalletAPITransactionSignFlowInfos: function () {
return bitcoinBridge();
},
},
};
});
describe("getWalletAPITransactionSignFlowInfos", () => {
beforeEach(() => {
evmBridge.mockClear();
bitcoinBridge.mockClear();
});
it("should call the bridge if the implementation exists", () => {
// Given
const tx = {
family: "bitcoin",
amount: new bignumber_js_1.default(100000),
recipient: "0xABCDEF",
};
// When
(0, converters_1.getWalletAPITransactionSignFlowInfos)({ walletApiTransaction: tx, account: {} });
// Then
expect(bitcoinBridge).toBeCalledTimes(1);
expect(evmBridge).toBeCalledTimes(0);
});
it("should call the evm bridge for WalletAPITransaction tx of ethereum family", () => {
// Given
const tx = {
family: "ethereum",
amount: new bignumber_js_1.default(100000),
recipient: "0xABCDEF",
};
// When
(0, converters_1.getWalletAPITransactionSignFlowInfos)({ walletApiTransaction: tx, account: {} });
// Then
expect(evmBridge).toBeCalledTimes(1);
expect(bitcoinBridge).toBeCalledTimes(0);
});
it("should use its fallback if the bridge doesn't exist", () => {
// Given
const tx = {
family: "algorand",
mode: "send",
amount: new bignumber_js_1.default(100000),
recipient: "0xABCDEF",
};
const expectedLiveTx = {
family: tx.family,
mode: "send",
amount: tx.amount,
recipient: tx.recipient,
};
// When
const { canEditFees, hasFeesProvided, liveTx } = (0, converters_1.getWalletAPITransactionSignFlowInfos)({
walletApiTransaction: tx,
account: {},
});
// Then
expect(evmBridge).toBeCalledTimes(0);
expect(bitcoinBridge).toBeCalledTimes(0);
expect(canEditFees).toBe(false);
expect(hasFeesProvided).toBe(false);
expect(liveTx).toEqual(expectedLiveTx);
});
});
//# sourceMappingURL=converters.test.js.map