"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 estimateMaxSpendable_1 = require("../estimateMaxSpendable");
const alpaca = __importStar(require("../alpaca"));
// Mock the alpaca API
jest.mock("../alpaca", () => ({
    getAlpacaApi: jest.fn(),
}));
const mockedGetAlpacaApi = alpaca.getAlpacaApi;
// Dummy data
const dummyAccount = {
    id: "js:2:ripple:r123:",
    type: "Account",
    spendableBalance: new bignumber_js_1.default(50000000),
    currency: { id: "ripple", name: "XRP", units: [{ name: "XRP", magnitude: 6 }] },
    freshAddress: "r123",
};
describe("genericEstimateMaxSpendable", () => {
    afterEach(() => {
        jest.clearAllMocks();
    });
    it("subtracts estimated fee from spendable balance", async () => {
        mockedGetAlpacaApi.mockReturnValue({
            estimateFees: jest.fn().mockResolvedValue({ value: 10000n }), // 0.01 XRP
        });
        const estimate = (0, estimateMaxSpendable_1.genericEstimateMaxSpendable)("xrp", "local");
        const result = await estimate({
            account: dummyAccount,
            parentAccount: null,
            transaction: {},
        });
        expect(result.toString()).toBe("49990000"); // 50_000_000 - 10_000
    });
    it("returns 0 if fee is higher than spendable", async () => {
        const poorAccount = {
            ...dummyAccount,
            spendableBalance: new bignumber_js_1.default(5000), // very low
        };
        mockedGetAlpacaApi.mockReturnValue({
            estimateFees: jest.fn().mockResolvedValue({ value: 10000n }),
        });
        const estimate = (0, estimateMaxSpendable_1.genericEstimateMaxSpendable)("xrp", "local");
        const result = await estimate({
            account: poorAccount,
            parentAccount: null,
            transaction: {},
        });
        expect(result.toString()).toBe("0");
    });
    it("returns full spendable balance if fee is 0", async () => {
        mockedGetAlpacaApi.mockReturnValue({
            estimateFees: jest.fn().mockResolvedValue({ value: 0n }),
        });
        const estimate = (0, estimateMaxSpendable_1.genericEstimateMaxSpendable)("xrp", "local");
        const result = await estimate({
            account: dummyAccount,
            parentAccount: null,
            transaction: {},
        });
        expect(result.toString()).toBe("50000000");
    });
});
//# sourceMappingURL=estimateMaxSpendable.test.js.map