feat: implement console commands for accessing contract state data#2042
feat: implement console commands for accessing contract state data#2042grandima wants to merge 2 commits intostx-labs:mainfrom
Conversation
|
@hugoclrd please check, it's ready for review. |
hugo-stacks
left a comment
There was a problem hiding this comment.
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.
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.
that isn't a valid contract-call 🤔
Have you tested it?
There was a problem hiding this comment.
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.
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.
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.
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! |
|
Hello @grandima I refreshed the branch, can you take a look? |
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: