-
Notifications
You must be signed in to change notification settings - Fork 163
feat: implement console commands for accessing contract state data #2042
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
base: main
Are you sure you want to change the base?
Conversation
|
@hugoclrd please check, it's ready for review. |
hugo-stacks
left a comment
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.
Hey @grandima
Thanks for this contribution.
Could you add a screenshot of the output to the PR description please?
| let default_deployer = self.settings.initial_deployer.as_ref() | ||
| .map(|account| account.address.clone()) | ||
| .unwrap_or_else(|| "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM".to_string()); |
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.
The default address principal should be self.get_tx_sender()
| Err(e) => return format!("{} {}", "Invalid contract identifier:".red(), e), | ||
| }; | ||
|
|
||
| let call_expr = format!("(contract-call? '{}.{} var-get {})", |
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.
that isn't a valid contract-call 🤔
Have you tested it?
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.
You may want to use session.interpreter.get_data_var()
| assert!(!output.is_empty()); | ||
|
|
||
| let first_line = &output[0]; | ||
| assert!(!first_line.is_empty()); |
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.
Should check actual output
|
|
||
| assert!(!output.is_empty()); | ||
| let first_line = &output[0]; | ||
| assert!(!first_line.is_empty()); |
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.
Should check actual output
| Err(e) => return format!("{} {}", "Invalid contract identifier:".red(), e), | ||
| }; | ||
|
|
||
| let call_expr = format!("(contract-call? '{}.{} map-get {} {})", |
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.
Same as above. This isn't a valid contract-call
You may want to use session.interpreter.get_map_entry()
|
Hello @grandima Thank you |
|
@hugo-stacks thanks for such a quick and comprehensive review! I'm working on fixes. Meanwhile, I'll convert to draft and tag you when ready. |
Add three new REPL commands to inspect contract data during development:
- ::get_constant <contract> <constant> - Get constant value from a contract
- ::get_data_var <contract> <var> - Get data variable value from a contract
- ::get_map_val <contract> <map> <key> - Get map value from a contract
|
@hugo-stacks please check again as I applied the suggested changes and attached screenshots. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Resolves #1722
Summary
Implements three new REPL commands for inspecting contract data during development:
::get_constant <contract> <constant>- Get constant value from a contract::get_data_var <contract> <var>- Get data variable value from a contract::get_map_val <contract> <map> <key>- Get map value from a contractImplementation Details
components/clarity-repl/src/repl/session.rscomponents/clarinet-cli/tests/console.rsTest Plan
REPL demo of interaction with
fixtures/mxs/counter.clarcontract: