Skip to content
New issue

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

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

Already on GitHub? # to your account

Coverage: Contract size too large error thrown ONLY when running with parallel: true #4310

Closed
0xdavinchee opened this issue Aug 17, 2023 · 3 comments
Assignees

Comments

@0xdavinchee
Copy link

Version of Hardhat

2.17.1

What happened?

What happened: when I run my coverage tests using npx hardhat coverage with { mocha: { parallel: true } } in hardhat.config.ts, it throws an error:

Enable the 'allowUnlimitedContractSize' option to allow init codes of any length.
  Error: Returned error: Trying to send a deployment transaction whose init code length is 57472. The max length allowed by EIP-3860 is 49152.

What is expected: coverage runs despite this issue.

Minimal reproduction steps

# Clone the superfluid-finance repo
git clone git@github.com:superfluid-finance/protocol-monorepo.git

# cd into dir, install dependencies, and build
cd protocol-monorepo && yarn install && yarn build

# go into ethereum-contracts folder
cd packages/ethereum-contracts

# create a .env and put the necessary vars in there
echo "HARDHAT_TEST_JOBS=4" > .env && echo "HARDHAT_RUN_PARALLEL=true" >> .env

# run the coverage tests
yarn test-coverage:hardhat

# it should break, now remove the vars from .env and if you rerun it, it will work

This can be fixed by adhering to the error message, but we would rather not do that if possible.

Search terms

No response

@fvictorio
Copy link
Member

Hey @0xdavinchee, sorry for not responding before. I think I know what's going on here, I'll try to explain it.

solidity-coverage does automatically enable the allowUnlimitedContractSize flag. The reason it does it is that, before running the tests, the code is instrumented with coverage-measuring code. This increases the size of the bytecode, so it's really common for contracts to go over the limit when measuring test coverage.

Now the thing is that, when you run tests in parallel and measure coverage, that flag is not being correctly set, and you get that warning. I think the reason why it's not being correctly set is that mocha, in parallel mode, runs each test file in a separate worker process, but solidity-coverage only enables the flag in the "parent" process, which has no effect.

From what I saw in solidity-coverage's code, I don't think this is the only thing that won't work correctly with the plugin. Sadly I think the best you can do is use serial mode when running coverage, at least until solidity-coverage is adapted to work correctly in parallel mode (see sc-forks/solidity-coverage#691).

Alternatively, you can enable the allowUnlimitedContractSize flag in your config when running coverage, but there isn't a good way to do that (you can't see the task that is being run from the config).

@0xdavinchee
Copy link
Author

hey @fvictorio no worries at all for not responding before, thank you for responding and explaining what the issue is here.

good to know what the underlying issue is!

@fvictorio
Copy link
Member

I'm closing this in favor of #4492

For anyone landing here: there isn't a lot we can do right now on our side. The workaround for now is to disable parallel mode when the coverage task is used.

@fvictorio fvictorio closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Oct 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
Archived in project
Development

No branches or pull requests

2 participants