From 54f4bdc64e02222bea7b7a14c23c5f9a5f6272db Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Wed, 26 Aug 2026 16:08:01 +0200 Subject: [PATCH 1/7] test: used setup function in 'falsy but valid cache values' tests --- .../src/caching/useCache.test.ts | 124 +++++------------- 1 file changed, 30 insertions(+), 94 deletions(-) diff --git a/packages/tron-wallet-snap/src/caching/useCache.test.ts b/packages/tron-wallet-snap/src/caching/useCache.test.ts index a0efd1f5..b6181b1a 100644 --- a/packages/tron-wallet-snap/src/caching/useCache.test.ts +++ b/packages/tron-wallet-snap/src/caching/useCache.test.ts @@ -83,78 +83,6 @@ async function withUseCache(testFn: WithUseCacheCallback): Promise { } describe('useCache', () => { - // Spy to check if the original function was executed or not - let actualExecutionSpy: jest.Mock; - - // Mock cache - let cache: ICache; - - // Common cache options - let cacheOptions: CacheOptions; - - // Original test functions - let testFunction: () => Promise; - let testFunctionWithArgs: (arg1: string, arg2: number) => Promise; - let testFunctionWithComplexArgs: (obj: { - name: string; - age: number; - }) => Promise; - - // Cached versions - let cachedTestFunction: () => Promise; - let cachedTestFunctionWithArgs: ( - arg1: string, - arg2: number, - ) => Promise; - let cachedTestFunctionWithComplexArgs: (obj: { - name: string; - age: number; - }) => Promise; - - beforeEach(() => { - // Reset mocks for each test - actualExecutionSpy = jest.fn().mockResolvedValue('test'); - - // Create a mock cache - cache = { - get: jest.fn().mockResolvedValue(undefined), - set: jest.fn().mockResolvedValue(undefined), - } as unknown as ICache; - - // Define common cache options - cacheOptions = { - ttlMilliseconds: 1000, - functionName: 'testFunction', - }; - - // Define original functions - testFunction = async () => actualExecutionSpy(); - testFunctionWithArgs = async (arg1: string, arg2: number) => - actualExecutionSpy(arg1, arg2); - testFunctionWithComplexArgs = async (obj: { name: string; age: number }) => - actualExecutionSpy(obj); - - // Create cached versions - cachedTestFunction = useCache(testFunction, cache, { - ...cacheOptions, - functionName: 'testFunction', - }); - - cachedTestFunctionWithArgs = useCache(testFunctionWithArgs, cache, { - ...cacheOptions, - functionName: 'testFunctionWithArgs', - }); - - cachedTestFunctionWithComplexArgs = useCache( - testFunctionWithComplexArgs, - cache, - { - ...cacheOptions, - functionName: 'testFunctionWithComplexArgs', - }, - ); - }); - describe('when the data is not cached', () => { it('should cache the result of a function', async () => { await withUseCache( @@ -333,33 +261,41 @@ describe('useCache', () => { describe('falsy but valid cache values', () => { it('should handle falsy but valid cache values (false, 0, empty string)', async () => { - // Test with false - jest.spyOn(cache, 'get').mockResolvedValue(false); - let result = await cachedTestFunction(); - expect(result).toBe(false); - expect(actualExecutionSpy).not.toHaveBeenCalled(); - - // Test with 0 - jest.spyOn(cache, 'get').mockResolvedValue(0); - result = await cachedTestFunction(); - expect(result).toBe(0); - expect(actualExecutionSpy).not.toHaveBeenCalled(); - - // Test with empty string - jest.spyOn(cache, 'get').mockResolvedValue(''); - result = await cachedTestFunction(); - expect(result).toBe(''); - expect(actualExecutionSpy).not.toHaveBeenCalled(); + await withUseCache( + async ({ actualExecutionSpy, cache, cachedTestFunction }) => { + // Test with false + cache.get.mockResolvedValue(false); + let result = await cachedTestFunction(); + expect(result).toBe(false); + expect(actualExecutionSpy).not.toHaveBeenCalled(); + + // Test with 0 + cache.get.mockResolvedValue(0); + result = await cachedTestFunction(); + expect(result).toBe(0); + expect(actualExecutionSpy).not.toHaveBeenCalled(); + + // Test with empty string + cache.get.mockResolvedValue(''); + result = await cachedTestFunction(); + expect(result).toBe(''); + expect(actualExecutionSpy).not.toHaveBeenCalled(); + }, + ); }); it('should execute the function when cache returns undefined', async () => { - jest.spyOn(cache, 'get').mockResolvedValue(undefined); - actualExecutionSpy.mockResolvedValueOnce('test'); + await withUseCache( + async ({ actualExecutionSpy, cache, cachedTestFunction }) => { + cache.get.mockResolvedValue(undefined); + actualExecutionSpy.mockResolvedValueOnce('test'); - const result = await cachedTestFunction(); + const result = await cachedTestFunction(); - expect(result).toBe('test'); - expect(actualExecutionSpy).toHaveBeenCalledTimes(1); + expect(result).toBe('test'); + expect(actualExecutionSpy).toHaveBeenCalledTimes(1); + }, + ); }); }); }); From 85e71fe2baced1c28fa8f71eff0028ac12a15c06 Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Wed, 26 Aug 2026 16:17:59 +0200 Subject: [PATCH 2/7] fix: added missed CacheOptions type --- packages/tron-wallet-snap/src/caching/useCache.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/tron-wallet-snap/src/caching/useCache.test.ts b/packages/tron-wallet-snap/src/caching/useCache.test.ts index b6181b1a..bd19545a 100644 --- a/packages/tron-wallet-snap/src/caching/useCache.test.ts +++ b/packages/tron-wallet-snap/src/caching/useCache.test.ts @@ -1,11 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import type { Serializable } from '../utils/serialization/types'; import type { ICache } from './ICache'; -import { useCache } from './useCache'; -import type { CacheOptions } from './useCache'; +import { CacheOptions, useCache } from './useCache'; // Define common cache options -const cacheOptions = { +const cacheOptions: CacheOptions = { ttlMilliseconds: 1000, functionName: 'testFunction', }; From 8411214d23438c4af2be410d07a9de434e178f2b Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Wed, 26 Aug 2026 16:24:02 +0200 Subject: [PATCH 3/7] chore: prune suppressions --- eslint-suppressions.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 06d37eb0..572b02d1 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1641,11 +1641,6 @@ "count": 1 } }, - "packages/tron-wallet-snap/src/caching/useCache.test.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 4 - } - }, "packages/tron-wallet-snap/src/caching/useCacheUntil.test.ts": { "@typescript-eslint/explicit-function-return-type": { "count": 2 @@ -1815,4 +1810,4 @@ "count": 2 } } -} +} \ No newline at end of file From c101a7e61bf0bd9b635ea90116b8b2b831e5bcfe Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Wed, 26 Aug 2026 16:27:21 +0200 Subject: [PATCH 4/7] chore: lint fix --- eslint-suppressions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 572b02d1..f31d7f0e 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1810,4 +1810,4 @@ "count": 2 } } -} \ No newline at end of file +} From 6e8bbea543406a3306864fbe83efd85aef8b7fae Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Wed, 26 Aug 2026 16:50:40 +0200 Subject: [PATCH 5/7] chore: shasum # Conflicts: # packages/tron-wallet-snap/snap.manifest.json --- packages/tron-wallet-snap/snap.manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index 900a30df..f17db91d 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "IlS8YzpfJun/5aMb6cYAIzKBcn3x9BjOMVYJUE9zFzo=", + "shasum": "y1eBQiM9lDqVQ6wJj1BG3qtDXB45dwC7SdKzYF5YZWo=", "location": { "npm": { "filePath": "dist/bundle.js", From 7d1ff68fa39069e880a52d1b66c5f827ec321f8d Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Thu, 27 Aug 2026 16:15:52 +0200 Subject: [PATCH 6/7] chore: shasum --- packages/tron-wallet-snap/snap.manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index f17db91d..900a30df 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "y1eBQiM9lDqVQ6wJj1BG3qtDXB45dwC7SdKzYF5YZWo=", + "shasum": "IlS8YzpfJun/5aMb6cYAIzKBcn3x9BjOMVYJUE9zFzo=", "location": { "npm": { "filePath": "dist/bundle.js", From 9d3c4947eb4265cd16691b631afdd432f6ce6bd0 Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Thu, 27 Aug 2026 16:43:17 +0200 Subject: [PATCH 7/7] test: removed es lint disable rule --- packages/tron-wallet-snap/src/caching/useCache.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/tron-wallet-snap/src/caching/useCache.test.ts b/packages/tron-wallet-snap/src/caching/useCache.test.ts index bd19545a..59d1be2d 100644 --- a/packages/tron-wallet-snap/src/caching/useCache.test.ts +++ b/packages/tron-wallet-snap/src/caching/useCache.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import type { Serializable } from '../utils/serialization/types'; import type { ICache } from './ICache'; import { CacheOptions, useCache } from './useCache';