From 8708597b7eaf552465947807d5542ae418598e70 Mon Sep 17 00:00:00 2001 From: John Feras Date: Mon, 24 Jun 2024 16:15:52 -0400 Subject: [PATCH] Fix to return proper error string when public address not found in subgraph --- umbra-js/src/utils/utils.ts | 26 +++++++++++++++----------- umbra-js/test/utils.test.ts | 1 + 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/umbra-js/src/utils/utils.ts b/umbra-js/src/utils/utils.ts index d5aaa188..8ccbd26a 100644 --- a/umbra-js/src/utils/utils.ts +++ b/umbra-js/src/utils/utils.ts @@ -329,19 +329,23 @@ export async function getMostRecentSubgraphStealthKeyChangedEventFromAddress( chainConfig ); let theEvent: SubgraphStealthKeyChangedEvent | undefined; - for await (const event of stealthKeyChangedEvents) { - for (let i = 0; i < event.length; i++) { - if (theEvent) { - console.log( - `We found a previous StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}` - ); - } else { - theEvent = event[i]; - console.log( - `We found a StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}` - ); + try { + for await (const event of stealthKeyChangedEvents) { + for (let i = 0; i < event.length; i++) { + if (theEvent) { + console.log( + `We found a previous StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}` + ); + } else { + theEvent = event[i]; + console.log( + `We found a StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}` + ); + } } } + } catch (error) { + throw new Error(`Address ${address} has not registered stealth keys. Please ask them to setup their Umbra account`); // prettier-ignore } if (!theEvent) { diff --git a/umbra-js/test/utils.test.ts b/umbra-js/test/utils.test.ts index 37ae2afa..9374c0c5 100644 --- a/umbra-js/test/utils.test.ts +++ b/umbra-js/test/utils.test.ts @@ -242,6 +242,7 @@ describe('Utilities', () => { ); }); + // prove test failure is related to the ordering of RPC query vs subgraph query, and subgraph URL is not setup it('throws when looking up an address that has not sent a transaction', async () => { const address = '0x0000000000000000000000000000000000000002'; const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL); // otherwise throws with unsupported network since we're on localhost