Skip to content

Commit

Permalink
(fix): e2e tests running on local erigon instances
Browse files Browse the repository at this point in the history
  • Loading branch information
mauromedda committed Mar 19, 2024
1 parent 0bb9269 commit 92e3620
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/useErigonHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 92e3620

Please sign in to comment.