Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32822119
D7044.1768055059.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7044.1768055059.diff
View Options
diff --git a/lib/utils/ens-cache.test.js b/lib/utils/ens-cache.test.js
--- a/lib/utils/ens-cache.test.js
+++ b/lib/utils/ens-cache.test.js
@@ -24,6 +24,13 @@
return baseResolveName(ensName);
};
+const baseGetAvatar = provider.getAvatar.bind(provider);
+let timesGetAvatarCalled = 0;
+provider.getAvatar = (ethAddress: string) => {
+ timesGetAvatarCalled++;
+ return baseGetAvatar(ethAddress);
+};
+
if (!process.env.ALCHEMY_API_KEY) {
// Test only works if we can query blockchain
console.log(
@@ -138,7 +145,7 @@
const timesResolveNameCalledBeforeSingleFetch = timesResolveNameCalled;
const ashoatAddrResult1 = await ensCache.getAddressForName(ashoatDotEth);
expect(ashoatAddrResult1).toBe(ashoatAddr);
- const timesResolveNamesCalledForSingleFetch =
+ const timesResolveNameCalledForSingleFetch =
timesResolveNameCalled - timesResolveNameCalledBeforeSingleFetch;
ensCache.clearCache();
@@ -153,7 +160,7 @@
timesResolveNameCalled - timesResolveNameCalledBeforeDoubleFetch;
expect(timesResolveNamesCalledForDoubleFetch).toBe(
- timesResolveNamesCalledForSingleFetch,
+ timesResolveNameCalledForSingleFetch,
);
});
});
@@ -184,4 +191,44 @@
ensCache.getCachedAvatarURIForAddress(ashoatAddr);
expect(ashoatAvatarResult).toBe(ashoatAvatar);
});
+ it("should have ashoat.eth's avatar cached", async () => {
+ if (!process.env.ALCHEMY_API_KEY) {
+ return;
+ }
+ const timesGetAvatarCalledBefore = timesGetAvatarCalled;
+ const ashoatAvatarResult = await ensCache.getAvatarURIForAddress(
+ ashoatAddr,
+ );
+ expect(ashoatAvatarResult).toBe(ashoatAvatar);
+ expect(timesGetAvatarCalled).toBe(timesGetAvatarCalledBefore);
+ });
+ it('should dedup simultaneous fetches', async () => {
+ if (!process.env.ALCHEMY_API_KEY) {
+ return;
+ }
+
+ ensCache.clearCache();
+ const timesGetAvatarCalledBeforeSingleFetch = timesGetAvatarCalled;
+ const ashoatAvatarResult1 = await ensCache.getAvatarURIForAddress(
+ ashoatAddr,
+ );
+ expect(ashoatAvatarResult1).toBe(ashoatAvatar);
+ const timesGetAvatarCalledForSingleFetch =
+ timesGetAvatarCalled - timesGetAvatarCalledBeforeSingleFetch;
+
+ ensCache.clearCache();
+ const timesGetAvatarCalledBeforeDoubleFetch = timesGetAvatarCalled;
+ const [ashoatAvatarResult2, ashoatAvatarResult3] = await Promise.all([
+ ensCache.getAvatarURIForAddress(ashoatAddr),
+ ensCache.getAvatarURIForAddress(ashoatAddr),
+ ]);
+ expect(ashoatAvatarResult2).toBe(ashoatAvatar);
+ expect(ashoatAvatarResult3).toBe(ashoatAvatar);
+ const timesGetAvatarCalledForDoubleFetch =
+ timesGetAvatarCalled - timesGetAvatarCalledBeforeDoubleFetch;
+
+ expect(timesGetAvatarCalledForDoubleFetch).toBe(
+ timesGetAvatarCalledForSingleFetch,
+ );
+ });
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 10, 2:24 PM (10 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5915425
Default Alt Text
D7044.1768055059.diff (2 KB)
Attached To
Mode
D7044: [lib] Add tests for caching behavior of getAvatarURIForAddress
Attached
Detach File
Event Timeline
Log In to Comment