-
Notifications
You must be signed in to change notification settings - Fork 264
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
Coverage overwrites provider logic in extendEnvironment hook #819
Comments
Here is a reproductible example that does not require any artefact: const { ethers } = require('hardhat');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
async function fixture() {
const [owner, other] = await ethers.getSigners();
return { owner, other };
}
describe('Ownable', function () {
beforeEach(async function () {
Object.assign(this, await loadFixture(fixture));
console.log("beforeEach:", await ethers.provider.getBlockNumber())
});
afterEach(async function () {
console.log("afterEach:", await ethers.provider.getBlockNumber())
});
it('run #1', async function () {
await this.owner.sendTransaction({ to: this.other });
});
it('run #2', async function () {
await this.owner.sendTransaction({ to: this.other });
});
}); it shows that when running the second |
@Amxx Thanks for these reproductions. Will take a look. |
Tried to reproduce the I think the problem in the Ownable PR you're working on is caused by redefining The execution stack at HH looks like:
One solution could be to move your signers logic to a mocha root hook where it would run as part of the test task after solidity-coverage has done its own provider stuff. Was able to get the Ownable tests working in a fork of your PR here: https://github.com/cgewecke/openzeppelin-contracts/actions/runs/6518313002/job/17703604132 A couple commits were necessary, including commenting out the coverage specific blockLimit in |
Closing because Zeppelin 4657 merged. Lmk if you think something else needs to be addressed. |
We found a dirty work around because we needed to move on, but its not a fix. We had to disable some of our env test from running when coverage is enabled ... and we know that traditional tests are no running in the same environment as coverage tests (this part if probably not affecting the security to much, but its not nice) |
And the issue can be summarized as:
I understand that its not as bad as |
Is it not possible to move the hardhat signers override to a mocha root hook(as suggested above)? Unfortunately the coverage task has to recreate the provider and afaik there's no way to re-trigger the extendEnvironment hooks from within a hardhat task. Fwiw this problem has not arisen very frequently - it sometimes happens with other plugins but I suspect it's relatively uncommon for people to try to cache provider values the way you have. (Am going to retitle the issue so it's more easily discoverable) |
Re-opening because it may be possible to fix this by moving the plugin's provider recreation logic to a hardhat |
Another update: in v0.8.12, the plugin defaults to using hardhat's
This prevents the provider from being overwritten in the task & preserves existing user modifications. Unfortunately there's no other way to tell the plugin it's being invoked early in the command launch sequence and the changes solidity-coverage makes to the provider should only happen when it's being called. (Have documented this in the README trouble-shooting section) (Leaving issue open until there's some structural change at HH that removes this requirement) |
Here is a minimum reproductible example, based on OpenZeppelin's Ownable:
What it does:
owner
When running this test "normally", everything is fine !
When running this test in "coverage" mode, the second run fails with error
It looks like the snapshot is not restored properly.
The text was updated successfully, but these errors were encountered: