foundry
foundry copied to clipboard
Allow replacing `constant` or `immutable` in Foundry, or allow `mockCall` to replace constructor
Component
Forge
Describe the feature you would like
is there a way to replace a constant or immutable variable? vm.store doesn't work as they are not in storage slot. Or is there a way to mockCall to override the constructor?
My use case is that I deploy a new contract in the constructor and save the contract address as immutable variable. While in my unit test, I want to override the implementation of that contract
pragma solidity ^0.8.0;
contract DataExtractor {
function extractData(bytes32 dataId) public pure returns (uint256) {
return uint256(dataId);
}
}
contract DataFetcher {
address public immutable dataExtractor;
constructor() {
dataExtractor = address(new DataExtractor());
}
// other functions that use dataExtractor
}
Additional context
No response
how would you implement this? constants/immutables are replaced in the bytecode itself before deployment
Related to https://github.com/foundry-rs/foundry/pull/5718
Maybe use a proxy contract for testing? Then you can modify the immutables in the implementation contract