UNPKG

@ledgerhq/live-common

Version:
100 lines 5.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const useGroupedCurrenciesByProvider_mock_1 = require("../../__mocks__/useGroupedCurrenciesByProvider.mock"); const currencyUtils_1 = require("../currencyUtils"); const currencies_mock_1 = require("../../__mocks__/currencies.mock"); describe("safeCurrencyLookup", () => { it("should return the currency if it is found", () => { const currency = (0, currencyUtils_1.safeCurrencyLookup)("ethereum"); expect(currency).toBeDefined(); }); it("should return null if the currency is not found", () => { const currency = (0, currencyUtils_1.safeCurrencyLookup)("not-a-currency"); expect(currency).toBeNull(); }); }); describe("isProviderToken", () => { it("should return true if the currency is a provider token", () => { const baseToken = { type: "TokenCurrency", id: "base/erc20/base", contractAddress: "0x0000000000000000000000000000000000000000", parentCurrency: currencies_mock_1.mockBaseCryptoCurrency, tokenType: "erc20", name: "Base", ticker: "BASE", units: [ { name: "Base", code: "BASE", magnitude: 18, }, ], }; const currency = (0, currencyUtils_1.isProviderToken)(baseToken, "base"); expect(currency).toBe(true); }); it("should return false if the currency is not a provider token", () => { const currency = (0, currencyUtils_1.isProviderToken)(currencies_mock_1.mockEthCryptoCurrency, "ethereum"); expect(currency).toBe(false); }); }); describe("getProviderCurrency", () => { it("should return the currency if it is a provider currency", () => { const { result } = (0, useGroupedCurrenciesByProvider_mock_1.useGroupedCurrenciesByProvider)(); const currency = (0, currencyUtils_1.getProviderCurrency)(result.currenciesByProvider[0]); expect(currency).toEqual(currencies_mock_1.mockBtcCryptoCurrency); }); it("should return the currency if it is a provider token", () => { const { result } = (0, useGroupedCurrenciesByProvider_mock_1.useGroupedCurrenciesByProvider)(); const currency = (0, currencyUtils_1.getProviderCurrency)(result.currenciesByProvider[3]); expect(currency).toEqual(currencies_mock_1.usdcToken); }); }); describe("buildProviderCoverageMap", () => { it("should build a map of provider coverage correctly", () => { const { result } = (0, useGroupedCurrenciesByProvider_mock_1.useGroupedCurrenciesByProvider)(); const coverageMap = (0, currencyUtils_1.buildProviderCoverageMap)(result.currenciesByProvider); expect(coverageMap).toBeInstanceOf(Map); expect(coverageMap.get("bitcoin")).toEqual(new Set(["bitcoin"])); expect(coverageMap.get("ethereum")).toEqual(new Set(["ethereum"])); expect(coverageMap.get("arbitrum")).toEqual(new Set(["ethereum"])); expect(coverageMap.get("base")).toEqual(new Set(["ethereum"])); expect(coverageMap.get("scroll")).toEqual(new Set(["ethereum"])); expect(coverageMap.get("arbitrum/erc20/arbitrum")).toEqual(new Set(["arbitrum"])); expect(coverageMap.get("ethereum/erc20/usd__coin")).toEqual(new Set(["usd-coin"])); expect(coverageMap.get("injective")).toEqual(new Set(["injective-protocol"])); }); it("should handle empty input", () => { const coverageMap = (0, currencyUtils_1.buildProviderCoverageMap)([]); expect(coverageMap).toBeInstanceOf(Map); expect(coverageMap.size).toBe(0); }); }); describe("filterProvidersByIds", () => { it("should filter providers by ids correctly #evm", () => { const { result } = (0, useGroupedCurrenciesByProvider_mock_1.useGroupedCurrenciesByProvider)(); const coverageMap = (0, currencyUtils_1.buildProviderCoverageMap)(result.currenciesByProvider); const filteredProviders = (0, currencyUtils_1.filterProvidersByIds)(result.currenciesByProvider, new Set(["base"]), coverageMap); expect(filteredProviders).toHaveLength(1); expect(filteredProviders[0].providerId).toBe("ethereum"); }); it("should filter providers by ids correctly #bitcoin", () => { const { result } = (0, useGroupedCurrenciesByProvider_mock_1.useGroupedCurrenciesByProvider)(); const coverageMap = (0, currencyUtils_1.buildProviderCoverageMap)(result.currenciesByProvider); const filteredProviders = (0, currencyUtils_1.filterProvidersByIds)(result.currenciesByProvider, new Set(["bitcoin"]), coverageMap); expect(filteredProviders).toHaveLength(1); expect(filteredProviders[0].providerId).toBe("bitcoin"); }); }); describe("extractProviderCurrencies", () => { it("should extract provider currencies correctly", () => { const { result } = (0, useGroupedCurrenciesByProvider_mock_1.useGroupedCurrenciesByProvider)(); const providerCurrencies = (0, currencyUtils_1.extractProviderCurrencies)(result.currenciesByProvider); expect(providerCurrencies).toHaveLength(5); expect(providerCurrencies[0]).toEqual(currencies_mock_1.mockBtcCryptoCurrency); expect(providerCurrencies[1].id).toBe("ethereum"); expect(providerCurrencies[2].id).toBe("arbitrum/erc20/arbitrum"); }); }); //# sourceMappingURL=currencyUtils.test.js.map