From 92e36203da8c303cadafc58c7452f4f02243f2b6 Mon Sep 17 00:00:00 2001 From: Mauro Medda Date: Tue, 19 Mar 2024 16:08:38 +0100 Subject: [PATCH] (fix): e2e tests running on local erigon instances --- src/useErigonHooks.ts | 47 +++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 50a34983..a1b02cd8 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -699,28 +699,31 @@ export const providerFetcher = return result; }; -export const useHasCode = ( - provider: JsonRpcApiProvider | undefined, - address: ChecksummedAddress | undefined, - blockTag: BlockTag = "latest", -): boolean | undefined => { - const fetcher = providerFetcher(provider); - // @todo Zilliqa 1 ignores the blockTag and so we set it to 0 if it is "latest". - // When ZQ2 comes along, we will need to remember that this is ZQ2. - // This is also rather horrific in that we lie about the contents of a block - // because ZQ1 is not capable of time travel and we need to query eg. - // the state of a contract at the block a txn took place :-( - blockTag = 0; - - const { data, error } = useSWRImmutable( - ["ots_hasCode", address, blockTag], - fetcher, - ); - if (error) { - return undefined; - } - return data as boolean | undefined; -}; + export const useHasCode = ( + provider: JsonRpcApiProvider | undefined, + address: ChecksummedAddress | undefined, + // @todo Zilliqa 1 ignores the blockTag and so we set it to 0 if it is "latest". + // When ZQ2 comes along, we will need to remember that this is ZQ2. + // This is also rather horrific in that we lie about the contents of a block + // because ZQ1 is not capable of time travel and we need to query eg. + // the state of a contract at the block a txn took place :-( + blockTag: BlockTag = "0", + ): boolean | undefined => { + // @todo: this fix the tests. So if the network is the local erigon node + // used for the tests with chainID 1337 we se the blockTag to "latest" + if (provider?._network.chainId === BigInt(1337)) { + blockTag = "latest" + }; + const fetcher = providerFetcher(provider); + const { data, error } = useSWRImmutable( + ["ots_hasCode", address, blockTag], + fetcher, + ); + if (error) { + return undefined; + } + return data as boolean | undefined; + }; export const useGetRawReceipt = ( provider: JsonRpcApiProvider | undefined,