-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add getVariable function #134
feat: add getVariable function #134
Conversation
This commit introduces a new function for mock contracts. With `getVariable` you can view an internal variable's value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yo @tonykogias, i'm very pleased to be reading this PR 😍
although the very precise commenting, got quite lost on the deep TS/EVM logic, but the tests seem to be working fine, so congrats for that gud ser 👏
made a few comments, will probably give a further review w/ @0xGorilla before approving 🚀
looks like it was way harder than it initially appeared, but you definitely have found the spot
oh this fell, i guess it's yours, KING
{\__/}
( • . •)
/ > 👑
.. code-block:: typescript | ||
|
||
const myMappingValue = await myMock.getVariable('myMappingVariableName', [mappingKeyA, mappingKeyB]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's please add a warning, mentioning the things that don't work. Will links to PRs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely 🔥, well done
This is great and in regular contract deployment it works, however if I try to use it with an OZ UUPS proxy I get:
The contract must be deployed using the const ProxyMock = await smock.mock("MyContract");
const proxyMock = await upgrades.deployProxy(ProxyMock as MockContractFactory<MyContract__factory> & MyContract__factory, [...]) as MyContract & MockContract<MyContract>; However that does not seem to help. What did I miss? Is there any possibility to pass a contract instance or a contract factory instead a Currently I need to use a preprocessor to conditionally add a bunch of accessors to the contract just to handle the private variables for unit testing. The Is there any work around I could try? Thanks |
Description
This commit introduces a new function for mock contracts. With
getVariable
you can view an internal variable's value.Approach
A rough idea of how I approached this problem is:
getVariableStorageSlots
that represent the position of the variable's value.vmManager.getContractStorage
function and providing the contract address and the appropriate slot key.decodeVariable
function and providing all the values from the above step which results in the variable's valueMetadata