Open hickscorp opened 2 years ago
Another problem, related to the same thing - if I use fixtures in different test files, but they all call deployments.diamond.deploy('Fast', ...)
, the error above is thrown.
If I use a unique name per test file for the diamond, it works...
hmm, deployments/hardhat should never exit. can you share your config ?
@wighawag Here goes:
From what you said, I should remove this part, right?
hardhat: {
live: false,
saveDeployments: true,
tags: ['test', 'local']
},
If I remove this from my config, the tests fail, but I have no way to make them pass by deleting deployments/hardhat
.
import 'dotenv/config';
import * as dotenv from 'dotenv';
import { HardhatUserConfig } from 'hardhat/config';
import '@typechain/hardhat';
import 'hardhat-deploy';
import 'hardhat-deploy-ethers';
import 'hardhat-diamond-abi';
import 'solidity-coverage';
import 'hardhat-gas-reporter';
// Loads `.env` file into `process.env`.
dotenv.config();
// Import all of our tasks here!
import './tasks/accounts';
...
const config: HardhatUserConfig = {
solidity: {
version: '0.8.4',
settings: {
outputSelection: {
'*': {
'*': ['storageLayout']
}
}
}
},
diamondAbi: {
name: 'Fast',
include: [
'IERC173',
'IERC165',
'IDiamondCut',
'IDiamondLoupe',
...
]
},
networks: {
hardhat: {
live: false,
saveDeployments: true,
tags: ['test', 'local']
},
localhost: {
live: false,
saveDeployments: true,
tags: ['local'],
}
},
namedAccounts: {
deployer: {
hardhat: 0,
localhost: 0
},
spcMember: {
hardhat: 1,
localhost: 1
},
fastGovernor: {
hardhat: 2,
localhost: 2
}
},
typechain: {
outDir: 'typechain',
target: 'ethers-v5',
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
gasPrice: 21
}
};
export default config;
Ok, the issue arise because you save the deployment via saveDeployments: true,
It should never be needed for hardhat as it is an in memory network
No, if I remove the hardhat
network, then only the first test file to run works. All the others fail.
The only way I found to have all test files to pass is to have:
hardhat
network defined, saving deploys on disk.diamond.deploy(NAME)
in every test file, so they don't collide.EDIT: Scratch that, none of these solution work.
@wighawag if you want to reproduce:
Try running yarn hardhat test
- the first test file will pass, the second will fail.
But if you run yarn hardhat test file1.test.ts && yarn hardhat test file2.test.ts
, both will pass.
For us it's a problem, because running test files one by one doesn't allow us to get overall coverage.
If you can create such repo, it would be helpful
But yes remove saveDeployments: true,
@wighawag I can't create a repo now - I might be able to opensource our repository - would that work?
I removed saveDeployments: true
- in fact I removed the whole hardhat
network configuration.
No luck so far.
@wighawag You can try https://github.com/tableturn/tt-white-contracts/commit/0364008a7e40c77db426f0c86ebcec0609d9c447
EDIT: Sorry - this is the commit that shows the bug: https://github.com/tableturn/tt-white-contracts/commit/30d7cd6de066aa0b2b8ac03686f097ec2dd4cab9
@wighawag any idea?
Did not have time yet to look at that, what are the step to reproduce ?
Simply run the test suite. If you run yarn test
, the first test using the Fast
diamond will succeed. Any subsequent test file using the Fast
diamond will fail.
However, running test files individually works - eg yarn test filename.test.ts
.
@wighawag Any chance that we could have a look at this?
Hi @hickscorp I reproduced your issue locally today but did not have time to see what is causing this issue yet.
Might be worth debugging to see what is happening. hardhat-deploy fixture reset the blockchain state, but maybe some js variable are kept in memory and so the values changes when you execute one file test versus many.
We are migrating a hardhat project to use
hardhat-deploy
, as we wanted to also leverage theDiamond
pattern baked intohardhat-deploy
.Consider the following test code:
This code behaves differently whether we clean the
deployments/hardhat
folder before running it. The first time, it runs (as long asdeployments/hardhat/
is empty). But for subsequent runs we get: