UNPKG

@ledgerhq/live-common

Version:
254 lines • 7.83 kB
"use strict"; 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")); const walletApiAdapter_1 = __importDefault(require("./walletApiAdapter")); describe("getWalletAPITransactionSignFlowInfos", () => { describe("should properly get infos for ETH platform tx", () => { test("without fees provided", () => { const ethPlatformTx = { family: "ethereum", amount: new bignumber_js_1.default(100000), recipient: "0xABCDEF", }; const { canEditFees, hasFeesProvided, liveTx } = walletApiAdapter_1.default.getWalletAPITransactionSignFlowInfos({ walletApiTransaction: ethPlatformTx, account: {}, }); expect(canEditFees).toBe(true); expect(hasFeesProvided).toBe(false); expect(liveTx).toMatchInlineSnapshot(` { "amount": "100000", "chainId": 0, "family": "evm", "feesStrategy": "medium", "gasLimit": "21000", "gasPrice": undefined, "maxFeePerGas": undefined, "maxPriorityFeePerGas": undefined, "mode": "send", "nonce": -1, "recipient": "0xABCDEF", "type": 2, "useAllAmount": false, } `); }); test("with fees provided for legacy tx", () => { const ethPlatformTx = { family: "ethereum", amount: new bignumber_js_1.default(100000), recipient: "0xABCDEF", gasPrice: new bignumber_js_1.default(300), gasLimit: new bignumber_js_1.default(21000), }; const { canEditFees, hasFeesProvided, liveTx } = walletApiAdapter_1.default.getWalletAPITransactionSignFlowInfos({ walletApiTransaction: ethPlatformTx, account: {}, }); expect(canEditFees).toBe(true); expect(hasFeesProvided).toBe(true); expect(liveTx).toMatchInlineSnapshot(` { "amount": "100000", "chainId": 0, "customGasLimit": "21000", "family": "evm", "feesStrategy": "custom", "gasLimit": "21000", "gasPrice": "300", "maxFeePerGas": undefined, "maxPriorityFeePerGas": undefined, "mode": "send", "nonce": -1, "recipient": "0xABCDEF", "type": 0, "useAllAmount": false, } `); }); test("with fees provided for eip1559 tx", () => { const ethPlatformTx = { family: "ethereum", amount: new bignumber_js_1.default(100000), recipient: "0xABCDEF", gasLimit: new bignumber_js_1.default(21000), maxFeePerGas: new bignumber_js_1.default(300), maxPriorityFeePerGas: new bignumber_js_1.default(200), }; const { canEditFees, hasFeesProvided, liveTx } = walletApiAdapter_1.default.getWalletAPITransactionSignFlowInfos({ walletApiTransaction: ethPlatformTx, account: {}, }); expect(canEditFees).toBe(true); expect(hasFeesProvided).toBe(true); expect(liveTx).toMatchInlineSnapshot(` { "amount": "100000", "chainId": 0, "customGasLimit": "21000", "family": "evm", "feesStrategy": "custom", "gasLimit": "21000", "gasPrice": undefined, "maxFeePerGas": "300", "maxPriorityFeePerGas": "200", "mode": "send", "nonce": -1, "recipient": "0xABCDEF", "type": 2, "useAllAmount": false, } `); }); test("with only gasLimit provided", () => { const ethPlatformTx = { family: "ethereum", amount: new bignumber_js_1.default(100000), recipient: "0xABCDEF", gasLimit: new bignumber_js_1.default(21000), }; const { canEditFees, hasFeesProvided, liveTx } = walletApiAdapter_1.default.getWalletAPITransactionSignFlowInfos({ walletApiTransaction: ethPlatformTx, account: {}, }); expect(canEditFees).toBe(true); expect(hasFeesProvided).toBe(false); expect(liveTx).toMatchInlineSnapshot(` { "amount": "100000", "chainId": 0, "customGasLimit": "21000", "family": "evm", "feesStrategy": "medium", "gasLimit": "21000", "gasPrice": undefined, "maxFeePerGas": undefined, "maxPriorityFeePerGas": undefined, "mode": "send", "nonce": -1, "recipient": "0xABCDEF", "type": 2, "useAllAmount": false, } `); }); test("with nonce provided", () => { const ethPlatformTx = { family: "ethereum", amount: new bignumber_js_1.default(100000), recipient: "0xABCDEF", nonce: 1, }; const { canEditFees, hasFeesProvided, liveTx } = walletApiAdapter_1.default.getWalletAPITransactionSignFlowInfos({ walletApiTransaction: ethPlatformTx, account: {}, }); expect(canEditFees).toBe(true); expect(hasFeesProvided).toBe(false); expect(liveTx).toMatchInlineSnapshot(` { "amount": "100000", "chainId": 0, "family": "evm", "feesStrategy": "medium", "gasLimit": "21000", "gasPrice": undefined, "maxFeePerGas": undefined, "maxPriorityFeePerGas": undefined, "mode": "send", "nonce": 1, "recipient": "0xABCDEF", "type": 2, "useAllAmount": false, } `); }); test("with data provided", () => { const ethPlatformTx = { family: "ethereum", amount: new bignumber_js_1.default(100000), recipient: "0xABCDEF", data: Buffer.from("testBufferString"), }; const { canEditFees, hasFeesProvided, liveTx } = walletApiAdapter_1.default.getWalletAPITransactionSignFlowInfos({ walletApiTransaction: ethPlatformTx, account: {}, }); expect(canEditFees).toBe(true); expect(hasFeesProvided).toBe(false); expect(liveTx).toMatchInlineSnapshot(` { "amount": "100000", "chainId": 0, "data": { "data": [ 116, 101, 115, 116, 66, 117, 102, 102, 101, 114, 83, 116, 114, 105, 110, 103, ], "type": "Buffer", }, "family": "evm", "feesStrategy": "medium", "gasLimit": "21000", "gasPrice": undefined, "maxFeePerGas": undefined, "maxPriorityFeePerGas": undefined, "mode": "send", "nonce": -1, "recipient": "0xABCDEF", "type": 2, "useAllAmount": false, } `); }); test("with account (chainId) provided", () => { const ethPlatformTx = { family: "ethereum", amount: new bignumber_js_1.default(100000), recipient: "0xABCDEF", }; const { canEditFees, hasFeesProvided, liveTx } = walletApiAdapter_1.default.getWalletAPITransactionSignFlowInfos({ walletApiTransaction: ethPlatformTx, account: { type: "Account", currency: { ethereumLikeInfo: { chainId: 1 } } }, }); expect(canEditFees).toBe(true); expect(hasFeesProvided).toBe(false); expect(liveTx).toMatchInlineSnapshot(` { "amount": "100000", "chainId": 1, "family": "evm", "feesStrategy": "medium", "gasLimit": "21000", "gasPrice": undefined, "maxFeePerGas": undefined, "maxPriorityFeePerGas": undefined, "mode": "send", "nonce": -1, "recipient": "0xABCDEF", "type": 2, "useAllAmount": false, } `); }); }); }); //# sourceMappingURL=walletApiAdapter.test.js.map