Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForkBlockhain.getLogs always sets logIndex to null #1048

Closed
chatch opened this issue Nov 25, 2020 · 1 comment · Fixed by #1080
Closed

ForkBlockhain.getLogs always sets logIndex to null #1048

chatch opened this issue Nov 25, 2020 · 1 comment · Fixed by #1080
Labels
type:bug Something isn't working

Comments

@chatch
Copy link

chatch commented Nov 25, 2020

Summary

hardhat: 2.0.3

ForkBlockchain.getLogs calls toRpcLogOutput with result logs here

index is always undefined and so logIndex is always set to null here

The problem I face with this is that ethers.provider.getLogs will throw when formatting the logs response (see Ethers error below).

I wonder could output.ts simply do something like numberToRpcQuantity(log.indexOf) instead of using the index argument...

Reproduce

Start hardhat node in mainnet forking mode.

Run the following script with hardhat run:

const hre = require("hardhat");

async function main() {
  const events = await hre.ethers.provider.getLogs({
    address: "0x2A07fBCD64BE0e2329890C21c6F34e81889a5912",
    topics: [
      "0x8f7de836135871245dd9c04f295aef602311da1591d262ecb4d2f45c7a88003d",
    ],
    fromBlock: 10721019,
    toBlock: 10721019,
  });
  console.log(JSON.stringify(events, null, 2));
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

Ethers Error

{ Error: invalid BigNumber value (argument="value", value=null, code=INVALID_ARGUMENT, version=bignumber/5.0.8)
at Logger.makeError (/home/hatch/projects/sb/startrail/app/node_modules/@ethersproject/logger/src.ts/index.ts:205:28)
at Logger.throwError (/home/hatch/projects/sb/startrail/app/node_modules/@ethersproject/logger/src.ts/index.ts:217:20)
at Logger.throwArgumentError (/home/hatch/projects/sb/startrail/app/node_modules/@ethersproject/logger/src.ts/index.ts:221:21)
at Function.BigNumber.from (/home/hatch/projects/sb/startrail/app/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:268:23)
at Formatter.number (/home/hatch/projects/sb/startrail/app/node_modules/ethers/node_modules/@ethersproject/providers/src.ts/formatter.ts:168:26)
at Function.Formatter.check (/home/hatch/projects/sb/startrail/app/node_modules/ethers/node_modules/@ethersproject/providers/src.ts/formatter.ts:416:42)
at Formatter.filterLog (/home/hatch/projects/sb/startrail/app/node_modules/ethers/node_modules/@ethersproject/providers/src.ts/formatter.ts:409:26)
at /home/hatch/projects/sb/startrail/app/node_modules/ethers/node_modules/@ethersproject/providers/src.ts/formatter.ts:451:29
at Array.forEach ()
at /home/hatch/projects/sb/startrail/app/node_modules/ethers/node_modules/@ethersproject/providers/src.ts/formatter.ts:450:19
reason: 'invalid BigNumber value',
code: 'INVALID_ARGUMENT',
argument: 'value',
value: null,
checkKey: 'logIndex',
checkValue: null }

@fvictorio fvictorio added the type:bug Something isn't working label Nov 25, 2020
@fvictorio
Copy link
Member

Thanks for reporting @chatch, definitely a bug on our side.


Notes for whoever tackles this: the problem comes from this line

https://github.com/nomiclabs/hardhat/blob/cadbb43800059f4d9058f3f3f3dd0a0591c3aa52/packages/hardhat-core/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts#L186

that calls toRpcLogOutput without an index, and therefore returns a null logIndex for the remote logs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants