@ledgerhq/live-common 34.38.1 → 34.38.2-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/hw/getLatestFirmwareForDevice.js +4 -0
- package/lib/__tests__/hw/getLatestFirmwareForDevice.js.map +1 -1
- package/lib/__tests__/test-helpers/deviceInfos.d.ts.map +1 -1
- package/lib/__tests__/test-helpers/deviceInfos.js +5 -0
- package/lib/__tests__/test-helpers/deviceInfos.js.map +1 -1
- package/lib/apps/mock.d.ts +2 -32
- package/lib/apps/mock.d.ts.map +1 -1
- package/lib/apps/mock.js +3 -0
- package/lib/apps/mock.js.map +1 -1
- package/lib/apps/polyfill.d.ts +4 -1
- package/lib/apps/polyfill.d.ts.map +1 -1
- package/lib/bridge/cache.d.ts.map +1 -1
- package/lib/bridge/cache.js +2 -2
- package/lib/bridge/cache.js.map +1 -1
- package/lib/bridge/cache.test.d.ts +2 -0
- package/lib/bridge/cache.test.d.ts.map +1 -0
- package/lib/bridge/cache.test.js +63 -0
- package/lib/bridge/cache.test.js.map +1 -0
- package/lib/deposit/deposit.test.js +418 -74
- package/lib/deposit/deposit.test.js.map +1 -1
- package/lib/deposit/helper.d.ts +1 -0
- package/lib/deposit/helper.d.ts.map +1 -1
- package/lib/deposit/helper.js +19 -6
- package/lib/deposit/helper.js.map +1 -1
- package/lib/deviceSDK/tasks/getDeviceInfo.d.ts.map +1 -1
- package/lib/deviceSDK/tasks/getDeviceInfo.js +3 -1
- package/lib/deviceSDK/tasks/getDeviceInfo.js.map +1 -1
- package/lib/e2e/enum/Provider.d.ts +1 -1
- package/lib/e2e/enum/Provider.d.ts.map +1 -1
- package/lib/e2e/enum/Provider.js +1 -1
- package/lib/e2e/enum/Provider.js.map +1 -1
- package/lib/e2e/index.d.ts +5 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/e2e/swap.d.ts.map +1 -1
- package/lib/e2e/swap.js +10 -7
- package/lib/e2e/swap.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +35 -0
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/hooks/useAppVersionBlockCheck.d.ts +11 -0
- package/lib/hooks/useAppVersionBlockCheck.d.ts.map +1 -0
- package/lib/hooks/useAppVersionBlockCheck.js +32 -0
- package/lib/hooks/useAppVersionBlockCheck.js.map +1 -0
- package/lib/hooks/useAppVersionBlockCheck.test.d.ts +2 -0
- package/lib/hooks/useAppVersionBlockCheck.test.d.ts.map +1 -0
- package/lib/hooks/useAppVersionBlockCheck.test.js +133 -0
- package/lib/hooks/useAppVersionBlockCheck.test.js.map +1 -0
- package/lib/hw/connectAppEventMapper.d.ts.map +1 -1
- package/lib/hw/connectAppEventMapper.js +3 -1
- package/lib/hw/connectAppEventMapper.js.map +1 -1
- package/lib/hw/connectManager.d.ts.map +1 -1
- package/lib/hw/connectManager.js +9 -0
- package/lib/hw/connectManager.js.map +1 -1
- package/lib/hw/customLockScreenLoad.d.ts.map +1 -1
- package/lib/hw/customLockScreenLoad.js +22 -18
- package/lib/hw/customLockScreenLoad.js.map +1 -1
- package/lib/hw/customLockScreenLoad.test.d.ts +2 -0
- package/lib/hw/customLockScreenLoad.test.d.ts.map +1 -0
- package/lib/hw/customLockScreenLoad.test.js +63 -0
- package/lib/hw/customLockScreenLoad.test.js.map +1 -0
- package/lib/hw/extractOnboardingState.d.ts +15 -2
- package/lib/hw/extractOnboardingState.d.ts.map +1 -1
- package/lib/hw/extractOnboardingState.js +67 -19
- package/lib/hw/extractOnboardingState.js.map +1 -1
- package/lib/hw/extractOnboardingState.test.js +96 -1
- package/lib/hw/extractOnboardingState.test.js.map +1 -1
- package/lib/hw/getDeviceInfo.d.ts.map +1 -1
- package/lib/hw/getDeviceInfo.js +3 -1
- package/lib/hw/getDeviceInfo.js.map +1 -1
- package/lib/hw/getGenuineCheckFromDeviceId.test.js +1 -0
- package/lib/hw/getGenuineCheckFromDeviceId.test.js.map +1 -1
- package/lib/hw/getOnboardingStatePolling.js +1 -1
- package/lib/hw/getOnboardingStatePolling.js.map +1 -1
- package/lib/hw/getOnboardingStatePolling.test.js +2 -0
- package/lib/hw/getOnboardingStatePolling.test.js.map +1 -1
- package/lib/hw/isFirmwareUpdateVersionSupported.test.js +2 -1
- package/lib/hw/isFirmwareUpdateVersionSupported.test.js.map +1 -1
- package/lib/mock/fixtures/aDeviceInfo.d.ts.map +1 -1
- package/lib/mock/fixtures/aDeviceInfo.js +1 -0
- package/lib/mock/fixtures/aDeviceInfo.js.map +1 -1
- package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts +2 -0
- package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts.map +1 -0
- package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js +107 -0
- package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +1 -0
- package/lib/modularDrawer/enums.d.ts +8 -0
- package/lib/modularDrawer/enums.d.ts.map +1 -0
- package/lib/modularDrawer/enums.js +12 -0
- package/lib/modularDrawer/enums.js.map +1 -0
- package/lib/modularDrawer/useModularDrawerVisibility.d.ts +9 -0
- package/lib/modularDrawer/useModularDrawerVisibility.d.ts.map +1 -0
- package/lib/modularDrawer/useModularDrawerVisibility.js +18 -0
- package/lib/modularDrawer/useModularDrawerVisibility.js.map +1 -0
- package/lib/onboarding/hooks/useOnboardingStatePolling.test.js +2 -0
- package/lib/onboarding/hooks/useOnboardingStatePolling.test.js.map +1 -1
- package/lib/wallet-api/types.d.ts +1 -1
- package/lib/wallet-api/types.d.ts.map +1 -1
- package/lib/wallet-api/useDappLogic.d.ts.map +1 -1
- package/lib/wallet-api/useDappLogic.js +3 -24
- package/lib/wallet-api/useDappLogic.js.map +1 -1
- package/lib/wallet-api/utils/txTrackingHelper.d.ts +3 -0
- package/lib/wallet-api/utils/txTrackingHelper.d.ts.map +1 -0
- package/lib/wallet-api/utils/txTrackingHelper.js +16 -0
- package/lib/wallet-api/utils/txTrackingHelper.js.map +1 -0
- package/lib/wallet-api/utils/txTrackingHelper.test.d.ts +2 -0
- package/lib/wallet-api/utils/txTrackingHelper.test.d.ts.map +1 -0
- package/lib/wallet-api/utils/txTrackingHelper.test.js +70 -0
- package/lib/wallet-api/utils/txTrackingHelper.test.js.map +1 -0
- package/lib-es/__tests__/hw/getLatestFirmwareForDevice.js +4 -0
- package/lib-es/__tests__/hw/getLatestFirmwareForDevice.js.map +1 -1
- package/lib-es/__tests__/test-helpers/deviceInfos.d.ts.map +1 -1
- package/lib-es/__tests__/test-helpers/deviceInfos.js +5 -0
- package/lib-es/__tests__/test-helpers/deviceInfos.js.map +1 -1
- package/lib-es/apps/mock.d.ts +2 -32
- package/lib-es/apps/mock.d.ts.map +1 -1
- package/lib-es/apps/mock.js +3 -0
- package/lib-es/apps/mock.js.map +1 -1
- package/lib-es/apps/polyfill.d.ts +4 -1
- package/lib-es/apps/polyfill.d.ts.map +1 -1
- package/lib-es/bridge/cache.d.ts.map +1 -1
- package/lib-es/bridge/cache.js +2 -2
- package/lib-es/bridge/cache.js.map +1 -1
- package/lib-es/bridge/cache.test.d.ts +2 -0
- package/lib-es/bridge/cache.test.d.ts.map +1 -0
- package/lib-es/bridge/cache.test.js +38 -0
- package/lib-es/bridge/cache.test.js.map +1 -0
- package/lib-es/deposit/deposit.test.js +419 -75
- package/lib-es/deposit/deposit.test.js.map +1 -1
- package/lib-es/deposit/helper.d.ts +1 -0
- package/lib-es/deposit/helper.d.ts.map +1 -1
- package/lib-es/deposit/helper.js +18 -6
- package/lib-es/deposit/helper.js.map +1 -1
- package/lib-es/deviceSDK/tasks/getDeviceInfo.d.ts.map +1 -1
- package/lib-es/deviceSDK/tasks/getDeviceInfo.js +3 -1
- package/lib-es/deviceSDK/tasks/getDeviceInfo.js.map +1 -1
- package/lib-es/e2e/enum/Provider.d.ts +1 -1
- package/lib-es/e2e/enum/Provider.d.ts.map +1 -1
- package/lib-es/e2e/enum/Provider.js +1 -1
- package/lib-es/e2e/enum/Provider.js.map +1 -1
- package/lib-es/e2e/index.d.ts +5 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/e2e/swap.d.ts.map +1 -1
- package/lib-es/e2e/swap.js +10 -7
- package/lib-es/e2e/swap.js.map +1 -1
- package/lib-es/env.react.d.ts +1 -1
- package/lib-es/env.react.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +35 -0
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/hooks/useAppVersionBlockCheck.d.ts +11 -0
- package/lib-es/hooks/useAppVersionBlockCheck.d.ts.map +1 -0
- package/lib-es/hooks/useAppVersionBlockCheck.js +25 -0
- package/lib-es/hooks/useAppVersionBlockCheck.js.map +1 -0
- package/lib-es/hooks/useAppVersionBlockCheck.test.d.ts +2 -0
- package/lib-es/hooks/useAppVersionBlockCheck.test.d.ts.map +1 -0
- package/lib-es/hooks/useAppVersionBlockCheck.test.js +131 -0
- package/lib-es/hooks/useAppVersionBlockCheck.test.js.map +1 -0
- package/lib-es/hw/connectAppEventMapper.d.ts.map +1 -1
- package/lib-es/hw/connectAppEventMapper.js +3 -1
- package/lib-es/hw/connectAppEventMapper.js.map +1 -1
- package/lib-es/hw/connectManager.d.ts.map +1 -1
- package/lib-es/hw/connectManager.js +9 -0
- package/lib-es/hw/connectManager.js.map +1 -1
- package/lib-es/hw/customLockScreenLoad.d.ts.map +1 -1
- package/lib-es/hw/customLockScreenLoad.js +22 -18
- package/lib-es/hw/customLockScreenLoad.js.map +1 -1
- package/lib-es/hw/customLockScreenLoad.test.d.ts +2 -0
- package/lib-es/hw/customLockScreenLoad.test.d.ts.map +1 -0
- package/lib-es/hw/customLockScreenLoad.test.js +58 -0
- package/lib-es/hw/customLockScreenLoad.test.js.map +1 -0
- package/lib-es/hw/extractOnboardingState.d.ts +15 -2
- package/lib-es/hw/extractOnboardingState.d.ts.map +1 -1
- package/lib-es/hw/extractOnboardingState.js +66 -18
- package/lib-es/hw/extractOnboardingState.js.map +1 -1
- package/lib-es/hw/extractOnboardingState.test.js +97 -2
- package/lib-es/hw/extractOnboardingState.test.js.map +1 -1
- package/lib-es/hw/getDeviceInfo.d.ts.map +1 -1
- package/lib-es/hw/getDeviceInfo.js +3 -1
- package/lib-es/hw/getDeviceInfo.js.map +1 -1
- package/lib-es/hw/getGenuineCheckFromDeviceId.test.js +1 -0
- package/lib-es/hw/getGenuineCheckFromDeviceId.test.js.map +1 -1
- package/lib-es/hw/getOnboardingStatePolling.js +1 -1
- package/lib-es/hw/getOnboardingStatePolling.js.map +1 -1
- package/lib-es/hw/getOnboardingStatePolling.test.js +2 -0
- package/lib-es/hw/getOnboardingStatePolling.test.js.map +1 -1
- package/lib-es/hw/isFirmwareUpdateVersionSupported.test.js +2 -1
- package/lib-es/hw/isFirmwareUpdateVersionSupported.test.js.map +1 -1
- package/lib-es/mock/fixtures/aDeviceInfo.d.ts.map +1 -1
- package/lib-es/mock/fixtures/aDeviceInfo.js +1 -0
- package/lib-es/mock/fixtures/aDeviceInfo.js.map +1 -1
- package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts +2 -0
- package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.d.ts.map +1 -0
- package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js +105 -0
- package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +1 -0
- package/lib-es/modularDrawer/enums.d.ts +8 -0
- package/lib-es/modularDrawer/enums.d.ts.map +1 -0
- package/lib-es/modularDrawer/enums.js +9 -0
- package/lib-es/modularDrawer/enums.js.map +1 -0
- package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts +9 -0
- package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts.map +1 -0
- package/lib-es/modularDrawer/useModularDrawerVisibility.js +14 -0
- package/lib-es/modularDrawer/useModularDrawerVisibility.js.map +1 -0
- package/lib-es/onboarding/hooks/useOnboardingStatePolling.test.js +2 -0
- package/lib-es/onboarding/hooks/useOnboardingStatePolling.test.js.map +1 -1
- package/lib-es/wallet-api/types.d.ts +1 -1
- package/lib-es/wallet-api/types.d.ts.map +1 -1
- package/lib-es/wallet-api/useDappLogic.d.ts.map +1 -1
- package/lib-es/wallet-api/useDappLogic.js +3 -24
- package/lib-es/wallet-api/useDappLogic.js.map +1 -1
- package/lib-es/wallet-api/utils/txTrackingHelper.d.ts +3 -0
- package/lib-es/wallet-api/utils/txTrackingHelper.d.ts.map +1 -0
- package/lib-es/wallet-api/utils/txTrackingHelper.js +12 -0
- package/lib-es/wallet-api/utils/txTrackingHelper.js.map +1 -0
- package/lib-es/wallet-api/utils/txTrackingHelper.test.d.ts +2 -0
- package/lib-es/wallet-api/utils/txTrackingHelper.test.d.ts.map +1 -0
- package/lib-es/wallet-api/utils/txTrackingHelper.test.js +68 -0
- package/lib-es/wallet-api/utils/txTrackingHelper.test.js.map +1 -0
- package/package.json +49 -49
- package/src/__tests__/hw/getLatestFirmwareForDevice.ts +8 -3
- package/src/__tests__/test-helpers/deviceInfos.ts +5 -0
- package/src/apps/mock.ts +5 -2
- package/src/bridge/cache.test.ts +46 -0
- package/src/bridge/cache.ts +5 -2
- package/src/deposit/deposit.test.ts +611 -136
- package/src/deposit/helper.ts +27 -9
- package/src/deviceSDK/tasks/getDeviceInfo.ts +3 -0
- package/src/e2e/enum/Provider.ts +1 -1
- package/src/e2e/swap.ts +12 -7
- package/src/featureFlags/defaultFeatures.ts +35 -0
- package/src/hooks/useAppVersionBlockCheck.test.ts +134 -0
- package/src/hooks/useAppVersionBlockCheck.ts +65 -0
- package/src/hw/connectAppEventMapper.ts +3 -1
- package/src/hw/connectManager.ts +18 -0
- package/src/hw/customLockScreenLoad.test.ts +86 -0
- package/src/hw/customLockScreenLoad.ts +31 -17
- package/src/hw/extractOnboardingState.test.ts +122 -2
- package/src/hw/extractOnboardingState.ts +81 -18
- package/src/hw/getDeviceInfo.ts +4 -1
- package/src/hw/getGenuineCheckFromDeviceId.test.ts +2 -1
- package/src/hw/getOnboardingStatePolling.test.ts +2 -0
- package/src/hw/getOnboardingStatePolling.ts +1 -1
- package/src/hw/isFirmwareUpdateVersionSupported.test.ts +3 -1
- package/src/mock/fixtures/aDeviceInfo.ts +1 -0
- package/src/modularDrawer/__test__/useModularDrawerVisibility.test.ts +149 -0
- package/src/modularDrawer/enums.ts +7 -0
- package/src/modularDrawer/useModularDrawerVisibility.ts +25 -0
- package/src/onboarding/hooks/useOnboardingStatePolling.test.ts +2 -0
- package/src/wallet-api/types.ts +1 -1
- package/src/wallet-api/useDappLogic.ts +4 -27
- package/src/wallet-api/utils/txTrackingHelper.test.ts +80 -0
- package/src/wallet-api/utils/txTrackingHelper.ts +14 -0
package/lib-es/bridge/cache.js
CHANGED
@@ -11,14 +11,14 @@ export function makeBridgeCacheSystem({ saveData, getData, }) {
|
|
11
11
|
return value;
|
12
12
|
};
|
13
13
|
const lruCaches = {};
|
14
|
-
const prepareCurrency = async (currency) => {
|
14
|
+
const prepareCurrency = async (currency, { forceUpdate } = { forceUpdate: false }) => {
|
15
15
|
const bridge = getCurrencyBridge(currency);
|
16
16
|
const { preloadMaxAge } = {
|
17
17
|
...defaultCacheStrategy,
|
18
18
|
...(bridge.getPreloadStrategy && bridge.getPreloadStrategy(currency)),
|
19
19
|
};
|
20
20
|
let cache = lruCaches[currency.id];
|
21
|
-
if (!cache) {
|
21
|
+
if (!cache || forceUpdate) {
|
22
22
|
cache = makeLRUCache(async () => {
|
23
23
|
const preloaded = await bridge.preload(currency);
|
24
24
|
if (preloaded) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/bridge/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAEvC,MAAM,oBAAoB,GAAG;IAC3B,aAAa,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;CAC7B,CAAC;AACF,MAAM,UAAU,qBAAqB,CAAC,EACpC,QAAQ,EACR,OAAO,GAIR;IACC,MAAM,eAAe,GAAG,KAAK,EAAE,QAAwB,EAAE,EAAE;QACzD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC3C,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,MAAM,eAAe,GAAG,KAAK,
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/bridge/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAEvC,MAAM,oBAAoB,GAAG;IAC3B,aAAa,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;CAC7B,CAAC;AACF,MAAM,UAAU,qBAAqB,CAAC,EACpC,QAAQ,EACR,OAAO,GAIR;IACC,MAAM,eAAe,GAAG,KAAK,EAAE,QAAwB,EAAE,EAAE;QACzD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC3C,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,MAAM,eAAe,GAAG,KAAK,EAC3B,QAAwB,EACxB,EAAE,WAAW,KAA+B,EAAE,WAAW,EAAE,KAAK,EAAE,EAClE,EAAE;QACF,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC3C,MAAM,EAAE,aAAa,EAAE,GAAG;YACxB,GAAG,oBAAoB;YACvB,GAAG,CAAC,MAAM,CAAC,kBAAkB,IAAI,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;SACtE,CAAC;QACF,IAAI,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEnC,IAAI,CAAC,KAAK,IAAI,WAAW,EAAE;YACzB,KAAK,GAAG,YAAY,CAClB,KAAK,IAAI,EAAE;gBACT,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAEjD,IAAI,SAAS,EAAE;oBACb,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;oBACpC,MAAM,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;iBACrC;gBAED,OAAO,SAAS,CAAC;YACnB,CAAC,EACD,GAAG,EAAE,CAAC,EAAE,EACR;gBACE,GAAG,EAAE,aAAa;aACnB,CACF,CAAC;YACF,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;SAChC;QAED,OAAO,KAAK,EAAE,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO;QACL,eAAe;QACf,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cache.test.d.ts","sourceRoot":"","sources":["../../src/bridge/cache.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as cacheModule from "@ledgerhq/live-network/cache";
|
2
|
+
import { makeBridgeCacheSystem } from "./cache";
|
3
|
+
import { getCryptoCurrencyById } from "../currencies";
|
4
|
+
import { setEnv } from "@ledgerhq/live-env";
|
5
|
+
describe("Bridge Cache", () => {
|
6
|
+
beforeEach(() => {
|
7
|
+
jest.clearAllMocks();
|
8
|
+
});
|
9
|
+
beforeAll(() => {
|
10
|
+
setEnv("MOCK", "1");
|
11
|
+
});
|
12
|
+
afterAll(() => {
|
13
|
+
setEnv("MOCK", "");
|
14
|
+
});
|
15
|
+
it("does not re-generate the LRU cache by default", async () => {
|
16
|
+
const makeLRUCache = jest.spyOn(cacheModule, "makeLRUCache");
|
17
|
+
const { prepareCurrency } = makeBridgeCacheSystem({
|
18
|
+
saveData: () => Promise.resolve(),
|
19
|
+
getData: () => Promise.resolve(null),
|
20
|
+
});
|
21
|
+
await prepareCurrency(getCryptoCurrencyById("solana"));
|
22
|
+
expect(makeLRUCache).toHaveBeenCalledTimes(1);
|
23
|
+
await prepareCurrency(getCryptoCurrencyById("solana"));
|
24
|
+
expect(makeLRUCache).toHaveBeenCalledTimes(1);
|
25
|
+
});
|
26
|
+
it("forces the LRU cache to be re-generated", async () => {
|
27
|
+
const makeLRUCache = jest.spyOn(cacheModule, "makeLRUCache");
|
28
|
+
const { prepareCurrency } = makeBridgeCacheSystem({
|
29
|
+
saveData: () => Promise.resolve(),
|
30
|
+
getData: () => Promise.resolve(null),
|
31
|
+
});
|
32
|
+
await prepareCurrency(getCryptoCurrencyById("solana"));
|
33
|
+
expect(makeLRUCache).toHaveBeenCalledTimes(1);
|
34
|
+
await prepareCurrency(getCryptoCurrencyById("solana"), { forceUpdate: true });
|
35
|
+
expect(makeLRUCache).toHaveBeenCalledTimes(2);
|
36
|
+
});
|
37
|
+
});
|
38
|
+
//# sourceMappingURL=cache.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cache.test.js","sourceRoot":"","sources":["../../src/bridge/cache.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,GAAG,EAAE;QACZ,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAC7D,MAAM,EAAE,eAAe,EAAE,GAAG,qBAAqB,CAAC;YAChD,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;YACjC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;SACrC,CAAC,CAAC;QAEH,MAAM,eAAe,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAE9C,MAAM,eAAe,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAC7D,MAAM,EAAE,eAAe,EAAE,GAAG,qBAAqB,CAAC;YAChD,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;YACjC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;SACrC,CAAC,CAAC;QAEH,MAAM,eAAe,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAE9C,MAAM,eAAe,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9E,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { groupCurrenciesByProvider, searchByNameOrTicker, searchByProviderId } from "./helper";
|
1
|
+
import { groupCurrenciesByProvider, searchByNameOrTicker, searchByProviderId, loadCurrenciesByProvider, getTokenOrCryptoCurrencyById, } from "./helper";
|
2
2
|
import { MOCK_TOKENS_ONLY, MOCK_WITH_TOKEN_AND_CURRENCY_ASSET, MOCK_IDS, MOCK_POL } from "./mock";
|
3
3
|
import { getCryptoCurrencyById, getTokenById, setSupportedCurrencies, sortCurrenciesByIds, } from "../currencies/index";
|
4
4
|
import { isCurrencySupported, listSupportedCurrencies, listTokens } from "../currencies";
|
@@ -8,88 +8,432 @@ describe("Deposit logic", () => {
|
|
8
8
|
afterEach(() => {
|
9
9
|
setSupportedCurrencies([]);
|
10
10
|
});
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
describe("searchByProviderId", () => {
|
12
|
+
test("should find assets by provider ID", () => {
|
13
|
+
const result = searchByProviderId(TOKEN_ONLY_ASSETS, "tether");
|
14
|
+
expect(result).toEqual(TOKEN_ONLY_ASSETS);
|
15
|
+
});
|
16
|
+
test("should return empty array for non-existent provider ID", () => {
|
17
|
+
const result = searchByProviderId(TOKEN_ONLY_ASSETS, "non-existent-provider");
|
18
|
+
expect(result).toEqual([]);
|
19
|
+
});
|
20
|
+
test("should handle case insensitive search", () => {
|
21
|
+
const result = searchByProviderId(TOKEN_ONLY_ASSETS, "TETHER");
|
22
|
+
expect(result).toEqual(TOKEN_ONLY_ASSETS);
|
23
|
+
});
|
24
|
+
test("should handle empty assets list", () => {
|
25
|
+
const result = searchByProviderId([], "tether");
|
26
|
+
expect(result).toEqual([]);
|
27
|
+
});
|
28
|
+
test("should handle empty provider ID", () => {
|
29
|
+
const result = searchByProviderId(TOKEN_ONLY_ASSETS, "");
|
30
|
+
expect(result).toEqual([]);
|
31
|
+
});
|
32
|
+
test("should handle special characters in provider ID", () => {
|
33
|
+
const mockAssets = [
|
34
|
+
{ ...TOKEN_ONLY_ASSETS[0], providerId: "test-provider_123" },
|
35
|
+
];
|
36
|
+
const result = searchByProviderId(mockAssets, "test-provider_123");
|
37
|
+
expect(result).toHaveLength(1);
|
38
|
+
});
|
14
39
|
});
|
15
|
-
|
16
|
-
|
17
|
-
|
40
|
+
describe("searchByNameOrTicker", () => {
|
41
|
+
test("should find assets by name or ticker", () => {
|
42
|
+
const result = searchByNameOrTicker(TOKEN_ONLY_ASSETS, "usdt");
|
43
|
+
expect(result.length).toBeGreaterThan(0);
|
44
|
+
});
|
45
|
+
test("should handle case insensitive search", () => {
|
46
|
+
const result = searchByNameOrTicker(TOKEN_ONLY_ASSETS, "USDT");
|
47
|
+
expect(result.length).toBeGreaterThan(0);
|
48
|
+
});
|
49
|
+
test("should find partial matches", () => {
|
50
|
+
const result = searchByNameOrTicker(TOKEN_ONLY_ASSETS, "usd");
|
51
|
+
expect(result.length).toBeGreaterThan(0);
|
52
|
+
});
|
53
|
+
test("should return empty array for non-matching search", () => {
|
54
|
+
const result = searchByNameOrTicker(TOKEN_ONLY_ASSETS, "non-existent-token");
|
55
|
+
expect(result).toEqual([]);
|
56
|
+
});
|
57
|
+
test("should handle empty search term", () => {
|
58
|
+
const result = searchByNameOrTicker(TOKEN_ONLY_ASSETS, "");
|
59
|
+
expect(result).toEqual(TOKEN_ONLY_ASSETS);
|
60
|
+
});
|
61
|
+
test("should handle empty assets list", () => {
|
62
|
+
const result = searchByNameOrTicker([], "usdt");
|
63
|
+
expect(result).toEqual([]);
|
64
|
+
});
|
65
|
+
test("should search in both name and ticker fields", () => {
|
66
|
+
const mockAssets = [
|
67
|
+
{ ...TOKEN_ONLY_ASSETS[0], name: "Test Token", ticker: "TTK" },
|
68
|
+
{ ...TOKEN_ONLY_ASSETS[0], name: "Another Token", ticker: "USDT" },
|
69
|
+
];
|
70
|
+
const nameResult = searchByNameOrTicker(mockAssets, "Test");
|
71
|
+
const tickerResult = searchByNameOrTicker(mockAssets, "USDT");
|
72
|
+
expect(nameResult).toHaveLength(1);
|
73
|
+
expect(tickerResult).toHaveLength(1);
|
74
|
+
});
|
18
75
|
});
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
76
|
+
describe("groupCurrenciesByProvider", () => {
|
77
|
+
test("should group currencies by provider", () => {
|
78
|
+
const currencies = TOKEN_ONLY_ASSETS.map(asset => getTokenById(asset.ledgerId));
|
79
|
+
const { currenciesByProvider } = groupCurrenciesByProvider(TOKEN_ONLY_ASSETS, currencies);
|
80
|
+
expect(currenciesByProvider).toEqual([
|
81
|
+
{
|
82
|
+
providerId: "tether",
|
83
|
+
currenciesByNetwork: currencies,
|
84
|
+
},
|
85
|
+
]);
|
86
|
+
});
|
87
|
+
test("should handle POL assets correctly", () => {
|
88
|
+
const currenciesPol = MOCK_POL.map(asset => asset.$type === "Token"
|
89
|
+
? getTokenById(asset.ledgerId)
|
90
|
+
: getCryptoCurrencyById(asset.ledgerId));
|
91
|
+
const { currenciesByProvider: currenciesByProviderBis, sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_POL, currenciesPol);
|
92
|
+
expect(currenciesByProviderBis).toEqual([
|
93
|
+
{
|
94
|
+
providerId: "matic-network",
|
95
|
+
currenciesByNetwork: currenciesPol,
|
96
|
+
},
|
97
|
+
]);
|
98
|
+
expect(sortedCryptoCurrencies).toEqual([currenciesPol[1]]);
|
99
|
+
});
|
100
|
+
test("should handle empty assets array", () => {
|
101
|
+
const currencies = TOKEN_ONLY_ASSETS.map(asset => getTokenById(asset.ledgerId));
|
102
|
+
const { currenciesByProvider, sortedCryptoCurrencies } = groupCurrenciesByProvider([], currencies);
|
103
|
+
expect(currenciesByProvider).toEqual([]);
|
104
|
+
expect(sortedCryptoCurrencies).toEqual([]);
|
105
|
+
});
|
106
|
+
test("should handle empty currencies array", () => {
|
107
|
+
const { currenciesByProvider, sortedCryptoCurrencies } = groupCurrenciesByProvider(TOKEN_ONLY_ASSETS, []);
|
108
|
+
expect(currenciesByProvider).toEqual([]);
|
109
|
+
expect(sortedCryptoCurrencies).toEqual([]);
|
110
|
+
});
|
111
|
+
test("should handle currencies without corresponding assets", () => {
|
112
|
+
setSupportedCurrencies(["bitcoin"]);
|
113
|
+
const btcCurrency = getCryptoCurrencyById("bitcoin");
|
114
|
+
const { currenciesByProvider, sortedCryptoCurrencies } = groupCurrenciesByProvider(TOKEN_ONLY_ASSETS, [btcCurrency]);
|
115
|
+
expect(currenciesByProvider).toEqual([]);
|
116
|
+
expect(sortedCryptoCurrencies).toEqual([]);
|
117
|
+
});
|
118
|
+
test("should prioritize crypto currencies over tokens in sortedCryptoCurrencies", () => {
|
119
|
+
const mockAssets = [
|
120
|
+
{ ...TOKEN_ONLY_ASSETS[0], providerId: "test-provider" },
|
121
|
+
];
|
122
|
+
setSupportedCurrencies(["ethereum"]);
|
123
|
+
const ethCurrency = getCryptoCurrencyById("ethereum");
|
124
|
+
const tokenCurrency = getTokenById(TOKEN_ONLY_ASSETS[0].ledgerId);
|
125
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(mockAssets, [
|
126
|
+
tokenCurrency,
|
127
|
+
ethCurrency,
|
128
|
+
]);
|
129
|
+
expect(sortedCryptoCurrencies.length).toBeGreaterThan(0);
|
130
|
+
});
|
131
|
+
test("should handle duplicate provider IDs correctly", () => {
|
132
|
+
const duplicateAssets = [
|
133
|
+
TOKEN_ONLY_ASSETS[0],
|
134
|
+
{ ...TOKEN_ONLY_ASSETS[0], ledgerId: "different-id" },
|
135
|
+
];
|
136
|
+
const currencies = [getTokenById(TOKEN_ONLY_ASSETS[0].ledgerId)];
|
137
|
+
const { currenciesByProvider } = groupCurrenciesByProvider(duplicateAssets, currencies);
|
138
|
+
expect(currenciesByProvider).toHaveLength(1);
|
139
|
+
expect(currenciesByProvider[0].currenciesByNetwork).toHaveLength(1);
|
140
|
+
});
|
41
141
|
});
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
142
|
+
describe("getTokenOrCryptoCurrencyById", () => {
|
143
|
+
test("should return crypto currency by ID", () => {
|
144
|
+
const result = getTokenOrCryptoCurrencyById("bitcoin");
|
145
|
+
expect(result).toBeDefined();
|
146
|
+
expect(result.type).toBe("CryptoCurrency");
|
147
|
+
});
|
148
|
+
test("should return token by ID", () => {
|
149
|
+
const result = getTokenOrCryptoCurrencyById("ethereum/erc20/usd_tether__erc20_");
|
150
|
+
expect(result).toBeDefined();
|
151
|
+
expect(result.type).toBe("TokenCurrency");
|
152
|
+
});
|
153
|
+
test("should handle invalid crypto currency ID", () => {
|
154
|
+
expect(() => getTokenOrCryptoCurrencyById("invalid-crypto-id")).toThrow();
|
155
|
+
});
|
156
|
+
test("should handle invalid token ID", () => {
|
157
|
+
expect(() => getTokenOrCryptoCurrencyById("invalid/token/id")).toThrow();
|
158
|
+
});
|
159
|
+
test("should handle empty ID", () => {
|
160
|
+
expect(() => getTokenOrCryptoCurrencyById("")).toThrow();
|
161
|
+
});
|
47
162
|
});
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
163
|
+
describe("loadCurrenciesByProvider", () => {
|
164
|
+
test("should load currencies by provider successfully", async () => {
|
165
|
+
setSupportedCurrencies(["ethereum", "bitcoin"]);
|
166
|
+
const supportedCurrencies = listSupportedCurrencies();
|
167
|
+
const result = await loadCurrenciesByProvider(supportedCurrencies);
|
168
|
+
expect(result).toBeDefined();
|
169
|
+
expect(result.currenciesByProvider).toBeDefined();
|
170
|
+
expect(result.sortedCryptoCurrencies).toBeDefined();
|
171
|
+
expect(Array.isArray(result.currenciesByProvider)).toBe(true);
|
172
|
+
expect(Array.isArray(result.sortedCryptoCurrencies)).toBe(true);
|
173
|
+
});
|
174
|
+
test("should handle empty currencies array", async () => {
|
175
|
+
const result = await loadCurrenciesByProvider([]);
|
176
|
+
expect(result).toBeDefined();
|
177
|
+
expect(result.currenciesByProvider).toEqual([]);
|
178
|
+
expect(result.sortedCryptoCurrencies).toEqual([]);
|
179
|
+
});
|
180
|
+
test("should handle currencies with no corresponding assets", async () => {
|
181
|
+
setSupportedCurrencies(["bitcoin"]);
|
182
|
+
const supportedCurrencies = [getCryptoCurrencyById("bitcoin")];
|
183
|
+
const result = await loadCurrenciesByProvider(supportedCurrencies);
|
184
|
+
expect(result).toBeDefined();
|
185
|
+
expect(Array.isArray(result.currenciesByProvider)).toBe(true);
|
186
|
+
expect(Array.isArray(result.sortedCryptoCurrencies)).toBe(true);
|
187
|
+
});
|
53
188
|
});
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
getCryptoCurrencyById("
|
60
|
-
|
61
|
-
|
189
|
+
describe("Currency support scenarios", () => {
|
190
|
+
it("should return Arbitrum and not Optimism in the sortedCryptoCurrencies", () => {
|
191
|
+
setSupportedCurrencies(["arbitrum", "arbitrum_sepolia"]);
|
192
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
193
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_WITH_TOKEN_AND_CURRENCY_ASSET, currencies);
|
194
|
+
expect(sortedCryptoCurrencies).toEqual([getCryptoCurrencyById("arbitrum")]);
|
195
|
+
});
|
196
|
+
it("should return Optimism only in the sortedCryptoCurrencies", () => {
|
197
|
+
setSupportedCurrencies(["optimism", "optimism_sepolia"]);
|
198
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
199
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_WITH_TOKEN_AND_CURRENCY_ASSET, currencies);
|
200
|
+
expect(sortedCryptoCurrencies).toEqual([getCryptoCurrencyById("optimism")]);
|
201
|
+
});
|
202
|
+
it("should return currencies based on what's actually supported and available in mock data", () => {
|
203
|
+
setSupportedCurrencies(["optimism", "optimism_sepolia", "arbitrum", "arbitrum_sepolia"]);
|
204
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
205
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_WITH_TOKEN_AND_CURRENCY_ASSET, currencies);
|
206
|
+
expect(Array.isArray(sortedCryptoCurrencies)).toBe(true);
|
207
|
+
expect(sortedCryptoCurrencies.length).toBeGreaterThanOrEqual(0);
|
208
|
+
sortedCryptoCurrencies.forEach(currency => {
|
209
|
+
expect(["optimism", "arbitrum"].includes(currency.id)).toBe(true);
|
210
|
+
});
|
211
|
+
});
|
62
212
|
});
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
213
|
+
describe("Token-only scenarios", () => {
|
214
|
+
it("should return only Polygon token while its currency is supported in the list", () => {
|
215
|
+
setSupportedCurrencies(["polygon"]);
|
216
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
217
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_TOKENS_ONLY, currencies);
|
218
|
+
expect(sortedCryptoCurrencies).toEqual([getTokenById("polygon/erc20/(pos)_tether_usd")]);
|
219
|
+
});
|
220
|
+
it("should return only BSC token while its currency is supported in the list", () => {
|
221
|
+
setSupportedCurrencies(["bsc"]);
|
222
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
223
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_TOKENS_ONLY, currencies);
|
224
|
+
expect(sortedCryptoCurrencies).toEqual([getTokenById("bsc/bep20/binance-peg_bsc-usd")]);
|
225
|
+
});
|
226
|
+
it("should return tokens that are actually supported based on mock data", () => {
|
227
|
+
setSupportedCurrencies(["ethereum", "bsc", "polygon"]);
|
228
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
229
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_TOKENS_ONLY, currencies);
|
230
|
+
expect(Array.isArray(sortedCryptoCurrencies)).toBe(true);
|
231
|
+
expect(sortedCryptoCurrencies.length).toBeGreaterThanOrEqual(0);
|
232
|
+
sortedCryptoCurrencies.forEach(currency => {
|
233
|
+
expect(currency.type).toBe("TokenCurrency");
|
234
|
+
expect(["ethereum", "polygon", "bsc"].some(network => currency.id.includes(network))).toBe(true);
|
235
|
+
});
|
236
|
+
});
|
237
|
+
it("should return specific Ethereum and Polygon USDT tokens when both currencies are supported", () => {
|
238
|
+
setSupportedCurrencies(["ethereum", "polygon"]);
|
239
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
240
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_TOKENS_ONLY, currencies);
|
241
|
+
expect(Array.isArray(sortedCryptoCurrencies)).toBe(true);
|
242
|
+
expect(sortedCryptoCurrencies.length).toBeGreaterThan(0);
|
243
|
+
const tokenIds = sortedCryptoCurrencies.map(currency => currency.id);
|
244
|
+
expect(tokenIds).toContain("ethereum/erc20/usd_tether__erc20_");
|
245
|
+
sortedCryptoCurrencies.forEach(currency => {
|
246
|
+
expect(currency.type).toBe("TokenCurrency");
|
247
|
+
expect(currency.id).toMatch(/tether|usdt/i);
|
248
|
+
});
|
249
|
+
});
|
250
|
+
it("should return all supported USDT tokens when multiple currencies are enabled", () => {
|
251
|
+
setSupportedCurrencies(["ethereum", "bsc", "polygon"]);
|
252
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
253
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider(MOCK_TOKENS_ONLY, currencies);
|
254
|
+
expect(Array.isArray(sortedCryptoCurrencies)).toBe(true);
|
255
|
+
expect(sortedCryptoCurrencies.length).toBeGreaterThan(0);
|
256
|
+
const tokenIds = sortedCryptoCurrencies.map(currency => currency.id);
|
257
|
+
expect(tokenIds).toContain("ethereum/erc20/usd_tether__erc20_");
|
258
|
+
sortedCryptoCurrencies.forEach(currency => {
|
259
|
+
expect(currency.type).toBe("TokenCurrency");
|
260
|
+
});
|
261
|
+
const hasExpectedNetworks = sortedCryptoCurrencies.every(currency => ["ethereum", "polygon", "bsc"].some(network => currency.id.includes(network)));
|
262
|
+
expect(hasExpectedNetworks).toBe(true);
|
263
|
+
});
|
264
|
+
it("should return empty array when no supported currencies", () => {
|
265
|
+
setSupportedCurrencies([]);
|
266
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
267
|
+
const { sortedCryptoCurrencies } = groupCurrenciesByProvider([...TOKEN_ONLY_ASSETS, ...MOCK_WITH_TOKEN_AND_CURRENCY_ASSET], currencies);
|
268
|
+
expect(sortedCryptoCurrencies).toEqual([]);
|
269
|
+
});
|
70
270
|
});
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
271
|
+
describe("Comprehensive integration tests", () => {
|
272
|
+
it("should handle all supported currencies and tokens in the system", async () => {
|
273
|
+
// Set all major supported currencies from the live-common setup
|
274
|
+
setSupportedCurrencies([
|
275
|
+
"bitcoin",
|
276
|
+
"ethereum",
|
277
|
+
"bsc",
|
278
|
+
"polygon",
|
279
|
+
"arbitrum",
|
280
|
+
"optimism",
|
281
|
+
"avalanche_c_chain",
|
282
|
+
"solana",
|
283
|
+
"cardano",
|
284
|
+
"polkadot",
|
285
|
+
"cosmos",
|
286
|
+
"tron",
|
287
|
+
"stellar",
|
288
|
+
"hedera",
|
289
|
+
"near",
|
290
|
+
"sui",
|
291
|
+
]);
|
292
|
+
const allSupportedCurrencies = listSupportedCurrencies();
|
293
|
+
const allSupportedTokens = listSupportedTokens();
|
294
|
+
// Test the full loadCurrenciesByProvider functionality
|
295
|
+
const result = await loadCurrenciesByProvider(allSupportedCurrencies.concat(allSupportedTokens));
|
296
|
+
// Comprehensive validation
|
297
|
+
expect(result).toBeDefined();
|
298
|
+
expect(result.currenciesByProvider).toBeDefined();
|
299
|
+
expect(result.sortedCryptoCurrencies).toBeDefined();
|
300
|
+
expect(Array.isArray(result.currenciesByProvider)).toBe(true);
|
301
|
+
expect(Array.isArray(result.sortedCryptoCurrencies)).toBe(true);
|
302
|
+
// Should have meaningful results with this many currencies
|
303
|
+
expect(result.currenciesByProvider.length).toBeGreaterThan(0);
|
304
|
+
expect(result.sortedCryptoCurrencies.length).toBeGreaterThan(0);
|
305
|
+
// Validate structure of each provider group
|
306
|
+
result.currenciesByProvider.forEach(providerGroup => {
|
307
|
+
expect(providerGroup.providerId).toBeDefined();
|
308
|
+
expect(typeof providerGroup.providerId).toBe("string");
|
309
|
+
expect(Array.isArray(providerGroup.currenciesByNetwork)).toBe(true);
|
310
|
+
expect(providerGroup.currenciesByNetwork.length).toBeGreaterThan(0);
|
311
|
+
// Each currency in the group should be valid
|
312
|
+
providerGroup.currenciesByNetwork.forEach(currency => {
|
313
|
+
expect(currency.id).toBeDefined();
|
314
|
+
expect(currency.type).toMatch(/^(CryptoCurrency|TokenCurrency)$/);
|
315
|
+
});
|
316
|
+
});
|
317
|
+
// Validate sortedCryptoCurrencies
|
318
|
+
result.sortedCryptoCurrencies.forEach(currency => {
|
319
|
+
expect(currency.id).toBeDefined();
|
320
|
+
expect(currency.type).toMatch(/^(CryptoCurrency|TokenCurrency)$/);
|
321
|
+
});
|
322
|
+
// Should not have duplicates in sortedCryptoCurrencies
|
323
|
+
const sortedIds = result.sortedCryptoCurrencies.map(c => c.id);
|
324
|
+
const uniqueIds = new Set(sortedIds);
|
325
|
+
expect(sortedIds.length).toBe(uniqueIds.size);
|
326
|
+
});
|
327
|
+
it("should efficiently handle the intersection of all mock assets with all supported currencies", () => {
|
328
|
+
setSupportedCurrencies([
|
329
|
+
"bitcoin",
|
330
|
+
"ethereum",
|
331
|
+
"bsc",
|
332
|
+
"polygon",
|
333
|
+
"arbitrum",
|
334
|
+
"optimism",
|
335
|
+
"avalanche_c_chain",
|
336
|
+
"solana",
|
337
|
+
"cardano",
|
338
|
+
"polkadot",
|
339
|
+
"cosmos",
|
340
|
+
"tron",
|
341
|
+
"stellar",
|
342
|
+
"hedera",
|
343
|
+
"near",
|
344
|
+
"sui",
|
345
|
+
"litecoin",
|
346
|
+
"dogecoin",
|
347
|
+
]);
|
348
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
349
|
+
const allMockAssets = [
|
350
|
+
...TOKEN_ONLY_ASSETS,
|
351
|
+
...MOCK_WITH_TOKEN_AND_CURRENCY_ASSET,
|
352
|
+
...MOCK_POL,
|
353
|
+
];
|
354
|
+
const startTime = Date.now();
|
355
|
+
const { currenciesByProvider, sortedCryptoCurrencies } = groupCurrenciesByProvider(allMockAssets, currencies);
|
356
|
+
const endTime = Date.now();
|
357
|
+
expect(endTime - startTime).toBeLessThan(100);
|
358
|
+
expect(Array.isArray(currenciesByProvider)).toBe(true);
|
359
|
+
expect(Array.isArray(sortedCryptoCurrencies)).toBe(true);
|
360
|
+
if (currenciesByProvider.length > 0) {
|
361
|
+
currenciesByProvider.forEach(provider => {
|
362
|
+
expect(provider.providerId).toBeDefined();
|
363
|
+
expect(provider.currenciesByNetwork.length).toBeGreaterThan(0);
|
364
|
+
});
|
365
|
+
}
|
366
|
+
if (sortedCryptoCurrencies.length > 0) {
|
367
|
+
sortedCryptoCurrencies.forEach(currency => {
|
368
|
+
expect(currency.type).toMatch(/^(CryptoCurrency|TokenCurrency)$/);
|
369
|
+
});
|
370
|
+
}
|
371
|
+
});
|
372
|
+
it("should demonstrate provider grouping behavior with diverse mock data", () => {
|
373
|
+
setSupportedCurrencies(["ethereum", "polygon", "arbitrum", "optimism"]);
|
374
|
+
const currencies = sortCurrenciesByIds(listSupportedCurrencies().concat(listSupportedTokens()), MOCK_IDS);
|
375
|
+
const { currenciesByProvider, sortedCryptoCurrencies } = groupCurrenciesByProvider([...TOKEN_ONLY_ASSETS, ...MOCK_WITH_TOKEN_AND_CURRENCY_ASSET, ...MOCK_POL], currencies);
|
376
|
+
const providerIds = new Set(currenciesByProvider.map(p => p.providerId));
|
377
|
+
const expectedProviders = ["tether", "ethereum", "matic-network"];
|
378
|
+
expectedProviders.forEach(expectedProvider => {
|
379
|
+
if (currenciesByProvider.some(p => p.providerId === expectedProvider)) {
|
380
|
+
expect(providerIds.has(expectedProvider)).toBe(true);
|
381
|
+
}
|
382
|
+
});
|
383
|
+
currenciesByProvider.forEach(provider => {
|
384
|
+
expect(provider.currenciesByNetwork.length).toBeGreaterThan(0);
|
385
|
+
provider.currenciesByNetwork.forEach(currency => {
|
386
|
+
expect(currency.id).toBeDefined();
|
387
|
+
expect(["CryptoCurrency", "TokenCurrency"].includes(currency.type)).toBe(true);
|
388
|
+
});
|
389
|
+
});
|
390
|
+
expect(sortedCryptoCurrencies.length).toBeLessThanOrEqual(providerIds.size);
|
391
|
+
});
|
77
392
|
});
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
getTokenById(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
393
|
+
describe("Error handling", () => {
|
394
|
+
test("should handle malformed asset data by throwing error", () => {
|
395
|
+
const malformedAssets = [
|
396
|
+
{ ...TOKEN_ONLY_ASSETS[0], ledgerId: undefined },
|
397
|
+
{ ...TOKEN_ONLY_ASSETS[0], providerId: null },
|
398
|
+
];
|
399
|
+
const currencies = [getTokenById(TOKEN_ONLY_ASSETS[0].ledgerId)];
|
400
|
+
expect(() => {
|
401
|
+
groupCurrenciesByProvider(malformedAssets, currencies);
|
402
|
+
}).toThrow();
|
403
|
+
});
|
404
|
+
test("should handle assets with null/undefined fields gracefully where possible", () => {
|
405
|
+
const partiallyMalformedAssets = [
|
406
|
+
{ ...TOKEN_ONLY_ASSETS[0], providerId: "" },
|
407
|
+
];
|
408
|
+
const currencies = [getTokenById(TOKEN_ONLY_ASSETS[0].ledgerId)];
|
409
|
+
expect(() => {
|
410
|
+
groupCurrenciesByProvider(partiallyMalformedAssets, currencies);
|
411
|
+
}).not.toThrow();
|
412
|
+
});
|
413
|
+
test("should handle very large datasets efficiently", () => {
|
414
|
+
const largeAssetList = Array(10000)
|
415
|
+
.fill(TOKEN_ONLY_ASSETS[0])
|
416
|
+
.map((asset, index) => ({
|
417
|
+
...asset,
|
418
|
+
ledgerId: `${asset.ledgerId}_${index}`,
|
419
|
+
providerId: `provider_${index % 10}`,
|
420
|
+
}));
|
421
|
+
const currencies = [getTokenById(TOKEN_ONLY_ASSETS[0].ledgerId)];
|
422
|
+
const startTime = Date.now();
|
423
|
+
const result = groupCurrenciesByProvider(largeAssetList, currencies);
|
424
|
+
const endTime = Date.now();
|
425
|
+
expect(endTime - startTime).toBeLessThan(1000);
|
426
|
+
expect(result.currenciesByProvider).toBeDefined();
|
427
|
+
expect(result.sortedCryptoCurrencies).toBeDefined();
|
428
|
+
});
|
429
|
+
test("should handle case sensitivity in ledger IDs correctly", () => {
|
430
|
+
const mixedCaseAssets = [
|
431
|
+
{ ...TOKEN_ONLY_ASSETS[0], ledgerId: TOKEN_ONLY_ASSETS[0].ledgerId.toUpperCase() },
|
432
|
+
];
|
433
|
+
const currencies = [getTokenById(TOKEN_ONLY_ASSETS[0].ledgerId)];
|
434
|
+
const { currenciesByProvider } = groupCurrenciesByProvider(mixedCaseAssets, currencies);
|
435
|
+
expect(currenciesByProvider).toHaveLength(1);
|
436
|
+
});
|
93
437
|
});
|
94
438
|
});
|
95
439
|
//# sourceMappingURL=deposit.test.js.map
|