ganache icon indicating copy to clipboard operation
ganache copied to clipboard

`eth_getTransactionByBlockNumberAndIndex` and `eth_getTransactionByBlockHashAndIndex` behave inconsistently

Open SamWilsn opened this issue 2 years ago • 0 comments

Calling either eth_getTransactionByBlockNumberAndIndex or eth_getTransactionByBlockHashAndIndex through request has different behaviour when the block doesn't exist vs. the transaction is out of bounds.

For example:

const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, to, gas: "0x5b8d80" }] });
const { blockHash, transactionIndex } = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });

// Returns null:
const fakeHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
await provider.request({ method: "eth_getTransactionByBlockHashAndIndex", params: [ fakeHash, transactionIndex] });

// Throws exception:
await provider.request({ method: "eth_getTransactionByBlockHashAndIndex", params: [ blockHash, transactionIndex + 1] });

The specific message is:

n.getTransactions()[w.Quantity.toNumber(...)] is undefined

Presumably these two error cases should behave similarly: both throw exceptions or both return null.

SamWilsn avatar Jun 07 '23 18:06 SamWilsn