-
Notifications
You must be signed in to change notification settings - Fork 138
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(era-cheatcodes): expectRevert
cheatcode
#200
Conversation
d93045e
to
2ff4e5a
Compare
Co-authored-by: Nisheeth Barthwal <[email protected]>
fix(era:cc:expectRevert): offset expected depth fix(era:cc:expectRevert): check only shallower than expected
feat(era:cheatcodes): delay action by n statements refactor(era:cc): recurring actions
2a2b999
to
3af1a58
Compare
6c54bb5
to
5606e38
Compare
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
9323302
to
c6da906
Compare
expectRevert
cheatcodeexpectRevert
cheatcode
Signed-off-by: Danil <[email protected]>
expectRevert
cheatcodeexpectRevert
cheatcode
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
05ed383
to
39b750a
Compare
Signed-off-by: Danil <[email protected]>
39b750a
to
7a282c1
Compare
Signed-off-by: Danil <[email protected]>
0449a36
to
243d072
Compare
// function testExpectRevertCallsThenReverts() public { | ||
// Reverter reverter = new Reverter(); | ||
// Dummy dummy = new Dummy(); | ||
// cheatcodes.expectRevert("called a function and then reverted"); | ||
// reverter.callThenRevert(dummy, "called a function and then reverted"); | ||
// } |
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.
Are these cases not yet supported?
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.
I assume @Karrq copypasted them from the cheatcodes and we will activate it, once we are supporting cheat codes calls directly
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.
@Karrq Can these be enabled (using the the long form call syntax)?
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.
Yes I did copy paste, and I simply had these removed for now not for the direct calls but to simplify a bit the tests honestly. These should be enabled (and fixed)
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.
Some minor comments, and in general it makes sense to add documentation to most items in the PR, given its complex nature
Signed-off-by: Danil <[email protected]>
What 💻
expectRevert
implementations and testexpectRevert
works with general messagesexpectRevert
works with CustomErrorsexpectRevert
works with low level callsHow
Once the cheatcode expectRevert set, we have to check the next call, is it success or revert.
To do it, after cheatcode installation, we check returns on a certain depth for reverting or correct execution. Unfortunately, after setting this cheatcode we have at least one return on this depth, it's a return from cheatcode contract, and after we probably have one another return 0x..8002 address (ACCOUNT_CODE_STORAGE_ADDRESS), it's a system contract, that returns correct bytecode, based on address. So we have to skip either 1 or 2 returns before the necessary return.
Once we found the necessary return, we have to check it and probably change the execution path. E.g. convert revert to ok.
And it's the place where magic starts. We have
pc
and it represents the next command to execute.So, we have 2 possible paths:
The exception handler is placed in the
current
depth of the callstack, because it's a property of return, but the continue pc is placed in the desired depth, depth - 1.So for proper jump to the necessary path we have to grab two pc. and later on jump to one of them.
Evidence 📷