types are not re-generated when "hardhat test" is executed
hardhat compile automatically does generate types on every change,
but hardhat test doesn't.
There is a workaround (always run hardhat compile && hardhat test) but its awkward..
This is to do with hardhat, not typechain. Other workarounds include:
- creating an alias for
hardhat compile && hardhat testin os - creating a npm / yarn script that named test and then call it using npm run test
Yes, this is not a problem of typechain per se, but the hardhat-typechain plugin.
The plugin automatically generates types on hardhat compile task, but doesn't automatically generate types on hardhat test
Regenerating types make sense when the artifacts change and they do when you run compile script (which change artifacts only if you change solidity files).
The test script also runs compile script if you changed solidity files else it does not. Are you saying this doesn't happen for you?
@drortirosh @NikolaiSch can you guys prepare an example repo where this happens? This must be a regression because it works. We even have tests for that: https://github.com/dethcrypto/TypeChain/blob/master/packages/hardhat/test/project.test.ts#L77
I'm having this same problem:
- Make a change to a solidity file that fixes a bug, save.
- Run
hardhat test- test fails - Run
hardhat testagain, test passes.
I heavily use the TypeChain factories in my tests, it seems the old types/artifacts are already loaded into memory - the factories include the bytecode from the previous compile, they don't use the bytecode from the artifacts from the compile that executes during hardhat test.