Skip to content
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

Support unit tests written in Clarity - #[test] #1456

Open
lgalabru opened this issue May 15, 2024 · 2 comments
Open

Support unit tests written in Clarity - #[test] #1456

lgalabru opened this issue May 15, 2024 · 2 comments
Labels

Comments

@lgalabru
Copy link
Contributor

lgalabru commented May 15, 2024

A non negligible amount of developers want to write their tests in clarity.
I wonder if this is something we could support "simply" by introducing a #[test] command processor.
It could look like:

(define-public (increment-counter (step uint))
    (+ step (data-var-get counter)))

;; #[test]
(define-public (test-increment)
    (asserts! (is-eq u1 (increment-counter u1)) (err u1001)))

I think we would still be using js/ts for coordinating / structuring the test execution, but at least the logic would be written in clarity - developers would be calling something like:

describe("Counter contract tests", () => {
  it("ensures counter is counting", () => {
    const { result, events } = simnet.assertPublicFn(
      "counter",
      "test-increment",
      [Cl.uint(1)],
      deployer,
    );
  });
});

So when deploying such contracts, I think the #[test] directive would exclude the subsequent clarity statement from the contract?

@lgalabru lgalabru changed the title Support clarity unit testing - #[test] Support unit tests written in Clarity - #[test] May 15, 2024
@hugocaillard
Copy link
Collaborator

@lgalabru What do you think about the clarunit approach? https://www.npmjs.com/package/@stacks/clarunit
(Similar ideas)

@lgalabru
Copy link
Contributor Author

Oh nice, that probably works. I guess with this present proposal, clarity testing clarity would become a first class citizen.
We can keep this issue open for a few week and passively collect feedbacks / demands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants