Page MenuHomePhabricator

D11487.diff
No OneTemporary

D11487.diff

diff --git a/lib/utils/ens-cache.js b/lib/utils/ens-cache.js
--- a/lib/utils/ens-cache.js
+++ b/lib/utils/ens-cache.js
@@ -58,7 +58,7 @@
class ENSCache {
provider: EthersProvider;
batchReverseResolverSmartContract: ?ReverseRecordsEthersSmartContract;
- batchReverseResolverSmartContractPromise: Promise<ReverseRecordsEthersSmartContract>;
+ batchReverseResolverSmartContractPromise: Promise<?ReverseRecordsEthersSmartContract>;
// Maps from normalized ETH address to a cache entry for its name
nameQueryCache: Map<string, ENSNameQueryCacheEntry> = new Map();
@@ -72,15 +72,15 @@
this.batchReverseResolverSmartContractPromise = (async () => {
const { chainId } = await provider.getNetwork();
const reverseRecordsAddress = resolverAddresses[chainId];
- invariant(
- reverseRecordsAddress,
- `no ReverseRecords smart contract address for chaind ID ${chainId}!`,
- );
- this.batchReverseResolverSmartContract = new Contract(
- reverseRecordsAddress,
- resolverABI,
- provider,
- );
+ if (reverseRecordsAddress) {
+ this.batchReverseResolverSmartContract = new Contract(
+ reverseRecordsAddress,
+ resolverABI,
+ provider,
+ );
+ } else {
+ this.batchReverseResolverSmartContract = null;
+ }
return this.batchReverseResolverSmartContract;
})();
}
@@ -182,25 +182,31 @@
let smartContract;
if (batchReverseResolverSmartContract) {
smartContract = batchReverseResolverSmartContract;
- } else {
+ } else if (batchReverseResolverSmartContract !== null) {
smartContract = await batchReverseResolverSmartContractPromise;
}
// ReverseRecords smart contract handles checking forward resolution
let ensNames: $ReadOnlyArray<?string>;
- try {
- const raceResult = await Promise.race([
- smartContract['getNames(address[])'](needFetch),
- throwOnTimeout(`names for ${JSON.stringify(needFetch)}`),
- ]);
- invariant(
- Array.isArray(raceResult),
- 'ReverseRecords smart contract should return array',
+ if (smartContract) {
+ try {
+ const raceResult = await Promise.race([
+ smartContract['getNames(address[])'](needFetch),
+ throwOnTimeout(`names for ${JSON.stringify(needFetch)}`),
+ ]);
+ invariant(
+ Array.isArray(raceResult),
+ 'ReverseRecords smart contract should return array',
+ );
+ ensNames = raceResult;
+ } catch (e) {
+ console.log(e);
+ ensNames = new Array<?string>(needFetch.length).fill(null);
+ }
+ } else {
+ ensNames = await Promise.all(
+ needFetch.map(ethAddress => this.getNameForAddress(ethAddress)),
);
- ensNames = raceResult;
- } catch (e) {
- console.log(e);
- ensNames = new Array<?string>(needFetch.length).fill(null);
}
const resultMap = new Map<string, ?string>();
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
@@ -183,7 +183,14 @@
const timesLookupAddressCalledAfter = timesLookupAddressCalled;
const timesLookupAddressCalledDuringTest =
timesLookupAddressCalledAfter - timesLookupAddressCalledBefore;
- expect(timesLookupAddressCalledDuringTest).toBe(0);
+
+ // These tests are run on the Sepolia testnet, where the ReverseRecords
+ // smart contract is not deployed. As a result, we end up needing to call
+ // the lookupAddress method (single lookup) once for each address. On
+ // mainnet (outside of these tests) this is 0, since the ReverseRecords
+ // smart contract lets us batch up our requests, and avoid calling
+ // lookupAddress entirely.
+ expect(timesLookupAddressCalledDuringTest).toBe(3);
expect(ashoatEthResult1).toBe(ashoatDotEth);
expect(commalphaEthResult1).toBe(commalphaDotEth);

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 11:13 PM (19 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2602727
Default Alt Text
D11487.diff (3 KB)

Event Timeline