From 5dd9ccc6090e120fa307886e01d452d0741eb94a 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 d5aaa1880..8ccbd26ab 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 86c42b244..35936a147 100644 --- a/umbra-js/test/utils.test.ts +++ b/umbra-js/test/utils.test.ts @@ -236,6 +236,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(`https://sepolia.infura.io/v3/${INFURA_ID}`); // otherwise throws with unsupported network since we're on localhost