From a17f510fb212018f5cef361a866c18f1d60ccea2 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 3 Jun 2024 10:05:14 -0400 Subject: [PATCH 01/39] (WIP) migration hook --- .../utils/cache/useMigrateLocalStorageV1.ts | 72 +++++++++++++++++++ src/providers/Providers.tsx | 2 + 2 files changed, 74 insertions(+) create mode 100644 src/hooks/utils/cache/useMigrateLocalStorageV1.ts diff --git a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts new file mode 100644 index 0000000000..d1d618ef14 --- /dev/null +++ b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts @@ -0,0 +1,72 @@ +import { useEffect, useRef, useState } from 'react'; +import { addNetworkPrefix } from './../../../utils/url'; +// This should be a temporary hook to migrate the old local storage to the new one +// and should be removed after a few months + +import { CacheKeys, CacheKeysV0 } from './cacheDefaults'; + +export const useMigrateLocalStorageV1 = () => { + const isMounted = useRef(false); + const [isMigrated, setIsMigrated] = useState(false); + + useEffect(() => { + if (isMounted.current) return; + // Migrate old cache keys to new format + if (isMigrated) return; + const keys = Object.keys(localStorage); + keys.forEach(key => { + const prefix = key.split('_')[0]; + const chainId = key.split('_')[1]; + if (prefix === 'fract') { + // const storagePrefixLength = prefix.length + chainId.length + 2; + // const isMaster = key.includes(CacheKeysV0.MASTER_COPY_PREFIX) + // // Migrate Master Copy cache + // if(isMaster) { + // const cacheNameFull = key.substring(storagePrefixLength) + // const [, uniqueId] = cacheNameFull.split(CacheKeysV0.MASTER_COPY_PREFIX) + // const newKey = { + // name: CacheKeys.MASTER_COPY, + // chainId: chainId, + // proxyAddress: uniqueId, + // } + // const value = localStorage.getItem(key) + // localStorage.setItem(JSON.stringify(newKey), value!) + // localStorage.removeItem(key) + // } + // const isFavoriteCache = key.includes(CacheKeysV0.FAVORITES); + // // Migrate Favorites cache + // if (isFavoriteCache) { + // const value = localStorage.getItem(key); + // if (value) { + // localStorage.removeItem(key); + // const [, favoritedChainId] = key.split('_'); + // console.log('🚀 ~ _chainId:', favoritedChainId); + + // const newKey = { + // name: CacheKeys.FAVORITES, + // }; + // localStorage.setItem( + // JSON.stringify(newKey), + // addNetworkPrefix(value, Number(favoritedChainId)), + // ); + // // localStorage.removeItem(key) + // } + // } + // const isAverageBlockTime = key.includes(CacheKeysV0.AVERAGE_BLOCK_TIME) + // // Migrate Average Block Time cache, more to remove the old one than to migrate + // if(isAverageBlockTime) { + // const value = localStorage.getItem(key) + // const newKey = { + // name: CacheKeys.AVERAGE_BLOCK_TIME, + // } + // localStorage.setItem(JSON.stringify(newKey), value!) + // localStorage.removeItem(key) + // } + } + }); + setIsMigrated(true); + isMounted.current = true; + }, [isMigrated]); + + return isMigrated; +}; diff --git a/src/providers/Providers.tsx b/src/providers/Providers.tsx index ce8bfd460c..4785cdab7a 100644 --- a/src/providers/Providers.tsx +++ b/src/providers/Providers.tsx @@ -8,12 +8,14 @@ import { theme } from '../assets/theme'; import { ErrorBoundary } from '../components/ui/utils/ErrorBoundary'; import { TopErrorFallback } from '../components/ui/utils/TopErrorFallback'; import graphQLClient from '../graphql'; +import { useMigrateLocalStorageV1 } from '../hooks/utils/cache/useMigrateLocalStorageV1'; import { AppProvider } from './App/AppProvider'; import EthersContextProvider from './Ethers'; import { NetworkConfigProvider } from './NetworkConfig/NetworkConfigProvider'; import { wagmiConfig, queryClient } from './NetworkConfig/web3-modal.config'; export default function Providers({ children }: { children: ReactNode }) { + useMigrateLocalStorageV1(); return ( Date: Mon, 10 Jun 2024 09:24:46 -0400 Subject: [PATCH 02/39] migrate only favorites; - delete other cache --- .../utils/cache/useMigrateLocalStorageV1.ts | 84 ++++++++----------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts index d1d618ef14..e15262d227 100644 --- a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts +++ b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts @@ -4,66 +4,54 @@ import { addNetworkPrefix } from './../../../utils/url'; // and should be removed after a few months import { CacheKeys, CacheKeysV0 } from './cacheDefaults'; +import { setValue } from './useLocalStorage'; export const useMigrateLocalStorageV1 = () => { const isMounted = useRef(false); const [isMigrated, setIsMigrated] = useState(false); useEffect(() => { + // prevent multiple calls if (isMounted.current) return; - // Migrate old cache keys to new format if (isMigrated) return; + + // Migrate old cache keys to new format const keys = Object.keys(localStorage); - keys.forEach(key => { - const prefix = key.split('_')[0]; - const chainId = key.split('_')[1]; - if (prefix === 'fract') { - // const storagePrefixLength = prefix.length + chainId.length + 2; - // const isMaster = key.includes(CacheKeysV0.MASTER_COPY_PREFIX) - // // Migrate Master Copy cache - // if(isMaster) { - // const cacheNameFull = key.substring(storagePrefixLength) - // const [, uniqueId] = cacheNameFull.split(CacheKeysV0.MASTER_COPY_PREFIX) - // const newKey = { - // name: CacheKeys.MASTER_COPY, - // chainId: chainId, - // proxyAddress: uniqueId, - // } - // const value = localStorage.getItem(key) - // localStorage.setItem(JSON.stringify(newKey), value!) - // localStorage.removeItem(key) - // } - // const isFavoriteCache = key.includes(CacheKeysV0.FAVORITES); - // // Migrate Favorites cache - // if (isFavoriteCache) { - // const value = localStorage.getItem(key); - // if (value) { - // localStorage.removeItem(key); - // const [, favoritedChainId] = key.split('_'); - // console.log('🚀 ~ _chainId:', favoritedChainId); + const fractKeys = keys.filter(key => key.includes('fract')); + + if (!fractKeys.length) { + setIsMigrated(true); + return; + } + // Get All Network Favorites + const favoritesCache = fractKeys.filter(key => key.includes(CacheKeysV0.FAVORITES)); + const newFavorites: string[] = []; - // const newKey = { - // name: CacheKeys.FAVORITES, - // }; - // localStorage.setItem( - // JSON.stringify(newKey), - // addNetworkPrefix(value, Number(favoritedChainId)), - // ); - // // localStorage.removeItem(key) - // } - // } - // const isAverageBlockTime = key.includes(CacheKeysV0.AVERAGE_BLOCK_TIME) - // // Migrate Average Block Time cache, more to remove the old one than to migrate - // if(isAverageBlockTime) { - // const value = localStorage.getItem(key) - // const newKey = { - // name: CacheKeys.AVERAGE_BLOCK_TIME, - // } - // localStorage.setItem(JSON.stringify(newKey), value!) - // localStorage.removeItem(key) - // } + if (!favoritesCache.length) { + setIsMigrated(true); + return; + } + // loop through all favorites + favoritesCache.forEach(favorite => { + // Get ChainId from favorite key + const [, chainId] = favorite.split('_'); + const favoritesValue = localStorage.getItem(favorite); + if (favoritesValue) { + // Parse favorites value and add network prefix + const parsedValue: string[] = JSON.parse(favoritesValue); + parsedValue.forEach((value: string) => { + newFavorites.push(addNetworkPrefix(value, Number(chainId))); + }); } }); + // Set new Favorites cache + setValue({ cacheName: CacheKeys.FAVORITES }, newFavorites); + + // delete old cache + fractKeys.forEach(key => { + localStorage.removeItem(key); + }); + setIsMigrated(true); isMounted.current = true; }, [isMigrated]); From 774ddab0ba090a7577d29ae6bfa84214561e9c69 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:56:21 -0400 Subject: [PATCH 03/39] remove old cache keys --- src/hooks/utils/cache/cacheDefaults.ts | 11 ----------- src/hooks/utils/cache/useMigrateLocalStorageV1.ts | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/hooks/utils/cache/cacheDefaults.ts b/src/hooks/utils/cache/cacheDefaults.ts index 688d9702fb..02d17a7c35 100644 --- a/src/hooks/utils/cache/cacheDefaults.ts +++ b/src/hooks/utils/cache/cacheDefaults.ts @@ -36,17 +36,6 @@ export enum CacheKeys { MULTISIG_METADATA_PREFIX = 'm_m_', } -export enum CacheKeysV0 { - FAVORITES = 'favorites', - MASTER_COPY_PREFIX = 'master_copy_of_', - // wasn't a originally part of the cache keys but was used - AVERAGE_BLOCK_TIME = 'averageBlockTime', - // these were not used for local storage - // DECODED_TRANSACTION_PREFIX = 'decode_trans_', - // MULTISIG_METADATA_PREFIX = 'm_m_', - PROPOSAL_PREFIX = 'proposal', -} - export type CacheKey = { cacheName: CacheKeys; version: number; diff --git a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts index e15262d227..700799b4c6 100644 --- a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts +++ b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts @@ -3,7 +3,7 @@ import { addNetworkPrefix } from './../../../utils/url'; // This should be a temporary hook to migrate the old local storage to the new one // and should be removed after a few months -import { CacheKeys, CacheKeysV0 } from './cacheDefaults'; +import { CacheKeys } from './cacheDefaults'; import { setValue } from './useLocalStorage'; export const useMigrateLocalStorageV1 = () => { @@ -24,7 +24,7 @@ export const useMigrateLocalStorageV1 = () => { return; } // Get All Network Favorites - const favoritesCache = fractKeys.filter(key => key.includes(CacheKeysV0.FAVORITES)); + const favoritesCache = fractKeys.filter(key => key.includes('favorites')); const newFavorites: string[] = []; if (!favoritesCache.length) { From 5f1d82eb15fb490122c0a74e47d54c617f930234 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:35:37 -0400 Subject: [PATCH 04/39] extract to a testable function; - added conditionals to ensure proper handling of cache --- .../utils/cache/useMigrateLocalStorageV1.ts | 83 ++++++++++--------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts index 700799b4c6..1d992e5668 100644 --- a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts +++ b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts @@ -6,6 +6,49 @@ import { addNetworkPrefix } from './../../../utils/url'; import { CacheKeys } from './cacheDefaults'; import { setValue } from './useLocalStorage'; +//@dev for testing seperated the function from the hook and export +export function migrateCacheToV1(): boolean { + // Migrate old cache keys to new format + const keys = Object.keys(localStorage); + const fractKeys = keys.filter(key => key.includes('fract')); + if (!fractKeys.length) { + return true; + } + // Get All Network Favorites + const favoritesCache = fractKeys.filter(key => key.endsWith('favorites')); + const newFavorites: string[] = []; + + if (!favoritesCache.length) { + return true; + } + // loop through all favorites + for (const favorite of favoritesCache) { + // Get ChainId from favorite key + const [, chainId] = favorite.split('_'); + if (Number.isNaN(Number(chainId))) { + continue; + } + const favoritesValue = localStorage.getItem(favorite); + if (favoritesValue) { + // Parse favorites value and add network prefix + const parsedValue: { v: string[] } = JSON.parse(favoritesValue); + parsedValue.v.forEach((value: string) => { + newFavorites.push(addNetworkPrefix(value, Number(chainId))); + }); + } + } + if (newFavorites.length) { + // Set new Favorites cache + setValue({ cacheName: CacheKeys.FAVORITES }, newFavorites); + } + + // delete old cache + fractKeys.forEach(key => { + localStorage.removeItem(key); + }); + return true; +} + export const useMigrateLocalStorageV1 = () => { const isMounted = useRef(false); const [isMigrated, setIsMigrated] = useState(false); @@ -14,45 +57,7 @@ export const useMigrateLocalStorageV1 = () => { // prevent multiple calls if (isMounted.current) return; if (isMigrated) return; - - // Migrate old cache keys to new format - const keys = Object.keys(localStorage); - const fractKeys = keys.filter(key => key.includes('fract')); - - if (!fractKeys.length) { - setIsMigrated(true); - return; - } - // Get All Network Favorites - const favoritesCache = fractKeys.filter(key => key.includes('favorites')); - const newFavorites: string[] = []; - - if (!favoritesCache.length) { - setIsMigrated(true); - return; - } - // loop through all favorites - favoritesCache.forEach(favorite => { - // Get ChainId from favorite key - const [, chainId] = favorite.split('_'); - const favoritesValue = localStorage.getItem(favorite); - if (favoritesValue) { - // Parse favorites value and add network prefix - const parsedValue: string[] = JSON.parse(favoritesValue); - parsedValue.forEach((value: string) => { - newFavorites.push(addNetworkPrefix(value, Number(chainId))); - }); - } - }); - // Set new Favorites cache - setValue({ cacheName: CacheKeys.FAVORITES }, newFavorites); - - // delete old cache - fractKeys.forEach(key => { - localStorage.removeItem(key); - }); - - setIsMigrated(true); + setIsMigrated(migrateCacheToV1()); isMounted.current = true; }, [isMigrated]); From 2ef4685c9932e4d7711891eb0a37ea09c5be59cc Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:36:10 -0400 Subject: [PATCH 05/39] add unit test for migration func --- test/useMigrationV1.test.ts | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/useMigrationV1.test.ts diff --git a/test/useMigrationV1.test.ts b/test/useMigrationV1.test.ts new file mode 100644 index 0000000000..555b2b8da4 --- /dev/null +++ b/test/useMigrationV1.test.ts @@ -0,0 +1,89 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; +import { setValue } from '../src/hooks/utils/cache/useLocalStorage'; +import { migrateCacheToV1 } from '../src/hooks/utils/cache/useMigrateLocalStorageV1'; + +// Mock the setValue function +vi.mock('../src/hooks/utils/cache/useLocalStorage', () => ({ + setValue: vi.fn(), +})); + +// Clear localStorage before each test +beforeEach(() => { + localStorage.clear(); + vi.clearAllMocks(); +}); + +describe('migrateCacheToV1', () => { + it('should correctly migrate a single favorite', () => { + const oldKey = 'fract_11155111_favorites'; + const oldValue = JSON.stringify({ + v: ['0xd418E98a11B9189fCc05cddfbB10F4Cee996C749'], + e: -1, + }); + localStorage.setItem(oldKey, oldValue); + + const expectedNewValue = ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']; + + migrateCacheToV1(); + + expect(setValue).toHaveBeenCalledWith({ cacheName: CacheKeys.FAVORITES }, expectedNewValue); + expect(localStorage.getItem(oldKey)).toBeNull(); + }); + + it('should correctly migrate multiple favorites from different networks', () => { + const oldKey1 = 'fract_11155111_favorites'; + const oldValue1 = JSON.stringify({ + v: ['0xd418E98a11B9189fCc05cddfbB10F4Cee996C749'], + e: -1, + }); + + const oldKey2 = 'fract_1_favorites'; + const oldValue2 = JSON.stringify({ + v: ['0xabcdE98a11B9189fCc05cddfbB10F4Cee996C999'], + e: -1, + }); + + localStorage.setItem(oldKey1, oldValue1); + localStorage.setItem(oldKey2, oldValue2); + + const expectedNewValue = [ + 'sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749', + 'eth:0xabcdE98a11B9189fCc05cddfbB10F4Cee996C999' + ]; + + migrateCacheToV1(); + + expect(setValue).toHaveBeenCalledWith({ cacheName: CacheKeys.FAVORITES }, expectedNewValue); + expect(localStorage.getItem(oldKey1)).toBeNull(); + expect(localStorage.getItem(oldKey2)).toBeNull(); + }); + + it('should handle an empty localStorage without errors', () => { + migrateCacheToV1(); + + expect(setValue).not.toHaveBeenCalled(); + }); + + it('should handle localStorage without relevant keys', () => { + localStorage.setItem('unrelatedKey', 'someValue'); + migrateCacheToV1(); + + expect(setValue).not.toHaveBeenCalled(); + expect(localStorage.getItem('unrelatedKey')).toBe('someValue'); + }); + + it('should handle favorites without chain IDs correctly', () => { + const oldKey = 'fract_favorites'; + const oldValue = JSON.stringify({ + v: ['0x1234abcd5678efgh91011ijklmno1234'], + e: -1, + }); + localStorage.setItem(oldKey, oldValue); + + migrateCacheToV1(); + + expect(setValue).not.toHaveBeenCalled(); + expect(localStorage.getItem(oldKey)).toBeNull(); + }); +}); \ No newline at end of file From 382d53fa8f079e5649fbb2aada806172f683344f Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:49:59 -0400 Subject: [PATCH 06/39] target `fract_` more precisely --- src/hooks/utils/cache/useMigrateLocalStorageV1.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts index 1d992e5668..72fdfec488 100644 --- a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts +++ b/src/hooks/utils/cache/useMigrateLocalStorageV1.ts @@ -10,7 +10,7 @@ import { setValue } from './useLocalStorage'; export function migrateCacheToV1(): boolean { // Migrate old cache keys to new format const keys = Object.keys(localStorage); - const fractKeys = keys.filter(key => key.includes('fract')); + const fractKeys = keys.filter(key => key.startsWith('fract_')); if (!fractKeys.length) { return true; } From fd4e1d80f3a1535687ceeb8a2bdac770228586a6 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:51:44 -0400 Subject: [PATCH 07/39] run pretty/lint --- test/useMigrationV1.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/useMigrationV1.test.ts b/test/useMigrationV1.test.ts index 555b2b8da4..c3c7f611dd 100644 --- a/test/useMigrationV1.test.ts +++ b/test/useMigrationV1.test.ts @@ -49,7 +49,7 @@ describe('migrateCacheToV1', () => { const expectedNewValue = [ 'sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749', - 'eth:0xabcdE98a11B9189fCc05cddfbB10F4Cee996C999' + 'eth:0xabcdE98a11B9189fCc05cddfbB10F4Cee996C999', ]; migrateCacheToV1(); @@ -86,4 +86,4 @@ describe('migrateCacheToV1', () => { expect(setValue).not.toHaveBeenCalled(); expect(localStorage.getItem(oldKey)).toBeNull(); }); -}); \ No newline at end of file +}); From e9d7792eabc02ffa00cbb7d7c66b07b434bb0c78 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 13 Jun 2024 18:34:23 -0400 Subject: [PATCH 08/39] rename -> useMigrate --- .../cache/{useMigrateLocalStorageV1.ts => useMigrate.ts} | 4 ++-- src/providers/Providers.tsx | 4 ++-- test/useMigrationV1.test.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/hooks/utils/cache/{useMigrateLocalStorageV1.ts => useMigrate.ts} (94%) diff --git a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts b/src/hooks/utils/cache/useMigrate.ts similarity index 94% rename from src/hooks/utils/cache/useMigrateLocalStorageV1.ts rename to src/hooks/utils/cache/useMigrate.ts index 72fdfec488..9bd98cdeb8 100644 --- a/src/hooks/utils/cache/useMigrateLocalStorageV1.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -1,5 +1,5 @@ import { useEffect, useRef, useState } from 'react'; -import { addNetworkPrefix } from './../../../utils/url'; +import { addNetworkPrefix } from '../../../utils/url'; // This should be a temporary hook to migrate the old local storage to the new one // and should be removed after a few months @@ -49,7 +49,7 @@ export function migrateCacheToV1(): boolean { return true; } -export const useMigrateLocalStorageV1 = () => { +export const useMigrate = () => { const isMounted = useRef(false); const [isMigrated, setIsMigrated] = useState(false); diff --git a/src/providers/Providers.tsx b/src/providers/Providers.tsx index 4785cdab7a..2a31771d98 100644 --- a/src/providers/Providers.tsx +++ b/src/providers/Providers.tsx @@ -8,14 +8,14 @@ import { theme } from '../assets/theme'; import { ErrorBoundary } from '../components/ui/utils/ErrorBoundary'; import { TopErrorFallback } from '../components/ui/utils/TopErrorFallback'; import graphQLClient from '../graphql'; -import { useMigrateLocalStorageV1 } from '../hooks/utils/cache/useMigrateLocalStorageV1'; +import { useMigrate } from '../hooks/utils/cache/useMigrate'; import { AppProvider } from './App/AppProvider'; import EthersContextProvider from './Ethers'; import { NetworkConfigProvider } from './NetworkConfig/NetworkConfigProvider'; import { wagmiConfig, queryClient } from './NetworkConfig/web3-modal.config'; export default function Providers({ children }: { children: ReactNode }) { - useMigrateLocalStorageV1(); + useMigrate(); return ( ({ From cc402b3a473714f79f937ce2c47b6d5b3a07706b Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 13 Jun 2024 18:43:34 -0400 Subject: [PATCH 09/39] add migration version --- src/hooks/utils/cache/cacheDefaults.ts | 2 ++ src/hooks/utils/cache/useMigrate.ts | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hooks/utils/cache/cacheDefaults.ts b/src/hooks/utils/cache/cacheDefaults.ts index 02d17a7c35..e66bacbe59 100644 --- a/src/hooks/utils/cache/cacheDefaults.ts +++ b/src/hooks/utils/cache/cacheDefaults.ts @@ -31,6 +31,7 @@ export enum CacheKeys { MASTER_COPY = 'Master Copy', AVERAGE_BLOCK_TIME = 'Average Block Time', PROPOSAL_CACHE = 'Proposal', + MIGRATION = 'Migration', // indexDB keys DECODED_TRANSACTION_PREFIX = 'decode_trans_', MULTISIG_METADATA_PREFIX = 'm_m_', @@ -96,6 +97,7 @@ export const CACHE_VERSIONS: { [key: string]: number } = Object.freeze({ [CacheKeys.MASTER_COPY]: 1, [CacheKeys.PROPOSAL_CACHE]: 1, [CacheKeys.AVERAGE_BLOCK_TIME]: 1, + [CacheKeys.MIGRATION]: 1, }); /** diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 9bd98cdeb8..51593b1488 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -3,11 +3,15 @@ import { addNetworkPrefix } from '../../../utils/url'; // This should be a temporary hook to migrate the old local storage to the new one // and should be removed after a few months -import { CacheKeys } from './cacheDefaults'; +import { CACHE_VERSIONS, CacheKeys } from './cacheDefaults'; import { setValue } from './useLocalStorage'; //@dev for testing seperated the function from the hook and export export function migrateCacheToV1(): boolean { + const cacheVersion = localStorage.getItem(CacheKeys.MIGRATION); + if (cacheVersion && Number(cacheVersion) === CACHE_VERSIONS[CacheKeys.MIGRATION]) { + return true; + } // Migrate old cache keys to new format const keys = Object.keys(localStorage); const fractKeys = keys.filter(key => key.startsWith('fract_')); @@ -46,6 +50,8 @@ export function migrateCacheToV1(): boolean { fractKeys.forEach(key => { localStorage.removeItem(key); }); + // set migration version + setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); return true; } From 62e37d919d5f50550e7616cbbbb89ede4ecc3841 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 13 Jun 2024 21:14:52 -0400 Subject: [PATCH 10/39] remove old conditional for SSR --- src/hooks/utils/cache/useLocalStorage.ts | 45 +++++++++++------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/hooks/utils/cache/useLocalStorage.ts b/src/hooks/utils/cache/useLocalStorage.ts index 5b0a683fc5..be8e72d5b9 100644 --- a/src/hooks/utils/cache/useLocalStorage.ts +++ b/src/hooks/utils/cache/useLocalStorage.ts @@ -30,36 +30,31 @@ export const setValue = ( value: any, expirationMinutes: number = CacheExpiry.ONE_WEEK, ): void => { - if (typeof window !== 'undefined') { - const val: CacheValue = { - v: value, - e: - expirationMinutes === CacheExpiry.NEVER - ? CacheExpiry.NEVER - : Date.now() + expirationMinutes * 60000, - }; - localStorage.setItem( - JSON.stringify({ ...key, version: CACHE_VERSIONS[key.cacheName] }), - JSON.stringify(val, bigintReplacer), - ); - } + const val: CacheValue = { + v: value, + e: + expirationMinutes === CacheExpiry.NEVER + ? CacheExpiry.NEVER + : Date.now() + expirationMinutes * 60000, + }; + localStorage.setItem( + JSON.stringify({ ...key, version: CACHE_VERSIONS[key.cacheName] }), + JSON.stringify(val, bigintReplacer), + ); }; export const getValue = (key: T): CacheValueType | null => { - if (typeof window !== 'undefined') { - const version = CACHE_VERSIONS[key.cacheName]; - const rawVal = localStorage.getItem(JSON.stringify({ ...key, version })); - if (rawVal) { - const parsed: CacheValue = JSON.parse(rawVal, proposalObjectReviver); - if (parsed.e === CacheExpiry.NEVER || parsed.e >= Date.now()) { - return parsed.v as CacheValueType; - } else { - localStorage.removeItem(JSON.stringify({ ...key, version })); - return null; - } + const version = CACHE_VERSIONS[key.cacheName]; + const rawVal = localStorage.getItem(JSON.stringify({ ...key, version })); + if (rawVal) { + const parsed: CacheValue = JSON.parse(rawVal, proposalObjectReviver); + if (parsed.e === CacheExpiry.NEVER || parsed.e >= Date.now()) { + return parsed.v as CacheValueType; } else { + localStorage.removeItem(JSON.stringify({ ...key, version })); return null; } + } else { + return null; } - return null; }; From 6a710b2bdb19f35f87cd5fea0ad4b40719cf4fe7 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 13 Jun 2024 21:16:38 -0400 Subject: [PATCH 11/39] set new migration version to track migrations --- src/hooks/utils/cache/cacheDefaults.ts | 1 + src/hooks/utils/cache/useMigrate.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hooks/utils/cache/cacheDefaults.ts b/src/hooks/utils/cache/cacheDefaults.ts index e66bacbe59..83703822a2 100644 --- a/src/hooks/utils/cache/cacheDefaults.ts +++ b/src/hooks/utils/cache/cacheDefaults.ts @@ -80,6 +80,7 @@ type CacheKeyToValueMap = { [CacheKeys.MASTER_COPY]: Address; [CacheKeys.PROPOSAL_CACHE]: AzoriusProposal; [CacheKeys.AVERAGE_BLOCK_TIME]: number; + [CacheKeys.MIGRATION]: number; }; export type CacheValueType = T extends { cacheName: infer U } diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 51593b1488..03088352d3 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -4,27 +4,26 @@ import { addNetworkPrefix } from '../../../utils/url'; // and should be removed after a few months import { CACHE_VERSIONS, CacheKeys } from './cacheDefaults'; -import { setValue } from './useLocalStorage'; +import { getValue, setValue } from './useLocalStorage'; //@dev for testing seperated the function from the hook and export export function migrateCacheToV1(): boolean { - const cacheVersion = localStorage.getItem(CacheKeys.MIGRATION); - if (cacheVersion && Number(cacheVersion) === CACHE_VERSIONS[CacheKeys.MIGRATION]) { + const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); + if (cacheVersion && cacheVersion === CACHE_VERSIONS[CacheKeys.MIGRATION]) { return true; } // Migrate old cache keys to new format const keys = Object.keys(localStorage); const fractKeys = keys.filter(key => key.startsWith('fract_')); if (!fractKeys.length) { + // update migration version if no old cache keys are found + setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); return true; } // Get All Network Favorites const favoritesCache = fractKeys.filter(key => key.endsWith('favorites')); const newFavorites: string[] = []; - if (!favoritesCache.length) { - return true; - } // loop through all favorites for (const favorite of favoritesCache) { // Get ChainId from favorite key @@ -51,6 +50,7 @@ export function migrateCacheToV1(): boolean { localStorage.removeItem(key); }); // set migration version + setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); return true; } From d148f040ba686ba8ab961182e8a1563898212865 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 13 Jun 2024 21:16:55 -0400 Subject: [PATCH 12/39] remove mocking and fix tests for checking migration number --- test/useMigrationV1.test.ts | 51 ++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/test/useMigrationV1.test.ts b/test/useMigrationV1.test.ts index d88b25cab3..c18ab436a0 100644 --- a/test/useMigrationV1.test.ts +++ b/test/useMigrationV1.test.ts @@ -1,13 +1,8 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; -import { setValue } from '../src/hooks/utils/cache/useLocalStorage'; +import { getValue } from '../src/hooks/utils/cache/useLocalStorage'; import { migrateCacheToV1 } from '../src/hooks/utils/cache/useMigrate'; -// Mock the setValue function -vi.mock('../src/hooks/utils/cache/useLocalStorage', () => ({ - setValue: vi.fn(), -})); - // Clear localStorage before each test beforeEach(() => { localStorage.clear(); @@ -26,8 +21,18 @@ describe('migrateCacheToV1', () => { const expectedNewValue = ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']; migrateCacheToV1(); + const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); + if (!favoriteCache) { + throw new Error('Favorites cache not found'); + } + expect(favoriteCache).toStrictEqual(expectedNewValue); + + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(1); - expect(setValue).toHaveBeenCalledWith({ cacheName: CacheKeys.FAVORITES }, expectedNewValue); expect(localStorage.getItem(oldKey)).toBeNull(); }); @@ -53,23 +58,41 @@ describe('migrateCacheToV1', () => { ]; migrateCacheToV1(); - - expect(setValue).toHaveBeenCalledWith({ cacheName: CacheKeys.FAVORITES }, expectedNewValue); + const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); + if (!favoriteCache) { + throw new Error('Favorites cache not found'); + } + expect(favoriteCache).toStrictEqual(expectedNewValue); expect(localStorage.getItem(oldKey1)).toBeNull(); expect(localStorage.getItem(oldKey2)).toBeNull(); + + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(1); }); it('should handle an empty localStorage without errors', () => { migrateCacheToV1(); - expect(setValue).not.toHaveBeenCalled(); + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(1); }); it('should handle localStorage without relevant keys', () => { localStorage.setItem('unrelatedKey', 'someValue'); migrateCacheToV1(); - expect(setValue).not.toHaveBeenCalled(); + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(1); + expect(localStorage.getItem('unrelatedKey')).toBe('someValue'); }); @@ -83,7 +106,11 @@ describe('migrateCacheToV1', () => { migrateCacheToV1(); - expect(setValue).not.toHaveBeenCalled(); expect(localStorage.getItem(oldKey)).toBeNull(); + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(1); }); }); From 92bc295e03b6c8fca6badc5e168985f6b80b6faf Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Thu, 13 Jun 2024 21:23:08 -0400 Subject: [PATCH 13/39] run pretty/lint --- test/useMigrationV1.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/useMigrationV1.test.ts b/test/useMigrationV1.test.ts index c18ab436a0..13ffdab098 100644 --- a/test/useMigrationV1.test.ts +++ b/test/useMigrationV1.test.ts @@ -26,7 +26,7 @@ describe('migrateCacheToV1', () => { throw new Error('Favorites cache not found'); } expect(favoriteCache).toStrictEqual(expectedNewValue); - + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); if (!migrationCache) { throw new Error('Migration cache not found'); From 2499cf5e82863af10af8fe7ace5a54de1be2c3b9 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:39:22 -0400 Subject: [PATCH 14/39] move cache version check to useEffect --- src/hooks/utils/cache/useMigrate.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 03088352d3..7e9d33345f 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -8,10 +8,6 @@ import { getValue, setValue } from './useLocalStorage'; //@dev for testing seperated the function from the hook and export export function migrateCacheToV1(): boolean { - const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); - if (cacheVersion && cacheVersion === CACHE_VERSIONS[CacheKeys.MIGRATION]) { - return true; - } // Migrate old cache keys to new format const keys = Object.keys(localStorage); const fractKeys = keys.filter(key => key.startsWith('fract_')); @@ -63,7 +59,14 @@ export const useMigrate = () => { // prevent multiple calls if (isMounted.current) return; if (isMigrated) return; - setIsMigrated(migrateCacheToV1()); + const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); + if ( + cacheVersion && + cacheVersion !== CACHE_VERSIONS[CacheKeys.MIGRATION] && + cacheVersion === 1 + ) { + setIsMigrated(migrateCacheToV1()); + } isMounted.current = true; }, [isMigrated]); From 04a80e4da6137b171ac8a0b0a94d6be9c552b9f9 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Fri, 14 Jun 2024 12:41:04 -0400 Subject: [PATCH 15/39] Infinity migrations --- src/hooks/utils/cache/migrations/1.ts | 45 +++++++++++++++ src/hooks/utils/cache/useMigrate.ts | 83 ++++++++------------------- test/useMigrationV1.test.ts | 2 +- 3 files changed, 69 insertions(+), 61 deletions(-) create mode 100644 src/hooks/utils/cache/migrations/1.ts diff --git a/src/hooks/utils/cache/migrations/1.ts b/src/hooks/utils/cache/migrations/1.ts new file mode 100644 index 0000000000..c9b99fe197 --- /dev/null +++ b/src/hooks/utils/cache/migrations/1.ts @@ -0,0 +1,45 @@ +import { addNetworkPrefix } from '../../../../utils/url'; +// This should be a temporary hook to migrate the old local storage to the new one +// and should be removed after a few months + +import { CacheKeys } from '../cacheDefaults'; +import { setValue } from '../useLocalStorage'; + +//@dev for testing seperated the function from the hook and export +export default function v1MigrateFavorites() { + // Migrate old cache keys to new format + const keys = Object.keys(localStorage); + const fractKeys = keys.filter(key => key.startsWith('fract_')); + if (!fractKeys.length) { + return; + } + // Get All Network Favorites + const favoritesCache = fractKeys.filter(key => key.endsWith('favorites')); + const newFavorites: string[] = []; + + // loop through all favorites + for (const favorite of favoritesCache) { + // Get ChainId from favorite key + const [, chainId] = favorite.split('_'); + if (Number.isNaN(Number(chainId))) { + continue; + } + const favoritesValue = localStorage.getItem(favorite); + if (favoritesValue) { + // Parse favorites value and add network prefix + const parsedValue: { v: string[] } = JSON.parse(favoritesValue); + parsedValue.v.forEach((value: string) => { + newFavorites.push(addNetworkPrefix(value, Number(chainId))); + }); + } + } + if (newFavorites.length) { + // Set new Favorites cache + setValue({ cacheName: CacheKeys.FAVORITES }, newFavorites); + } + + // delete old cache + fractKeys.forEach(key => { + localStorage.removeItem(key); + }); +} diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 7e9d33345f..32af29fe43 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -1,74 +1,37 @@ -import { useEffect, useRef, useState } from 'react'; -import { addNetworkPrefix } from '../../../utils/url'; -// This should be a temporary hook to migrate the old local storage to the new one -// and should be removed after a few months - +import { useEffect, useRef } from 'react'; import { CACHE_VERSIONS, CacheKeys } from './cacheDefaults'; import { getValue, setValue } from './useLocalStorage'; -//@dev for testing seperated the function from the hook and export -export function migrateCacheToV1(): boolean { - // Migrate old cache keys to new format - const keys = Object.keys(localStorage); - const fractKeys = keys.filter(key => key.startsWith('fract_')); - if (!fractKeys.length) { - // update migration version if no old cache keys are found - setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); - return true; - } - // Get All Network Favorites - const favoritesCache = fractKeys.filter(key => key.endsWith('favorites')); - const newFavorites: string[] = []; - - // loop through all favorites - for (const favorite of favoritesCache) { - // Get ChainId from favorite key - const [, chainId] = favorite.split('_'); - if (Number.isNaN(Number(chainId))) { - continue; - } - const favoritesValue = localStorage.getItem(favorite); - if (favoritesValue) { - // Parse favorites value and add network prefix - const parsedValue: { v: string[] } = JSON.parse(favoritesValue); - parsedValue.v.forEach((value: string) => { - newFavorites.push(addNetworkPrefix(value, Number(chainId))); - }); +const runMigrations = () => { + const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); + + if ( + cacheVersion === null || + (cacheVersion && cacheVersion < CACHE_VERSIONS[CacheKeys.MIGRATION]) + ) { + const actualCacheVersion = cacheVersion || 0; + const migrationsToRun = CACHE_VERSIONS[CacheKeys.MIGRATION] - actualCacheVersion; + // loop through each pending migration and run in turn + for (let i = actualCacheVersion + 1; i <= migrationsToRun; i++) { + const migration = require(`./migrations/${i}`); + try { + migration(); + } catch (e) { + setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); + return; + } } + setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); } - if (newFavorites.length) { - // Set new Favorites cache - setValue({ cacheName: CacheKeys.FAVORITES }, newFavorites); - } - - // delete old cache - fractKeys.forEach(key => { - localStorage.removeItem(key); - }); - // set migration version - - setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); - return true; -} +}; export const useMigrate = () => { const isMounted = useRef(false); - const [isMigrated, setIsMigrated] = useState(false); useEffect(() => { // prevent multiple calls if (isMounted.current) return; - if (isMigrated) return; - const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); - if ( - cacheVersion && - cacheVersion !== CACHE_VERSIONS[CacheKeys.MIGRATION] && - cacheVersion === 1 - ) { - setIsMigrated(migrateCacheToV1()); - } + runMigrations(); isMounted.current = true; - }, [isMigrated]); - - return isMigrated; + }, []); }; diff --git a/test/useMigrationV1.test.ts b/test/useMigrationV1.test.ts index 13ffdab098..a96b73324f 100644 --- a/test/useMigrationV1.test.ts +++ b/test/useMigrationV1.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; +import migrateCacheToV1 from '../src/hooks/utils/cache/migrations/1'; import { getValue } from '../src/hooks/utils/cache/useLocalStorage'; -import { migrateCacheToV1 } from '../src/hooks/utils/cache/useMigrate'; // Clear localStorage before each test beforeEach(() => { From 6e81487358dde3cd3b834e71f8164bc08d0e6a51 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:44:50 -0400 Subject: [PATCH 16/39] fix tests --- test/useMigrationV1.test.ts | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/test/useMigrationV1.test.ts b/test/useMigrationV1.test.ts index a96b73324f..2e53faa114 100644 --- a/test/useMigrationV1.test.ts +++ b/test/useMigrationV1.test.ts @@ -26,13 +26,6 @@ describe('migrateCacheToV1', () => { throw new Error('Favorites cache not found'); } expect(favoriteCache).toStrictEqual(expectedNewValue); - - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } - expect(migrationCache).toBe(1); - expect(localStorage.getItem(oldKey)).toBeNull(); }); @@ -65,34 +58,16 @@ describe('migrateCacheToV1', () => { expect(favoriteCache).toStrictEqual(expectedNewValue); expect(localStorage.getItem(oldKey1)).toBeNull(); expect(localStorage.getItem(oldKey2)).toBeNull(); - - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } - expect(migrationCache).toBe(1); }); it('should handle an empty localStorage without errors', () => { migrateCacheToV1(); - - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } - expect(migrationCache).toBe(1); }); it('should handle localStorage without relevant keys', () => { localStorage.setItem('unrelatedKey', 'someValue'); migrateCacheToV1(); - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } - expect(migrationCache).toBe(1); - expect(localStorage.getItem('unrelatedKey')).toBe('someValue'); }); @@ -107,10 +82,5 @@ describe('migrateCacheToV1', () => { migrateCacheToV1(); expect(localStorage.getItem(oldKey)).toBeNull(); - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } - expect(migrationCache).toBe(1); }); }); From 8a21e7eb0e51d62b8d7565b5f6d5aeec39d81a48 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:44:56 -0400 Subject: [PATCH 17/39] add logger --- src/hooks/utils/cache/useMigrate.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 32af29fe43..26be9f605e 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -1,4 +1,5 @@ import { useEffect, useRef } from 'react'; +import { logError } from '../../../helpers/errorLogging'; import { CACHE_VERSIONS, CacheKeys } from './cacheDefaults'; import { getValue, setValue } from './useLocalStorage'; @@ -17,6 +18,7 @@ const runMigrations = () => { try { migration(); } catch (e) { + logError(e) setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); return; } From c78e39ef4f87ba75b42730c81d2a623abf57b90c Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:45:58 -0400 Subject: [PATCH 18/39] rename test --- test/{useMigrationV1.test.ts => migrateCacheToV1.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{useMigrationV1.test.ts => migrateCacheToV1.test.ts} (100%) diff --git a/test/useMigrationV1.test.ts b/test/migrateCacheToV1.test.ts similarity index 100% rename from test/useMigrationV1.test.ts rename to test/migrateCacheToV1.test.ts From 1d4dec8f04255a72ca1ccdc950621331ab23d2ac Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:25:24 -0400 Subject: [PATCH 19/39] add new runMigration test --- src/hooks/utils/cache/useMigrate.ts | 6 ++-- test/runMigration.test.ts | 50 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 test/runMigration.test.ts diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 26be9f605e..95c343595c 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -3,7 +3,7 @@ import { logError } from '../../../helpers/errorLogging'; import { CACHE_VERSIONS, CacheKeys } from './cacheDefaults'; import { getValue, setValue } from './useLocalStorage'; -const runMigrations = () => { +export const runMigrations = async () => { const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); if ( @@ -14,9 +14,9 @@ const runMigrations = () => { const migrationsToRun = CACHE_VERSIONS[CacheKeys.MIGRATION] - actualCacheVersion; // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationsToRun; i++) { - const migration = require(`./migrations/${i}`); + const migration = await import(`./migrations/${i}`); try { - migration(); + migration.default(); } catch (e) { logError(e) setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); diff --git a/test/runMigration.test.ts b/test/runMigration.test.ts new file mode 100644 index 0000000000..767bfe578d --- /dev/null +++ b/test/runMigration.test.ts @@ -0,0 +1,50 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { CACHE_VERSIONS, CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; +import { getValue, setValue } from '../src/hooks/utils/cache/useLocalStorage'; +import { runMigrations } from '../src/hooks/utils/cache/useMigrate'; + +// Clear localStorage before each test +beforeEach(() => { + localStorage.clear(); + vi.clearAllMocks(); +}); + +describe('run migrations', () => { + it('should set migration version to current', async () => { + const oldKey = 'fract_11155111_favorites'; + const oldValue = JSON.stringify({ + v: ['0xd418E98a11B9189fCc05cddfbB10F4Cee996C749'], + e: -1, + }); + localStorage.setItem(oldKey, oldValue); + + await runMigrations(); + + const expectedNewValue = ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']; + const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); + if (!favoriteCache) { + throw new Error('Favorites cache not found'); + } + expect(favoriteCache).toStrictEqual(expectedNewValue); + + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(CACHE_VERSIONS[CacheKeys.MIGRATION]); + }); + + it('should early exit', async () => { + setValue({cacheName: CacheKeys.FAVORITES}, ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']); + setValue({cacheName: CacheKeys.MIGRATION}, CACHE_VERSIONS[CacheKeys.MIGRATION]); + + await runMigrations(); + + + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(CACHE_VERSIONS[CacheKeys.MIGRATION]); + }); +}); From fc0f1b971fbb3c9eb40d36f3029ad376c1c4e0f5 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:28:04 -0400 Subject: [PATCH 20/39] run pretty/lint --- src/hooks/utils/cache/useMigrate.ts | 2 +- test/runMigration.test.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 95c343595c..210f86decc 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -18,7 +18,7 @@ export const runMigrations = async () => { try { migration.default(); } catch (e) { - logError(e) + logError(e); setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); return; } diff --git a/test/runMigration.test.ts b/test/runMigration.test.ts index 767bfe578d..202c229d83 100644 --- a/test/runMigration.test.ts +++ b/test/runMigration.test.ts @@ -19,14 +19,14 @@ describe('run migrations', () => { localStorage.setItem(oldKey, oldValue); await runMigrations(); - + const expectedNewValue = ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']; const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); if (!favoriteCache) { throw new Error('Favorites cache not found'); } expect(favoriteCache).toStrictEqual(expectedNewValue); - + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); if (!migrationCache) { throw new Error('Migration cache not found'); @@ -35,12 +35,13 @@ describe('run migrations', () => { }); it('should early exit', async () => { - setValue({cacheName: CacheKeys.FAVORITES}, ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']); - setValue({cacheName: CacheKeys.MIGRATION}, CACHE_VERSIONS[CacheKeys.MIGRATION]); + setValue({ cacheName: CacheKeys.FAVORITES }, [ + 'sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749', + ]); + setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); await runMigrations(); - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); if (!migrationCache) { throw new Error('Migration cache not found'); From 3d08bcc0a8ac09f6559b7f8e2a1e891a14bd83a8 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sat, 15 Jun 2024 01:10:47 -0400 Subject: [PATCH 21/39] remove hardcoded migration version --- src/hooks/utils/cache/cacheDefaults.ts | 1 - src/hooks/utils/cache/useMigrate.ts | 35 +++++++++++++------------- test/runMigration.test.ts | 10 ++++---- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/hooks/utils/cache/cacheDefaults.ts b/src/hooks/utils/cache/cacheDefaults.ts index 83703822a2..9471dcc70f 100644 --- a/src/hooks/utils/cache/cacheDefaults.ts +++ b/src/hooks/utils/cache/cacheDefaults.ts @@ -98,7 +98,6 @@ export const CACHE_VERSIONS: { [key: string]: number } = Object.freeze({ [CacheKeys.MASTER_COPY]: 1, [CacheKeys.PROPOSAL_CACHE]: 1, [CacheKeys.AVERAGE_BLOCK_TIME]: 1, - [CacheKeys.MIGRATION]: 1, }); /** diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 210f86decc..17ed6c97e7 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -1,30 +1,29 @@ +import fs from 'fs'; +import path from 'path'; import { useEffect, useRef } from 'react'; import { logError } from '../../../helpers/errorLogging'; -import { CACHE_VERSIONS, CacheKeys } from './cacheDefaults'; +import { CacheKeys } from './cacheDefaults'; import { getValue, setValue } from './useLocalStorage'; export const runMigrations = async () => { const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); - if ( - cacheVersion === null || - (cacheVersion && cacheVersion < CACHE_VERSIONS[CacheKeys.MIGRATION]) - ) { - const actualCacheVersion = cacheVersion || 0; - const migrationsToRun = CACHE_VERSIONS[CacheKeys.MIGRATION] - actualCacheVersion; - // loop through each pending migration and run in turn - for (let i = actualCacheVersion + 1; i <= migrationsToRun; i++) { - const migration = await import(`./migrations/${i}`); - try { - migration.default(); - } catch (e) { - logError(e); - setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); - return; - } + const actualCacheVersion = cacheVersion || 0; + const migrationsPath = path.resolve(__dirname, './migrations'); + const migrationFiles = fs.readdirSync(migrationsPath); + const migrationCount = migrationFiles.length; + // loop through each pending migration and run in turn + for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { + const migration = await import(`./migrations/${i}`); + try { + migration.default(); + } catch (e) { + logError(e); + setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); + return; } - setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); } + setValue({ cacheName: CacheKeys.MIGRATION }, migrationCount); }; export const useMigrate = () => { diff --git a/test/runMigration.test.ts b/test/runMigration.test.ts index 202c229d83..3c87d6eeca 100644 --- a/test/runMigration.test.ts +++ b/test/runMigration.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; -import { CACHE_VERSIONS, CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; +import { CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; import { getValue, setValue } from '../src/hooks/utils/cache/useLocalStorage'; import { runMigrations } from '../src/hooks/utils/cache/useMigrate'; @@ -31,21 +31,21 @@ describe('run migrations', () => { if (!migrationCache) { throw new Error('Migration cache not found'); } - expect(migrationCache).toBe(CACHE_VERSIONS[CacheKeys.MIGRATION]); + expect(migrationCache).toBe(1); }); it('should early exit', async () => { setValue({ cacheName: CacheKeys.FAVORITES }, [ 'sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749', ]); - setValue({ cacheName: CacheKeys.MIGRATION }, CACHE_VERSIONS[CacheKeys.MIGRATION]); + setValue({ cacheName: CacheKeys.MIGRATION }, 1); await runMigrations(); - + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); if (!migrationCache) { throw new Error('Migration cache not found'); } - expect(migrationCache).toBe(CACHE_VERSIONS[CacheKeys.MIGRATION]); + expect(migrationCache).toBe(1); }); }); From 27832095b07ce53efcfce21725a2e008655fd421 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sat, 15 Jun 2024 01:11:07 -0400 Subject: [PATCH 22/39] run pretty/lint --- test/runMigration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runMigration.test.ts b/test/runMigration.test.ts index 3c87d6eeca..2eca14824e 100644 --- a/test/runMigration.test.ts +++ b/test/runMigration.test.ts @@ -41,7 +41,7 @@ describe('run migrations', () => { setValue({ cacheName: CacheKeys.MIGRATION }, 1); await runMigrations(); - + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); if (!migrationCache) { throw new Error('Migration cache not found'); From 06fc419eb971ea008b172f65ebce82c7828ed52d Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sat, 15 Jun 2024 23:22:24 -0400 Subject: [PATCH 23/39] move import into try/catch --- src/hooks/utils/cache/useMigrate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 17ed6c97e7..a7b40bb879 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -14,8 +14,8 @@ export const runMigrations = async () => { const migrationCount = migrationFiles.length; // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { - const migration = await import(`./migrations/${i}`); try { + const migration = await import(`./migrations/${i}`); migration.default(); } catch (e) { logError(e); From f866df015f858a2f608359c9d525df68d3bb18b3 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sun, 16 Jun 2024 00:28:45 -0400 Subject: [PATCH 24/39] remove use of `fs` API - use import.meta.glob to get migrations - pass count as param for testing --- src/hooks/utils/cache/useMigrate.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index a7b40bb879..bed903c70f 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -1,29 +1,29 @@ -import fs from 'fs'; -import path from 'path'; import { useEffect, useRef } from 'react'; import { logError } from '../../../helpers/errorLogging'; import { CacheKeys } from './cacheDefaults'; import { getValue, setValue } from './useLocalStorage'; -export const runMigrations = async () => { +const migrations = import.meta.glob('./migrations/*'); + +export const runMigrations = async ( + // @dev import.meta.glob can not be mocked in tests, so we pass the count as an argument + migrationCount: number = Object.keys(migrations).length, +) => { const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); const actualCacheVersion = cacheVersion || 0; - const migrationsPath = path.resolve(__dirname, './migrations'); - const migrationFiles = fs.readdirSync(migrationsPath); - const migrationCount = migrationFiles.length; // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { try { const migration = await import(`./migrations/${i}`); migration.default(); + setValue({ cacheName: CacheKeys.MIGRATION }, migrationCount); } catch (e) { logError(e); setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); return; } } - setValue({ cacheName: CacheKeys.MIGRATION }, migrationCount); }; export const useMigrate = () => { From 6fb2f02dd0d37eae9f15d202e5bc2213ebbf8ac9 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Sun, 16 Jun 2024 00:28:56 -0400 Subject: [PATCH 25/39] update test for malformed filenames --- ...teCacheToV1.test.ts => migrations.test.ts} | 68 ++++++++++++++++--- test/runMigration.test.ts | 51 -------------- 2 files changed, 60 insertions(+), 59 deletions(-) rename test/{migrateCacheToV1.test.ts => migrations.test.ts} (55%) delete mode 100644 test/runMigration.test.ts diff --git a/test/migrateCacheToV1.test.ts b/test/migrations.test.ts similarity index 55% rename from test/migrateCacheToV1.test.ts rename to test/migrations.test.ts index 2e53faa114..139dd562a0 100644 --- a/test/migrateCacheToV1.test.ts +++ b/test/migrations.test.ts @@ -1,15 +1,15 @@ -import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; +import * as logging from '../src/helpers/errorLogging'; import { CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; import migrateCacheToV1 from '../src/hooks/utils/cache/migrations/1'; import { getValue } from '../src/hooks/utils/cache/useLocalStorage'; +import { runMigrations } from '../src/hooks/utils/cache/useMigrate'; -// Clear localStorage before each test -beforeEach(() => { - localStorage.clear(); - vi.clearAllMocks(); -}); - -describe('migrateCacheToV1', () => { +describe('func migrateCacheToV1', () => { + beforeEach(() => { + localStorage.clear(); + vi.clearAllMocks(); + }); it('should correctly migrate a single favorite', () => { const oldKey = 'fract_11155111_favorites'; const oldValue = JSON.stringify({ @@ -84,3 +84,55 @@ describe('migrateCacheToV1', () => { expect(localStorage.getItem(oldKey)).toBeNull(); }); }); + +describe('func runMigrations (gap imports)', () => { + beforeEach(() => { + // Reset all mocks, ensuring fresh mock functions per test + vi.resetAllMocks(); + localStorage.clear(); + // Re-attach the spy before each test + vi.spyOn(logging, 'logError').mockImplementation(() => {}); + vi.mock('./migrations/1', () => ({ default: vi.fn() })); + vi.mock('./migrations/2', () => ({ default: vi.fn() })); + vi.mock('./migrations/4', () => ({ default: vi.fn() })); + }); + + it('should stop migration at first gap and log an error', async () => { + await runMigrations(3); + expect(logging.logError).toHaveBeenCalledOnce(); + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(2); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); +}); + +describe('func runMigrations (invalid filename)', () => { + beforeEach(() => { + vi.resetAllMocks(); + localStorage.clear(); + vi.spyOn(logging, 'logError').mockImplementation(() => {}); + vi.mock('../migrations/1', () => ({ default: vi.fn() })); + vi.mock('./migrations/2', () => ({ default: vi.fn() })); + vi.mock('./migrations/foo', () => ({ default: vi.fn() })); + }); + + it('should stop migration at malformed file name and log an error', async () => { + await runMigrations(3); + expect(logging.logError).toHaveBeenCalledOnce(); + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(2); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); +}); diff --git a/test/runMigration.test.ts b/test/runMigration.test.ts deleted file mode 100644 index 2eca14824e..0000000000 --- a/test/runMigration.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { describe, it, expect, beforeEach, vi } from 'vitest'; -import { CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; -import { getValue, setValue } from '../src/hooks/utils/cache/useLocalStorage'; -import { runMigrations } from '../src/hooks/utils/cache/useMigrate'; - -// Clear localStorage before each test -beforeEach(() => { - localStorage.clear(); - vi.clearAllMocks(); -}); - -describe('run migrations', () => { - it('should set migration version to current', async () => { - const oldKey = 'fract_11155111_favorites'; - const oldValue = JSON.stringify({ - v: ['0xd418E98a11B9189fCc05cddfbB10F4Cee996C749'], - e: -1, - }); - localStorage.setItem(oldKey, oldValue); - - await runMigrations(); - - const expectedNewValue = ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']; - const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); - if (!favoriteCache) { - throw new Error('Favorites cache not found'); - } - expect(favoriteCache).toStrictEqual(expectedNewValue); - - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } - expect(migrationCache).toBe(1); - }); - - it('should early exit', async () => { - setValue({ cacheName: CacheKeys.FAVORITES }, [ - 'sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749', - ]); - setValue({ cacheName: CacheKeys.MIGRATION }, 1); - - await runMigrations(); - - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } - expect(migrationCache).toBe(1); - }); -}); From 8843b83dae0ef220ff15210e39a18e01da809de6 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 00:55:36 -0400 Subject: [PATCH 26/39] properly set version number based index of loop - remove setValue from loop; --- src/hooks/utils/cache/useMigrate.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index bed903c70f..c8f6cf4b20 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -12,18 +12,19 @@ export const runMigrations = async ( const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); const actualCacheVersion = cacheVersion || 0; + let newVersion = actualCacheVersion; // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { try { - const migration = await import(`./migrations/${i}`); + const migration: { default: () => void } = await import(`./migrations/${i}`); migration.default(); - setValue({ cacheName: CacheKeys.MIGRATION }, migrationCount); + newVersion = i; } catch (e) { logError(e); - setValue({ cacheName: CacheKeys.MIGRATION }, i - 1); - return; + newVersion = i - 1; } } + setValue({ cacheName: CacheKeys.MIGRATION }, newVersion); }; export const useMigrate = () => { From 242361f815242e28d21a4094757d055817046200 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 00:56:02 -0400 Subject: [PATCH 27/39] add new test for success migration update. - fix hoisting issues with mocks --- test/migrations.test.ts | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/test/migrations.test.ts b/test/migrations.test.ts index 139dd562a0..9685529042 100644 --- a/test/migrations.test.ts +++ b/test/migrations.test.ts @@ -87,14 +87,13 @@ describe('func migrateCacheToV1', () => { describe('func runMigrations (gap imports)', () => { beforeEach(() => { - // Reset all mocks, ensuring fresh mock functions per test vi.resetAllMocks(); + vi.resetModules(); localStorage.clear(); - // Re-attach the spy before each test vi.spyOn(logging, 'logError').mockImplementation(() => {}); - vi.mock('./migrations/1', () => ({ default: vi.fn() })); - vi.mock('./migrations/2', () => ({ default: vi.fn() })); - vi.mock('./migrations/4', () => ({ default: vi.fn() })); + vi.doMock('./migrations/1', () => ({ default: vi.fn() })); + vi.doMock('./migrations/2', () => ({ default: vi.fn() })); + vi.doMock('./migrations/4', () => ({ default: vi.fn() })); }); it('should stop migration at first gap and log an error', async () => { @@ -115,11 +114,12 @@ describe('func runMigrations (gap imports)', () => { describe('func runMigrations (invalid filename)', () => { beforeEach(() => { vi.resetAllMocks(); + vi.resetModules(); localStorage.clear(); vi.spyOn(logging, 'logError').mockImplementation(() => {}); - vi.mock('../migrations/1', () => ({ default: vi.fn() })); - vi.mock('./migrations/2', () => ({ default: vi.fn() })); - vi.mock('./migrations/foo', () => ({ default: vi.fn() })); + vi.doMock('./migrations/1', () => ({ default: vi.fn() })); + vi.doMock('./migrations/2', () => ({ default: vi.fn() })); + vi.doMock('./migrations/foo', () => ({ default: vi.fn() })); }); it('should stop migration at malformed file name and log an error', async () => { @@ -136,3 +136,26 @@ describe('func runMigrations (invalid filename)', () => { vi.restoreAllMocks(); }); }); + +describe('func runMigrations (successfully migrate to lastest)', () => { + beforeEach(() => { + vi.resetAllMocks(); + localStorage.clear(); + vi.doMock('./migrations/1', () => ({ default: () => {} })); + vi.doMock('./migrations/2', () => ({ default: () => {} })); + vi.doMock('./migrations/3', () => ({ default: () => {} })); + }); + + it('should successfully migrate to the latest version', async () => { + await runMigrations(3); + const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); + if (!migrationCache) { + throw new Error('Migration cache not found'); + } + expect(migrationCache).toBe(3); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); +}); From 492ebffbf71eb1fbc6200db5192c161ddbed753d Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:50:47 -0400 Subject: [PATCH 28/39] can delete --- test/migrations.test.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test/migrations.test.ts b/test/migrations.test.ts index 9685529042..da114d60f1 100644 --- a/test/migrations.test.ts +++ b/test/migrations.test.ts @@ -22,9 +22,6 @@ describe('func migrateCacheToV1', () => { migrateCacheToV1(); const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); - if (!favoriteCache) { - throw new Error('Favorites cache not found'); - } expect(favoriteCache).toStrictEqual(expectedNewValue); expect(localStorage.getItem(oldKey)).toBeNull(); }); @@ -52,9 +49,6 @@ describe('func migrateCacheToV1', () => { migrateCacheToV1(); const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); - if (!favoriteCache) { - throw new Error('Favorites cache not found'); - } expect(favoriteCache).toStrictEqual(expectedNewValue); expect(localStorage.getItem(oldKey1)).toBeNull(); expect(localStorage.getItem(oldKey2)).toBeNull(); @@ -100,9 +94,6 @@ describe('func runMigrations (gap imports)', () => { await runMigrations(3); expect(logging.logError).toHaveBeenCalledOnce(); const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } expect(migrationCache).toBe(2); }); @@ -126,9 +117,6 @@ describe('func runMigrations (invalid filename)', () => { await runMigrations(3); expect(logging.logError).toHaveBeenCalledOnce(); const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } expect(migrationCache).toBe(2); }); @@ -149,9 +137,6 @@ describe('func runMigrations (successfully migrate to lastest)', () => { it('should successfully migrate to the latest version', async () => { await runMigrations(3); const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - if (!migrationCache) { - throw new Error('Migration cache not found'); - } expect(migrationCache).toBe(3); }); From 3b9191ceb56d017d855666e320c3da138dd1c782 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:51:58 -0400 Subject: [PATCH 29/39] remove this early exit --- src/hooks/utils/cache/migrations/1.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hooks/utils/cache/migrations/1.ts b/src/hooks/utils/cache/migrations/1.ts index c9b99fe197..bf6a66468e 100644 --- a/src/hooks/utils/cache/migrations/1.ts +++ b/src/hooks/utils/cache/migrations/1.ts @@ -10,9 +10,7 @@ export default function v1MigrateFavorites() { // Migrate old cache keys to new format const keys = Object.keys(localStorage); const fractKeys = keys.filter(key => key.startsWith('fract_')); - if (!fractKeys.length) { - return; - } + // Get All Network Favorites const favoritesCache = fractKeys.filter(key => key.endsWith('favorites')); const newFavorites: string[] = []; From 82d3cf46fcede3f62d3257543dcbe1959ac4a56d Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:53:56 -0400 Subject: [PATCH 30/39] early exit if migration is count is same as actualCacheVersion --- src/hooks/utils/cache/useMigrate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index c8f6cf4b20..4ccc153059 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -10,8 +10,8 @@ export const runMigrations = async ( migrationCount: number = Object.keys(migrations).length, ) => { const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); - const actualCacheVersion = cacheVersion || 0; + if(cacheVersion === migrationCount) return; let newVersion = actualCacheVersion; // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { From 18a47e45db071885f525a14a8465488c6271de89 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:55:08 -0400 Subject: [PATCH 31/39] add new expect to test before test is run --- test/migrations.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/migrations.test.ts b/test/migrations.test.ts index da114d60f1..39bf1ec104 100644 --- a/test/migrations.test.ts +++ b/test/migrations.test.ts @@ -135,9 +135,13 @@ describe('func runMigrations (successfully migrate to lastest)', () => { }); it('should successfully migrate to the latest version', async () => { + const migrationCacheBefore = getValue({ cacheName: CacheKeys.MIGRATION }); + expect(migrationCacheBefore).toBe(null); + await runMigrations(3); - const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); - expect(migrationCache).toBe(3); + + const migrationCacheAfter = getValue({ cacheName: CacheKeys.MIGRATION }); + expect(migrationCacheAfter).toBe(3); }); afterEach(() => { From b495b31b9f4ffa9f0947c7471a63e6abba417190 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:56:04 -0400 Subject: [PATCH 32/39] add never expire param --- src/hooks/utils/cache/useMigrate.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 4ccc153059..bf59bcb97f 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -1,6 +1,6 @@ import { useEffect, useRef } from 'react'; import { logError } from '../../../helpers/errorLogging'; -import { CacheKeys } from './cacheDefaults'; +import { CacheExpiry, CacheKeys } from './cacheDefaults'; import { getValue, setValue } from './useLocalStorage'; const migrations = import.meta.glob('./migrations/*'); @@ -24,7 +24,7 @@ export const runMigrations = async ( newVersion = i - 1; } } - setValue({ cacheName: CacheKeys.MIGRATION }, newVersion); + setValue({ cacheName: CacheKeys.MIGRATION }, newVersion, CacheExpiry.NEVER); }; export const useMigrate = () => { From d9307e5b5bf569a2104ddf8a414cde490033a96e Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:04:18 -0400 Subject: [PATCH 33/39] run pretty/lint --- src/hooks/utils/cache/useMigrate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index bf59bcb97f..02cd5f0b25 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -11,7 +11,7 @@ export const runMigrations = async ( ) => { const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); const actualCacheVersion = cacheVersion || 0; - if(cacheVersion === migrationCount) return; + if (cacheVersion === migrationCount) return; let newVersion = actualCacheVersion; // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { From 5626da1faa33b6fef203275cf98f6f51d30b0eff Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Mon, 17 Jun 2024 11:09:58 -0400 Subject: [PATCH 34/39] Small code tidying up --- src/hooks/utils/cache/migrations/1.ts | 51 +++++++++++++++------------ test/migrations.test.ts | 12 +++---- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/hooks/utils/cache/migrations/1.ts b/src/hooks/utils/cache/migrations/1.ts index bf6a66468e..fe202ea1d1 100644 --- a/src/hooks/utils/cache/migrations/1.ts +++ b/src/hooks/utils/cache/migrations/1.ts @@ -2,42 +2,49 @@ import { addNetworkPrefix } from '../../../../utils/url'; // This should be a temporary hook to migrate the old local storage to the new one // and should be removed after a few months -import { CacheKeys } from '../cacheDefaults'; +import { CacheExpiry, CacheKeys } from '../cacheDefaults'; import { setValue } from '../useLocalStorage'; -//@dev for testing seperated the function from the hook and export -export default function v1MigrateFavorites() { - // Migrate old cache keys to new format - const keys = Object.keys(localStorage); - const fractKeys = keys.filter(key => key.startsWith('fract_')); +const deleteAllV0FractData = (fractKeys: string[]) => { + // delete old cache + fractKeys.forEach(key => { + localStorage.removeItem(key); + }); +}; + +const createV1FavoratesData = (v0FavoritesData: string[]) => { + if (v0FavoritesData.length === 0) { + return; + } - // Get All Network Favorites - const favoritesCache = fractKeys.filter(key => key.endsWith('favorites')); const newFavorites: string[] = []; // loop through all favorites - for (const favorite of favoritesCache) { + for (const v0Favorite of v0FavoritesData) { // Get ChainId from favorite key - const [, chainId] = favorite.split('_'); + const [, chainId] = v0Favorite.split('_'); if (Number.isNaN(Number(chainId))) { continue; } - const favoritesValue = localStorage.getItem(favorite); - if (favoritesValue) { + const v0FavoriteValue = localStorage.getItem(v0Favorite); + if (v0FavoriteValue) { // Parse favorites value and add network prefix - const parsedValue: { v: string[] } = JSON.parse(favoritesValue); - parsedValue.v.forEach((value: string) => { + const v0ParsedValue: { v: string[] } = JSON.parse(v0FavoriteValue); + v0ParsedValue.v.forEach((value: string) => { newFavorites.push(addNetworkPrefix(value, Number(chainId))); }); } } - if (newFavorites.length) { - // Set new Favorites cache - setValue({ cacheName: CacheKeys.FAVORITES }, newFavorites); - } - // delete old cache - fractKeys.forEach(key => { - localStorage.removeItem(key); - }); + // Set new Favorites cache + setValue({ cacheName: CacheKeys.FAVORITES }, newFavorites, CacheExpiry.NEVER); +}; + +//@dev for testing seperated the function from the hook and export +export default function migration1() { + const allV0FractKeys = Object.keys(localStorage).filter(key => key.startsWith('fract_')); + const v0FavoritesData = allV0FractKeys.filter(key => key.endsWith('favorites')); + + createV1FavoratesData(v0FavoritesData); + deleteAllV0FractData(allV0FractKeys); } diff --git a/test/migrations.test.ts b/test/migrations.test.ts index 39bf1ec104..00bfbe6ed6 100644 --- a/test/migrations.test.ts +++ b/test/migrations.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; import * as logging from '../src/helpers/errorLogging'; import { CacheKeys } from '../src/hooks/utils/cache/cacheDefaults'; -import migrateCacheToV1 from '../src/hooks/utils/cache/migrations/1'; +import migration1 from '../src/hooks/utils/cache/migrations/1'; import { getValue } from '../src/hooks/utils/cache/useLocalStorage'; import { runMigrations } from '../src/hooks/utils/cache/useMigrate'; @@ -20,7 +20,7 @@ describe('func migrateCacheToV1', () => { const expectedNewValue = ['sep:0xd418E98a11B9189fCc05cddfbB10F4Cee996C749']; - migrateCacheToV1(); + migration1(); const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); expect(favoriteCache).toStrictEqual(expectedNewValue); expect(localStorage.getItem(oldKey)).toBeNull(); @@ -47,7 +47,7 @@ describe('func migrateCacheToV1', () => { 'eth:0xabcdE98a11B9189fCc05cddfbB10F4Cee996C999', ]; - migrateCacheToV1(); + migration1(); const favoriteCache = getValue({ cacheName: CacheKeys.FAVORITES }); expect(favoriteCache).toStrictEqual(expectedNewValue); expect(localStorage.getItem(oldKey1)).toBeNull(); @@ -55,12 +55,12 @@ describe('func migrateCacheToV1', () => { }); it('should handle an empty localStorage without errors', () => { - migrateCacheToV1(); + migration1(); }); it('should handle localStorage without relevant keys', () => { localStorage.setItem('unrelatedKey', 'someValue'); - migrateCacheToV1(); + migration1(); expect(localStorage.getItem('unrelatedKey')).toBe('someValue'); }); @@ -73,7 +73,7 @@ describe('func migrateCacheToV1', () => { }); localStorage.setItem(oldKey, oldValue); - migrateCacheToV1(); + migration1(); expect(localStorage.getItem(oldKey)).toBeNull(); }); From d2e616e5fb66747d8b9bb4f9573fa712a6549f49 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:05:31 -0400 Subject: [PATCH 35/39] add file extension --- src/hooks/utils/cache/useMigrate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 02cd5f0b25..6ddc8e88d6 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -16,7 +16,7 @@ export const runMigrations = async ( // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { try { - const migration: { default: () => void } = await import(`./migrations/${i}`); + const migration: { default: () => void } = await import(`./migrations/${i}.ts`); migration.default(); newVersion = i; } catch (e) { From 3cdce280adabfd04c6f80e7534952949ca2cf8f9 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:53:30 -0400 Subject: [PATCH 36/39] use glob import directly --- src/hooks/utils/cache/useMigrate.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index 6ddc8e88d6..b4ce59b887 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -3,12 +3,12 @@ import { logError } from '../../../helpers/errorLogging'; import { CacheExpiry, CacheKeys } from './cacheDefaults'; import { getValue, setValue } from './useLocalStorage'; -const migrations = import.meta.glob('./migrations/*'); - export const runMigrations = async ( // @dev import.meta.glob can not be mocked in tests, so we pass the count as an argument - migrationCount: number = Object.keys(migrations).length, + migrations = import.meta.glob('./migrations/*'), ) => { + console.log("🚀 ~ migrations:", migrations) + const migrationCount = Object.keys(migrations).length; const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); const actualCacheVersion = cacheVersion || 0; if (cacheVersion === migrationCount) return; @@ -16,8 +16,10 @@ export const runMigrations = async ( // loop through each pending migration and run in turn for (let i = actualCacheVersion + 1; i <= migrationCount; i++) { try { - const migration: { default: () => void } = await import(`./migrations/${i}.ts`); - migration.default(); + const migration = (await migrations[`./migrations/${i}.ts`]()) as { + default: () => Promise; + }; + await migration.default(); newVersion = i; } catch (e) { logError(e); From 5c10fa785543c643fc48166d93538fefe382f032 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:55:41 -0400 Subject: [PATCH 37/39] update tests for new setup --- test/migrations.test.ts | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/test/migrations.test.ts b/test/migrations.test.ts index 00bfbe6ed6..e50b48005e 100644 --- a/test/migrations.test.ts +++ b/test/migrations.test.ts @@ -80,18 +80,23 @@ describe('func migrateCacheToV1', () => { }); describe('func runMigrations (gap imports)', () => { + const migrations = { + './migrations/1.ts': () => Promise.resolve({ default: vi.fn() }), + './migrations/2.ts': () => Promise.resolve({ default: vi.fn() }), + './migrations/4.ts': () => Promise.resolve({ default: vi.fn() }), + }; beforeEach(() => { vi.resetAllMocks(); vi.resetModules(); localStorage.clear(); vi.spyOn(logging, 'logError').mockImplementation(() => {}); - vi.doMock('./migrations/1', () => ({ default: vi.fn() })); - vi.doMock('./migrations/2', () => ({ default: vi.fn() })); - vi.doMock('./migrations/4', () => ({ default: vi.fn() })); + Object.entries(migrations).forEach(([p, m]) => { + vi.doMock(p, m); + }); }); it('should stop migration at first gap and log an error', async () => { - await runMigrations(3); + await runMigrations(migrations); expect(logging.logError).toHaveBeenCalledOnce(); const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); expect(migrationCache).toBe(2); @@ -103,18 +108,23 @@ describe('func runMigrations (gap imports)', () => { }); describe('func runMigrations (invalid filename)', () => { + const migrations = { + './migrations/1.ts': () => Promise.resolve({ default: vi.fn() }), + './migrations/2.ts': () => Promise.resolve({ default: vi.fn() }), + './migrations/foo.ts': () => Promise.resolve({ default: vi.fn() }), + }; beforeEach(() => { vi.resetAllMocks(); vi.resetModules(); localStorage.clear(); vi.spyOn(logging, 'logError').mockImplementation(() => {}); - vi.doMock('./migrations/1', () => ({ default: vi.fn() })); - vi.doMock('./migrations/2', () => ({ default: vi.fn() })); - vi.doMock('./migrations/foo', () => ({ default: vi.fn() })); + Object.entries(migrations).forEach(([p, m]) => { + vi.doMock(p, m); + }); }); it('should stop migration at malformed file name and log an error', async () => { - await runMigrations(3); + await runMigrations(migrations); expect(logging.logError).toHaveBeenCalledOnce(); const migrationCache = getValue({ cacheName: CacheKeys.MIGRATION }); expect(migrationCache).toBe(2); @@ -126,19 +136,24 @@ describe('func runMigrations (invalid filename)', () => { }); describe('func runMigrations (successfully migrate to lastest)', () => { + const migrations = { + './migrations/1.ts': () => Promise.resolve({ default: vi.fn() }), + './migrations/2.ts': () => Promise.resolve({ default: vi.fn() }), + './migrations/3.ts': () => Promise.resolve({ default: vi.fn() }), + }; beforeEach(() => { vi.resetAllMocks(); localStorage.clear(); - vi.doMock('./migrations/1', () => ({ default: () => {} })); - vi.doMock('./migrations/2', () => ({ default: () => {} })); - vi.doMock('./migrations/3', () => ({ default: () => {} })); + Object.entries(migrations).forEach(([p, m]) => { + vi.doMock(p, m); + }); }); it('should successfully migrate to the latest version', async () => { const migrationCacheBefore = getValue({ cacheName: CacheKeys.MIGRATION }); expect(migrationCacheBefore).toBe(null); - await runMigrations(3); + await runMigrations(migrations); const migrationCacheAfter = getValue({ cacheName: CacheKeys.MIGRATION }); expect(migrationCacheAfter).toBe(3); From 9bb0ff2ffb4a7c0bb4c798bbd6869ff91a70ffd5 Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:56:09 -0400 Subject: [PATCH 38/39] run pretty/lint --- src/hooks/utils/cache/useMigrate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index b4ce59b887..e045d54340 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -7,7 +7,7 @@ export const runMigrations = async ( // @dev import.meta.glob can not be mocked in tests, so we pass the count as an argument migrations = import.meta.glob('./migrations/*'), ) => { - console.log("🚀 ~ migrations:", migrations) + console.log('🚀 ~ migrations:', migrations); const migrationCount = Object.keys(migrations).length; const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); const actualCacheVersion = cacheVersion || 0; From 367dbd66978b8e3019319faf61d176702cb0c0ba Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:59:31 -0400 Subject: [PATCH 39/39] remove console log --- src/hooks/utils/cache/useMigrate.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hooks/utils/cache/useMigrate.ts b/src/hooks/utils/cache/useMigrate.ts index e045d54340..a11fcf531a 100644 --- a/src/hooks/utils/cache/useMigrate.ts +++ b/src/hooks/utils/cache/useMigrate.ts @@ -7,7 +7,6 @@ export const runMigrations = async ( // @dev import.meta.glob can not be mocked in tests, so we pass the count as an argument migrations = import.meta.glob('./migrations/*'), ) => { - console.log('🚀 ~ migrations:', migrations); const migrationCount = Object.keys(migrations).length; const cacheVersion = getValue({ cacheName: CacheKeys.MIGRATION }); const actualCacheVersion = cacheVersion || 0;