clarinet icon indicating copy to clipboard operation
clarinet copied to clipboard

feat: implement console commands for accessing contract state data

Open grandima opened this issue 1 month ago • 5 comments

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 contract

Implementation Details

  • Added command handlers in components/clarity-repl/src/repl/session.rs
  • Added help documentation for the new commands
  • Added comprehensive tests in components/clarinet-cli/tests/console.rs

Test Plan

  • [x] All existing tests pass
  • [x] Added unit tests for all three new commands
  • [x] Commands work with both valid and invalid contract identifiers
  • [x] Error handling works correctly for missing contracts/data
  • [x] Help documentation displays properly

REPL demo of interaction with fixtures/mxs/counter.clar contract:

Screenshot 2025-11-05 at 18 07 15 Screenshot 2025-11-05 at 18 07 24

grandima avatar Oct 30 '25 13:10 grandima

@hugoclrd please check, it's ready for review.

grandima avatar Oct 30 '25 14:10 grandima

Hello @grandima Have you seen the review?

Thank you

hugo-stacks avatar Nov 04 '25 10:11 hugo-stacks

@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.

grandima avatar Nov 04 '25 14:11 grandima

@hugo-stacks please check again as I applied the suggested changes and attached screenshots.

grandima avatar Nov 05 '25 17:11 grandima

Codecov Report

:x: Patch coverage is 61.49068% with 62 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
components/clarity-repl/src/repl/session.rs 61.49% 62 Missing :warning:

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Nov 05 '25 18:11 codecov[bot]