Open joaquinlpereyra opened 1 year ago
I have edited for clarity, as constructors()
are annoying in this case. The idea would be to be able to set an already-existing address to an arbitrary new account.
@joaquinlpereyra we have now vm.cloneAccount
cheatcode which seems to be what you're looking for (clones everything form source, including storage, balance, code) (https://github.com/foundry-rs/foundry/issues/4893) see a test here https://github.com/foundry-rs/foundry/blob/15fdb2a19ee2a038f7e72523c6a0b0c3cdc6c3e4/testdata/default/cheats/CloneAccount.t.sol#L23-L45
please check if that works for your case too. thank you!
Component
Forge
Describe the feature you would like
As an auditor, the contract-under-test deployment is not under my control. Nor are all of the contracts-that-interact with my contract-under-test. I do have access to their source code.
One common idea when testing is to try to test different configurations which are set on contract initialization. One of the simplest way I can think to simplify these tests is to create a new instance of the contract-under-test (either via
new()
or using minimal proxies depending on the context) and then perform my tests.The problem is that when you create a new instance of the contract, you of course get a new address. This makes all contracts that interact with your contract-under-test interact with the old instance of the test, which is not desired.
As such, I would like to have the possibility to
fork
to a new state where theAccountInfo
of theaddress originalAddr
is replaced by theAccountInfo
of theaddress newAddr
. In this way, all contracts that point tooriginalAddr
would still work and I would be able to programatically test different configurations of the contracts under test.This cannot be done by forking from an state where the contract does not exist, as it is possible that contracts that interact with my contract under test do not exist at that point either.
This can also not be done by
etch
, asetch
only modifies thecode
and not the storage.This can not be done by
StdStorage
, as it requires specific keys. I want to wipe all of the storage.One of the most radical workarounds I thought of was using
etch
to replace the contract code with a singleselfdestruct()
call; but this does not work as the actual deletion is reserved for the end of the transaction... and when testing we are always inside the same transaction; so this does not work either.Additional context
No response