I have an orchestrated contract with a function that can only be called by another contract.

While struggling to find an elegant solution for writing a unit test, I realised that I could circumvent the issue by directly modifying the storage of one of my contracts.

I saw that Hardhat Network has a getStorageAt JSON-RPC method, which accepts a contract address and a position as arguments. But I found no equivalent setStorageAt method.

Is there one in Hardhat, Ganache, or any other test RPC network?


Even if it might sound like a good idea at first, it really isn't as it would tie this part of your testing suite to that specific software.

Which in turn can lead to discrepancies and issues that your tests might not detect unless you run them on an actual testnet node.

Since you're doing a UNIT test on a method, inheriting the base contract and adding an update method for your variable should be enough to validate your test case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.