diff --git a/lib/utils/ens-cache.test.js b/lib/utils/ens-cache.test.js index 2fbda32a0..46f6a4359 100644 --- a/lib/utils/ens-cache.test.js +++ b/lib/utils/ens-cache.test.js @@ -1,107 +1,102 @@ // @flow import { ethers } from 'ethers'; import { ENSCache } from './ens-cache'; const provider = new ethers.providers.AlchemyProvider( 'mainnet', process.env.ALCHEMY_API_KEY, ); const ensCache = new ENSCache(provider); const baseLookupAddress = provider.lookupAddress.bind(provider); let timesLookupAddressCalled = 0; provider.lookupAddress = (ethAddress: string) => { timesLookupAddressCalled++; return baseLookupAddress(ethAddress); }; const baseResolveName = provider.resolveName.bind(provider); let timesResolveNameCalled = 0; provider.resolveName = (ensName: string) => { timesResolveNameCalled++; return baseResolveName(ensName); }; if (!process.env.ALCHEMY_API_KEY) { // Test only works if we can query blockchain console.log( 'skipped running ENSCache tests because of missing ALCHEMY_API_KEY ' + 'environmental variable', ); } +const ashoatDotEth = 'ashoat.eth'; +const ashoatAddr = '0x911413ef4127910d79303483f7470d095f399ca9'; + describe('getNameForAddress', () => { it('should fail to return ashoat.eth if not in cache', async () => { if (!process.env.ALCHEMY_API_KEY) { return; } - const obviouslyAshoatEth = ensCache.getCachedNameForAddress( - '0x911413ef4127910d79303483f7470d095f399ca9', - ); - expect(obviouslyAshoatEth).toBe(undefined); + const ashoatEthResult = ensCache.getCachedNameForAddress(ashoatAddr); + expect(ashoatEthResult).toBe(undefined); }); it('should return ashoat.eth', async () => { if (!process.env.ALCHEMY_API_KEY) { return; } - const obviouslyAshoatEth = await ensCache.getNameForAddress( - '0x911413ef4127910d79303483f7470d095f399ca9', - ); - expect(obviouslyAshoatEth).toBe('ashoat.eth'); + const ashoatEthResult = await ensCache.getNameForAddress(ashoatAddr); + expect(ashoatEthResult).toBe(ashoatDotEth); }); it('should return ashoat.eth if in cache', async () => { if (!process.env.ALCHEMY_API_KEY) { return; } - const obviouslyAshoatEth = ensCache.getCachedNameForAddress( - '0x911413ef4127910d79303483f7470d095f399ca9', - ); - expect(obviouslyAshoatEth).toBe('ashoat.eth'); + const ashoatEthResult = ensCache.getCachedNameForAddress(ashoatAddr); + expect(ashoatEthResult).toBe(ashoatDotEth); }); it('should have ashoat.eth cached', async () => { if (!process.env.ALCHEMY_API_KEY) { return; } const timesLookupAddressCalledBefore = timesLookupAddressCalled; - const obviouslyAshoatEth = await ensCache.getNameForAddress( - '0x911413ef4127910d79303483f7470d095f399ca9', - ); - expect(obviouslyAshoatEth).toBe('ashoat.eth'); + const ashoatEthResult = await ensCache.getNameForAddress(ashoatAddr); + expect(ashoatEthResult).toBe(ashoatDotEth); expect(timesLookupAddressCalled).toBe(timesLookupAddressCalledBefore); }); }); describe('getAddressForName', () => { it("should fail to return ashoat.eth's address if not in cache", async () => { if (!process.env.ALCHEMY_API_KEY) { return; } - const ashoatAddr = ensCache.getCachedAddressForName('ashoat.eth'); - expect(ashoatAddr).toBe(undefined); + const ashoatAddrResult = ensCache.getCachedAddressForName(ashoatDotEth); + expect(ashoatAddrResult).toBe(undefined); }); it("should return ashoat.eth's address", async () => { if (!process.env.ALCHEMY_API_KEY) { return; } - const ashoatAddr = await ensCache.getAddressForName('ashoat.eth'); - expect(ashoatAddr).toBe('0x911413ef4127910d79303483f7470d095f399ca9'); + const ashoatAddrResult = await ensCache.getAddressForName(ashoatDotEth); + expect(ashoatAddrResult).toBe(ashoatAddr); }); it("should return ashoat.eth's address if in cache", async () => { if (!process.env.ALCHEMY_API_KEY) { return; } - const ashoatAddr = ensCache.getCachedAddressForName('ashoat.eth'); - expect(ashoatAddr).toBe('0x911413ef4127910d79303483f7470d095f399ca9'); + const ashoatAddrResult = ensCache.getCachedAddressForName(ashoatDotEth); + expect(ashoatAddrResult).toBe(ashoatAddr); }); it("should have ashoat.eth's address cached", async () => { if (!process.env.ALCHEMY_API_KEY) { return; } const timesResolveNameCalledBefore = timesResolveNameCalled; - const ashoatAddr = await ensCache.getAddressForName('ashoat.eth'); - expect(ashoatAddr).toBe('0x911413ef4127910d79303483f7470d095f399ca9'); + const ashoatAddrResult = await ensCache.getAddressForName(ashoatDotEth); + expect(ashoatAddrResult).toBe(ashoatAddr); expect(timesResolveNameCalled).toBe(timesResolveNameCalledBefore); }); });