"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const live_app_sdk_1 = require("@ledgerhq/live-app-sdk");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const platformAdapter_1 = __importDefault(require("./platformAdapter"));
const utils_1 = require("@ledgerhq/coin-evm/utils");
describe("getPlatformTransactionSignFlowInfos", () => {
    describe("should properly get infos for ETH platform tx", () => {
        test("without fees provided", () => {
            const ethPlatformTx = {
                family: live_app_sdk_1.FAMILIES.ETHEREUM,
                amount: new bignumber_js_1.default(100000),
                recipient: "0xABCDEF",
            };
            const expectedLiveTx = {
                family: "evm",
                amount: ethPlatformTx.amount,
                recipient: ethPlatformTx.recipient,
                data: undefined,
                gasLimit: undefined,
                nonce: utils_1.DEFAULT_NONCE,
                customGasLimit: undefined,
                feesStrategy: undefined,
                type: 2,
            };
            const { canEditFees, hasFeesProvided, liveTx } = platformAdapter_1.default.getPlatformTransactionSignFlowInfos(ethPlatformTx);
            expect(canEditFees).toBe(true);
            expect(hasFeesProvided).toBe(false);
            expect(liveTx).toEqual(expectedLiveTx);
        });
        // FIXME: add tests for tx of type 2
        test("with fees provided for legacy tx", () => {
            const ethPlatformTx = {
                family: live_app_sdk_1.FAMILIES.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 expectedLiveTx = {
                family: "evm",
                amount: ethPlatformTx.amount,
                recipient: ethPlatformTx.recipient,
                gasPrice: ethPlatformTx.gasPrice,
                gasLimit: ethPlatformTx.gasLimit,
                customGasLimit: ethPlatformTx.gasLimit,
                nonce: utils_1.DEFAULT_NONCE,
                data: undefined,
                feesStrategy: "custom",
                type: 0,
            };
            const { canEditFees, hasFeesProvided, liveTx } = platformAdapter_1.default.getPlatformTransactionSignFlowInfos(ethPlatformTx);
            expect(canEditFees).toBe(true);
            expect(hasFeesProvided).toBe(true);
            expect(liveTx).toEqual(expectedLiveTx);
        });
        test("with only gasLimit provided", () => {
            const ethPlatformTx = {
                family: live_app_sdk_1.FAMILIES.ETHEREUM,
                amount: new bignumber_js_1.default(100000),
                recipient: "0xABCDEF",
                gasLimit: new bignumber_js_1.default(21000),
            };
            const expectedLiveTx = {
                family: "evm",
                amount: ethPlatformTx.amount,
                recipient: ethPlatformTx.recipient,
                gasLimit: ethPlatformTx.gasLimit,
                customGasLimit: ethPlatformTx.gasLimit,
                nonce: utils_1.DEFAULT_NONCE,
                data: undefined,
                type: 2,
            };
            const { canEditFees, hasFeesProvided, liveTx } = platformAdapter_1.default.getPlatformTransactionSignFlowInfos(ethPlatformTx);
            expect(canEditFees).toBe(true);
            expect(hasFeesProvided).toBe(false);
            expect(liveTx).toEqual(expectedLiveTx);
        });
        test("with nonce provided", () => {
            const ethPlatformTx = {
                family: live_app_sdk_1.FAMILIES.ETHEREUM,
                amount: new bignumber_js_1.default(100000),
                recipient: "0xABCDEF",
                nonce: 1,
            };
            const expectedLiveTx = {
                family: "evm",
                amount: ethPlatformTx.amount,
                recipient: ethPlatformTx.recipient,
                data: undefined,
                gasLimit: undefined,
                nonce: 1,
                customGasLimit: undefined,
                feesStrategy: undefined,
                type: 2,
            };
            const { canEditFees, hasFeesProvided, liveTx } = platformAdapter_1.default.getPlatformTransactionSignFlowInfos(ethPlatformTx);
            expect(canEditFees).toBe(true);
            expect(hasFeesProvided).toBe(false);
            expect(liveTx).toEqual(expectedLiveTx);
        });
    });
});
//# sourceMappingURL=platformAdapter.test.js.map