-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(cheatcodes): add vm.getStateDiff
to get state diffs as string
#9435
Conversation
dc4f42f
to
5add458
Compare
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.
lgtm
I'm honestly a bit conflicted with this api / feature. With primitive type storage in incremental slots what is proposed here is definitely useful, although I think for us would be more useful in an easier-to-consume & post-process format (e.g. json). Currently I lack the imagination though to see how i could understand that a change in slot |
can add a flag to cheatcode to return plain text or json formatted
I think this would imply leveraging of storage layout but probably more complex, will have a look at but most probably feasible to add post v1. |
vm.getStateDiff(isJson)
to get state diffs as string
@grandizzy just had another look at the structure & was wondering it could make sense to change it so sth like: My thinking is that it's a bit weird that if a label is supplied, the address is lost on the diff. |
thank you, makes sense, will structure the output this way |
@sakulstra I formatted it as below in d46080c {
"0x2e234dae75c793f67a35089c9d99245e1c58470b":{
"label":"NestedStorer",
"changes":{
"31391530734884398925509096751136955997235046655136458338700630915422204365175":{
"original":"0x0000000000000000000000000000000000000000000000000000000000000000",
"dirty":"0x0000000000000000000000000000000000000000000000000000000000000001"
},
"86546418208203448386783321347074308435724792809315873744194221534962779865098":{
"original":"0x0000000000000000000000000000000000000000000000000000000000000000",
"dirty":"0x0000000000000000000000000000000000000000000000000000000000000001"
},
"89735575844917174604881245405098157398514761457822262993733937076486162048205":{
"original":"0x0000000000000000000000000000000000000000000000000000000000000000",
"dirty":"0x0000000000000000000000000000000000000000000000000000000000000001"
},
"99655811014363889343382125167956395016210879868288374279890486979400290732814":{
"original":"0x0000000000000000000000000000000000000000000000000000000000000000",
"dirty":"0x0000000000000000000000000000000000000000000000000000000000000001"
}
}
}
} |
@grandizzy looks good to me. I personally find the new naming not so optimal, but i think is just taste. |
changed in 1536119 and updated comment above |
rerequesting review as there were several changes (json output)
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.
Nice! Lgtm
Agreed with all the feedback from @sakulstra, thanks @grandizzy for implementing that! Some other comments:
|
Thanks for feedback!
This would require matching local artifact / contract by address in cheatcodes, I propose to address in a follow up (post 1.0) PR since it imply some more code changes.
Yep, changed, see format below
I included balance diff as well, rn there's no simple way to include nonce diffs so added only a placeholder -will check it in a (post v1.0) follow up PR {
"0x2e234dae75c793f67a35089c9d99245e1c58470b":{
"label":"NestedStorer",
"balanceDiff":{
"previousValue":"0x0",
"newValue":"0xde0b6b3a7640000"
},
"stateDiff":{
"0x4566fa0cd03218c55bba914d793f5e6b9113172c1f684bb5f464c08c867e8977":{
"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000",
"newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"
},
"0xbf57896b60daefa2c41de2feffecfc11debd98ea8c913a5170f60e53959ac00a":{
"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000",
"newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"
},
"0xc664893a982d78bbeab379feef216ff517b7ea73626b280723be1ace370364cd":{
"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000",
"newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"
},
"0xdc5330afa9872081253545dca3f448752688ff1b098b38c1abe4c4cdff4b0b0e":{
"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000",
"newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"
}
}
}
}
Same, I propose to do add this one in post v1.0 a follow up PR |
please rereview considering changes in #9435 (comment)
Overall LGTM, minor note in regards to placeholder |
@mds1 would #9435 (comment) be OK to give it a go in this stage? thanks! |
Thanks for the answers @grandizzy, doing the rest in a follow up works for me! Can we just make sure to track all those remaining items somewhere? They would definitely be super helpful so just want to make sure we don't lose them One thing I am still unsure of is the |
👍 I am going to update the issue with remaining things to implement.
Yeah, is |
|
Follow up #9504 |
Motivation
Closes #2846 by adding
startStateDiffRecording()
cheatcode as string (can be printed with console.log or written in file), at the moment of cheatcode call (can be called multiple times between start / stop state diff)E.g.
Json format
vm.getStateDiffJson()
Solution