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

Custom manifest file support #107

Merged
merged 3 commits into from
Feb 3, 2025
Merged

Conversation

BowTiedRadone
Copy link
Collaborator

This PR adds support for custom manifest files for each target contract. To use one, place a file named Clarinet-<contract-name>.toml in the target Clarinet project's root.

Example

For the command:

npx rv sbtc/contracts sbtc-token invariant

Rendezvous will check for sbtc-token/contracts/Clarinet-sbtc-token.toml. If found, it will be used to initialize the Simnet. If not, the default Clarinet.toml will be used.

Real-World Use Case

When fuzzing sbtc-token, a user may need to replace sbtc-registry with a test double. This allows bypassing the is-protocol-caller check, enabling state transitions.

Original sbtc-registry.clar

See sbtc-registry

(define-read-only (is-protocol-caller (contract-flag (buff 1)) (contract principal))
  (begin
    (asserts! (is-eq (some contract) (map-get? active-protocol-contracts contract-flag)) ERR_UNAUTHORIZED)
    (asserts! (is-eq (some contract-flag) (map-get? active-protocol-roles contract)) ERR_UNAUTHORIZED)
    (ok true)
  )
)

Test Double sbtc-registry-double.clar

(define-constant deployer tx-sender)

(define-read-only (is-protocol-caller (contract-flag (buff 1)) (contract principal))
  (begin
    (asserts! (is-eq tx-sender deployer) ERR_UNAUTHORIZED)
    (ok true)
  )
)

Rendezvous Property Test sbtc-token.tests.clar

(define-public (test-protocol-set-token-uri
    (new-uri (optional (string-utf8 256)))
    (contract-flag (buff 1))
  )
  (let (
      (initial-uri (unwrap-panic (get-token-uri)))
    )
    (ok
      (if
        (or
          (not (is-eq tx-sender deployer))
          (is-eq initial-uri new-uri)
        )
        false
        (begin
          (try! (protocol-set-token-uri new-uri contract-flag))
          (asserts!
            (is-eq
              (unwrap-panic (get-token-uri))
              new-uri
            )
            ERR_FAILED_ASSERTION
          )
          true
        )
      )
    )
  )
)

Custom Manifest Setup

To use the test double, create a custom manifest file:

# Clarinet-sbtc-token.toml
# unchanged...
[contracts.sbtc-registry]
path = 'contracts/sbtc-registry-double.clar'
clarity_version = 3
epoch = 3.0
# unchanged...

This PR can represent a solution for #97, where @moodmosaic pointed out the Test Doubles approach in #97 (comment).

This commit allows Rendezvous users to design a custom manifest file for each
fuzzed contract. This also allows for testing doubles. The custom manifest file
should be named `Clarinet-<contract-name>.toml`.
@BowTiedRadone BowTiedRadone requested a review from a team as a code owner January 31, 2025 15:31
app.tests.ts Outdated Show resolved Hide resolved
app.tests.ts Outdated Show resolved Hide resolved
@BowTiedRadone BowTiedRadone merged commit 4c3df98 into master Feb 3, 2025
21 checks passed
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.

2 participants