-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(forge): inspect storage slot value #2494
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
Conversation
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.
this is a good idea,
but I think this should be opt in
also I'd appreciate a simple forgetest! integration test for this, lmk if you need some pointers, have a look at the existing ones,
probably needs some setup up via
forgetest_async!(
test_inspect,
|prj: TestProject, cmd: TestCommand| async move {
// this will launch anvil
let (api, handle) = spawn(NodeConfig::test()).await;
// deploy
// inspect
}
cli/src/cmd/forge/inspect.rs
Outdated
| ]; | ||
| if let Some(ref provider) = provider { | ||
| let location = TxHash::from_low_u64_be(slot.slot.parse::<u64>()?); | ||
| let value = | ||
| provider.get_storage_at(contract_addr, location, None).await?; | ||
| row.push(format!("{:?}", value)); | ||
| } | ||
| table.add_row(row); |
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.
great!
|
Imo this should be in Cast where we also already have |
It makes sense, maybe we need to expose more forge-related contract interfaces to cast, so that cast can expand more transaction-related details from a contract perspective. |
|
I agree this is useful, but big +1 that this should not be part of forge. Right now
Note this PR does not properly handle dynamic types. It will print the length of an array for array types, and zero for mappings because it doesn't know the keys. I think that's ok for the first version, but I'd love for the next iteration to figure out array lengths and all mapping keys to print the all storage. @banteg has a POC for doing this here: https://github.com/banteg/storage-layout |
|
Definitely +1 for @mds1 |
|
Agreed, |
|
hey @b1u3h4t what are the best next steps here? (we at a minimum want a unit test here) |
|
Ping @b1u3h4t |
|
On further thought I think we should go wiht @mds1 suggestion. Closing given stale, and we can revisit! Thanks! |
Motivation
After deploying the contract, it is often necessary to check whether the parameters are set successfully, so here is a simple method to query the value of the slot corresponding to the contract variable.
Solution
Obtain the value of the specified slot in the contract through getStorageAt, and then print it in a developer-friendly way to facilitate the review of related variables.
TODO