-
Notifications
You must be signed in to change notification settings - Fork 2k
forge: Deploying and testing contracts compiled by older Solidity versions #326
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
Comments
I don't think this is possible in general? You should not be able to import & use a file that is |
this leaves two possible solutions:
There is an unrecommended third possible workaround: |
Yep, matches my understanding above. Closing then as it's not a Foundry issue and isn't something support-able in any framework afaict. |
This is doable in Hardhat, although with a hack. I think it's also possible to deploy binary code compiled by older Solidity compiler as a contract using inline assembly or some other magic. Probably this can be implemented as another cheat code (the VM contract). This feature can be needed when testint a contract that interacts with third-party contracts deployed on mainnet. For example, a contract that uses flash loans of Uniswap. Upgrading outdated contracts can cause bugs or result in different behavior. Also, since Forge dependencies are git submodule, one would have to fork original repo and add it as a dependency instead of the original one, to be able to save changes. Mocking is a solution but mocking is generally considered a bad practice because mocks are not exact copies and can differ in behavior. For simple cases like flash loans mocks are ok, but for more complex cases they can be problematic: imagine you used a slightly incorrect mock and then deployed to mainnet where the contract you depend on works differently. At this point though mocks seems like the simplest solution. |
What is the way it's doable in hardhat? Maybe we can streamline that hack? |
First step is to compile a dependency contract separately from other contracts. In Hardhat, I use an empty contract like: pragma solidity =0.5.16;
import "@uniswap/v2-core/contracts/UniswapV2Factory.sol";
contract DependencyUniswapV2 {} Then, in tests, it can be easily used via: const Factory = await ethers.getContractFactory("UniswapV2Factory");
|
Honestly that's not a bad workaround, maybe something we should add on the stdlib? 2 qs:
|
This is in a monorepo, so it's making sure the other pkg has been compiled first (does something like
Just defining a new interface for it maker-style in this case
Yea! Guess it depends if there are any gotchas with appending calldata to bin bytecodes compiled with different versions? I don't know of anything like that, but I would defer to others who are more familiar |
I've ended up using the same solution. Learned about it from this blog post: |
May i suggest to reduce external dependencies like |
Supportive @brockelmore |
If nobody else has, I'd like to give this one a shot. I've been wanting this feature for a while now in dapptools/foundry. |
Is this solved by #440? |
@onbjerg Yes! Thanks. |
When compiling a test contract that imports a contract that uses an older Solidity version, it fails with:
Steps to reproduce:
mkdir foundrysolversions && cd $_
forge init
forge install Uniswap/v2-core
src/test/Contract.t.sol
and addimport "v2-core/UniswapV2Pair.sol";
forge test
Is there a workaround? Is it possible to compile contracts with different compilers and then reuse binary code?
The text was updated successfully, but these errors were encountered: