Skip to content

Add REPL commands to print contract constants, data variables, and map entries #1845

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

felixjordandev
Copy link

This PR implements the feature request in issue #1722, enhancing the Clarinet REPL with new commands to inspect contract state directly from the console.

Description

This PR introduces three new commands to the Clarinet REPL:

  • ::print-constant [<contract-identifier>.]<constant-name>: Displays the value of a defined constant within a specified contract. If the contract identifier is omitted, it defaults to the current contract context.
  • ::print-data-var [<contract-identifier>.]<var-name>: Displays the value of a data variable within a specified contract. If the contract identifier is omitted, it defaults to the current contract context.
  • ::print-map-val [<contract-identifier>.]<map-name> <key-expression>: Evaluates the <key-expression> and displays the value of the corresponding entry in the specified map. If the contract identifier is omitted, it defaults to the current contract context.

These commands provide developers with a more convenient way to query and verify contract state during interactive development and debugging sessions in the Clarinet console.

The implementation involves:

  • Updating the REPL's command handler in repl/session.rs to recognize the new commands.
  • Adding new methods to the Session struct to parse arguments, retrieve data from the Clarity VM (constants from AST, vars and map entries from VM state), and format the output.
  • The ::print-map-val command uses the existing eval() mechanism to safely evaluate the provided key expression.
  • Updating the ::help command output to include documentation for these new commands.

Breaking change?

No breaking changes are introduced by this PR.

Checklist

  • Tests added in this PR (if applicable)

@felixjordandev
Copy link
Author

@hugocaillard Hello.
This is my PR for #1722, please have a look and let me know if I need to change anything. Thank you.

@hugoclrd
Copy link
Collaborator

hugoclrd commented Jun 3, 2025

Thanks @felixjordandev!
Can you add unit tests please?

@felixjordandev
Copy link
Author

@hugocaillard, added unit tests, if there is anything else let me know.

@hugoclrd hugoclrd marked this pull request as draft June 4, 2025 13:17
@hugoclrd
Copy link
Collaborator

hugoclrd commented Jun 4, 2025

@felixjordandev I converted the PR to a draft. You have to make sure the code compiles and passes the tests

@hugoclrd
Copy link
Collaborator

Hello @felixjordandev
Have you seen my previous comment?
Thank you

@andresgalante
Copy link
Member

@felixjordandev Would you like to take this to the finish line? You are so close!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants