foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Cheatcode for cloning account to a specific address

Open shouc opened this issue 2 years ago • 3 comments

Component

Forge

Describe the feature you would like

We are interested in a new cheatcode op: vm.cloneAccount, which clones (code, state, balance, nonce) from one account to another account. This would be useful when we need to deploy code with a complex constructor to a specific address, let external calls from a contract we cannot control execute different code on different accounts when we fork the chain, etc. These cannot be easily achieved using vm.deal, vm.etch or vm.accesses

This operation is hard to implement in Solidity but easy in revm.

Example:

vm.cloneAccount(0x35c9dfd76bf02107ff4f7128Bd69716612d31dDb, 0xeCf9571038d92097a6C09A8d75713fEE69877211)

which should clone (code, state, balance, nonce) of 0x35c9dfd76bf02107ff4f7128Bd69716612d31dDb to 0xeCf9571038d92097a6C09A8d75713fEE69877211.

Additional context

No response

shouc avatar May 08 '23 01:05 shouc

i can take this up if no objection on getting this into cheatcodes

shouc avatar May 08 '23 03:05 shouc

This seems useful to me, @mattsse any objections here?

mds1 avatar May 08 '23 18:05 mds1

I don't see why not

@shouc if you would still like to implement this, we have improved cheatcodes DX a lot, check out the cheatcodes dev docs

DaniPopes avatar Jun 27 '24 15:06 DaniPopes

@shouc Hi, are you still working on this feature?

Troublor avatar Jul 10 '24 15:07 Troublor