TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

types are not re-generated when "hardhat test" is executed

Open drortirosh opened this issue 3 years ago • 5 comments

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..

drortirosh avatar Apr 23 '22 10:04 drortirosh

This is to do with hardhat, not typechain. Other workarounds include:

  • creating an alias for hardhat compile && hardhat test in os
  • creating a npm / yarn script that named test and then call it using npm run test

NikolaiSch avatar May 01 '22 20:05 NikolaiSch

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

drortirosh avatar May 02 '22 10:05 drortirosh

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?

zemse avatar May 02 '22 10:05 zemse

@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

krzkaczor avatar May 15 '22 13:05 krzkaczor

I'm having this same problem:

  1. Make a change to a solidity file that fixes a bug, save.
  2. Run hardhat test - test fails
  3. Run hardhat test again, 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.

startswithaj avatar Jun 03 '23 10:06 startswithaj