defi-wonderland / smock

The Solidity mocking library
MIT License
319 stars 40 forks source link

Set Variable at specific storage position #89

Open Remscar opened 2 years ago

Remscar commented 2 years ago

Is your feature request related to a problem? Please describe. I want to be able to modify contract storage on a mock at a specific slot.

Describe the solution you'd like .setVariable allows me to change a variable, but in some cases (like when using Ethereum Diamonds) there is not a variable for me to set, but instead a storage slot that I need to set.

Being able to do something like

.setStorageSlot(storageSlotPosition: string, value: any)

where storageSlotPosition would be keccak256("diamond.standard.diamond.storage"); would be super helpful.

Describe alternatives you've considered Forking the repo.

Additional context For example take this library: https://github.com/zer0-os/zDAO/blob/edfb37aec5dc3922a8f64add3560d9ffbd84944c/contracts/zdao/libraries/LibBasicVoting.sol

You'll notice there's a function basicVotingStorage() which returns a BasicVotingStorage struct which is located at the storage slot position defined by bytes32 constant BASIC_VOTING_STORAGE_POSITION = keccak256("zer0.zdao.basicvoting.storage.v0");

I want to be able to modify that struct.

smartcontracts commented 2 years ago

Great idea! And very straightforward. I'll get a PR out for this over the weekend.

Remscar commented 2 years ago

Great idea! And very straightforward. I'll get a PR out for this over the weekend. @smartcontracts Thank you! Do you have an update on when this might get released?