Skip to content

Conversation

@grandima
Copy link

@grandima grandima commented Oct 30, 2025

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

  • All existing tests pass
  • Added unit tests for all three new commands
  • Commands work with both valid and invalid contract identifiers
  • Error handling works correctly for missing contracts/data
  • 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
Copy link
Author

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

Copy link
Collaborator

@hugo-stacks hugo-stacks left a 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?

Comment on lines 1173 to 1175
let default_deployer = self.settings.initial_deployer.as_ref()
.map(|account| account.address.clone())
.unwrap_or_else(|| "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM".to_string());
Copy link
Collaborator

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 {})",
Copy link
Collaborator

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?

Copy link
Collaborator

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());
Copy link
Collaborator

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());
Copy link
Collaborator

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 {} {})",
Copy link
Collaborator

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()

@hugo-stacks
Copy link
Collaborator

Hello @grandima
Have you seen the review?

Thank you

@grandima
Copy link
Author

grandima commented Nov 4, 2025

@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 grandima marked this pull request as draft November 4, 2025 14:28
auto-merge was automatically disabled November 4, 2025 14:28

Pull request was converted to draft

    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
@grandima grandima marked this pull request as ready for review November 5, 2025 17:15
@grandima grandima requested a review from hugo-stacks November 5, 2025 17:18
@grandima
Copy link
Author

grandima commented Nov 5, 2025

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

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ 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 ⚠️

📢 Thoughts on this report? Let us know!

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.

Print data vars, maps, and constants in console

2 participants