"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * @jest-environment jsdom
 */
require("../../__tests__/test-helpers/dom-polyfill");
const react_1 = require("@testing-library/react");
const live_env_1 = require("@ledgerhq/live-env");
const preload_data_1 = require("@ledgerhq/coin-solana/preload-data");
const utils_1 = require("@ledgerhq/coin-solana/utils");
const bridge_1 = require("../../bridge");
const currencies_1 = require("../../currencies");
const cache_1 = require("../../bridge/cache");
const account_1 = require("../../mock/account");
const hooks = __importStar(require("./react"));
jest.setTimeout(2 * 60 * 1000);
const localCache = {};
const cache = (0, cache_1.makeBridgeCacheSystem)({
    saveData(c, d) {
        localCache[c.id] = d;
        return Promise.resolve();
    },
    getData(c) {
        return Promise.resolve(localCache[c.id]);
    },
});
describe("solana/react", () => {
    describe("useValidators", () => {
        it("should return validators", async () => {
            const { prepare, account } = setup();
            await prepare();
            const { result } = (0, react_1.renderHook)(() => hooks.useValidators(account.currency));
            const data = (0, preload_data_1.getCurrentSolanaPreloadData)(account.currency);
            expect(result.current).toStrictEqual(data.validators);
        });
        it("should return validators", async () => {
            const { prepare, account } = setup();
            await prepare();
            const { result } = (0, react_1.renderHook)(() => hooks.useValidators(account.currency, "Ledger"));
            expect(result.current.some(validator => validator.voteAccount === utils_1.LEDGER_VALIDATOR_DEFAULT.voteAccount)).toBe(true);
        });
    });
});
function setup() {
    (0, live_env_1.setEnv)("MOCK", "1");
    (0, live_env_1.setEnv)("EXPERIMENTAL_CURRENCIES", "solana");
    const seed = "solana-2";
    const currency = (0, currencies_1.getCryptoCurrencyById)("solana");
    const a = (0, account_1.genAccount)(seed, {
        currency,
    });
    const account = (0, account_1.genAddingOperationsInAccount)(a, 3, seed);
    const currencyBridge = (0, bridge_1.getCurrencyBridge)(currency);
    const bridge = (0, bridge_1.getAccountBridge)(account);
    const transaction = bridge.createTransaction(account);
    return {
        account,
        currencyBridge,
        transaction,
        prepare: async () => cache.prepareCurrency(currency),
    };
}
//# sourceMappingURL=react.integration.test.js.map