UNPKG

@ledgerhq/live-common

Version:
36 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const getInterestRateForAsset_1 = require("../getInterestRateForAsset"); const currencies_mock_1 = require("../../__mocks__/currencies.mock"); describe("getInterestRateForAsset", () => { const networks = [currencies_mock_1.mockEthCryptoCurrency, currencies_mock_1.usdcToken]; const interestRates = { [currencies_mock_1.mockEthCryptoCurrency.id]: { value: 0.05, type: "APY" }, [currencies_mock_1.usdcToken.id]: { value: 0.042927, type: "NRR" }, }; it("returns correct rate for CryptoCurrency asset", () => { const { interestRate, interestRatePercentageRounded } = (0, getInterestRateForAsset_1.getInterestRateForAsset)(currencies_mock_1.mockEthCryptoCurrency, interestRates); expect(interestRate).toEqual({ value: 0.05, type: "APY" }); expect(interestRatePercentageRounded).toBe(5); }); it("returns correct rate for TokenCurrency (parentCurrency) asset", () => { const { interestRate, interestRatePercentageRounded } = (0, getInterestRateForAsset_1.getInterestRateForAsset)(currencies_mock_1.usdcToken, interestRates, networks); expect(interestRate).toEqual({ value: 0.042927, type: "NRR" }); expect(interestRatePercentageRounded).toBeCloseTo(4.29, 2); }); it("returns undefined and 0 if no rate found", () => { const { interestRate, interestRatePercentageRounded } = (0, getInterestRateForAsset_1.getInterestRateForAsset)(currencies_mock_1.mockScrollCryptoCurrency, interestRates, networks); expect(interestRate).toBeUndefined(); expect(interestRatePercentageRounded).toBe(0); }); it("returns 0 if rate is 0", () => { const zeroNetworks = [currencies_mock_1.mockEthCryptoCurrency]; const zeroRates = { ethereum: { value: 0, type: "APY" }, }; const { interestRate, interestRatePercentageRounded } = (0, getInterestRateForAsset_1.getInterestRateForAsset)(currencies_mock_1.mockEthCryptoCurrency, zeroRates, zeroNetworks); expect(interestRate).toEqual({ value: 0, type: "APY" }); expect(interestRatePercentageRounded).toBe(0); }); }); //# sourceMappingURL=getInterestRateForAsset.test.js.map