### Install Project Dependencies with npm Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Installs all necessary dependencies for the Rendezvous project after cloning the repository. This is part of the development installation process. ```bash npm install ``` -------------------------------- ### Verify Rendezvous Installation (Global) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Verifies the Rendezvous installation by checking its help information directly. This command is used when Rendezvous is installed globally. ```bash rv --help ``` -------------------------------- ### Verify Rendezvous Installation (npx) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Verifies the Rendezvous installation by checking its help information using npx. This command is used when Rendezvous is installed locally or not globally. ```bash npx rv --help ``` -------------------------------- ### Build Rendezvous Project Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Builds the Rendezvous project from source code. This command is typically run after installing dependencies during a development installation. ```bash npm run build ``` -------------------------------- ### Clone Rendezvous Repository Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Clones the Rendezvous project repository from GitHub to your local machine. This is the first step for development or contribution installations. ```bash git clone https://github.com/stacks-network/rendezvous.git ``` -------------------------------- ### Install Rendezvous Globally with npm Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Installs Rendezvous globally using npm, making the 'rv' command available system-wide. This is useful for running the command from any directory without needing 'npx'. ```bash npm install -g @stacks/rendezvous ``` -------------------------------- ### Check Node.js Version Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Checks the currently installed Node.js version. This is useful for troubleshooting installation issues related to Node.js version compatibility. ```bash node --version ``` -------------------------------- ### Link Rendezvous Package Globally Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Links a locally developed npm package globally, allowing it to be used as if it were installed globally. This is an optional step for development installations. ```bash npm link ``` -------------------------------- ### Example Pull Request Description Source: https://github.com/stacks-network/rendezvous/blob/master/docs/CONTRIBUTING.md An example of a clear and concise pull request description. It explains the purpose and impact of the changes, aiding reviewers in understanding the contribution. ```markdown This PR fixes a minor off-by-one error in the property-based tests. The fuzzing process now produces the expected results. ``` -------------------------------- ### Rendezvous Output - Shrinking Process Example Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md Sample output from a Rendezvous property test run, illustrating the shrinking process. It shows a series of test attempts, progressively simplifying the failing test case until a minimal counterexample is found. This helps in identifying the exact conditions that trigger a bug. ```text ₿ 3494 Ӿ 3526 wallet_3 [FAIL] reverse test-reverse-uint [332420496,1825325546,120054597,1173935866,164214015] (runtime) ₿ 3494 Ӿ 3527 wallet_3 [PASS] reverse test-reverse-uint [120054597,1173935866,164214015] ₿ 3494 Ӿ 3529 wallet_3 [FAIL] reverse test-reverse-uint [0,1825325546,120054597,1173935866,164214015] (runtime) ₿ 3494 Ӿ 3530 wallet_3 [PASS] reverse test-reverse-uint [120054597,1173935866,164214015] ₿ 3494 Ӿ 3532 wallet_3 [PASS] reverse test-reverse-uint [0] ₿ 3494 Ӿ 3533 wallet_3 [PASS] reverse test-reverse-uint [0,1173935866,164214015] ₿ 3494 Ӿ 3534 wallet_3 [PASS] reverse test-reverse-uint [0,120054597,1173935866,164214015] ₿ 3494 Ӿ 3535 wallet_3 [FAIL] reverse test-reverse-uint [0,0,120054597,1173935866,164214015] (runtime) ... ₿ 3494 Ӿ 3543 wallet_3 [FAIL] reverse test-reverse-uint [0,0,0,1173935866,164214015] (runtime) ₿ 3494 Ӿ 3545 wallet_3 [PASS] reverse test-reverse-uint [0,0,1173935866,164214015] ... ₿ 3494 Ӿ 3564 wallet_3 [FAIL] reverse test-reverse-uint [0,0,0,0,0] (runtime) ₿ 3494 Ӿ 3565 wallet_3 [PASS] reverse test-reverse-uint [0,0,0] ``` -------------------------------- ### Clarinet Project Structure Example Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This illustrates a typical Clarinet project directory structure, showing the location of the main configuration file (Clarinet.toml), contract files, test files, and settings. ```treeview root ☐☐ Clarinet.toml ☐☐ contracts ☐☐ ☐☐ contract.clar ☐☐ ☐☐ contract.tests.clar ☐☐ settings ☐☐ ☐☐ Devnet.toml ``` -------------------------------- ### Run Rendezvous Property Tests Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This command executes property-based tests for the 'reverse' contract using the Rendezvous tool. It's a simple way to initiate the testing process and observe the results. ```bash rv ./example slice test ``` -------------------------------- ### Install Rendezvous Fuzzer with npm Source: https://github.com/stacks-network/rendezvous/blob/master/README.md Installs the Rendezvous Clarity fuzzer package using npm. This is a prerequisite for using the `rv` command-line tool. ```bash npm install @stacks/rendezvous ``` -------------------------------- ### Run Rendezvous Property Tests Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md Execute property-based tests against a specified contract using the Rendezvous tool. This command initiates the testing process and expects the contract name and test command as arguments. Dependencies include the Rendezvous binary and the target smart contract. ```bash rv ./example reverse test ``` -------------------------------- ### Run Counter Contract Invariant Check with Rendezvous CLI Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This bash command executes Rendezvous to test the invariants of the 'counter' contract within the 'example' Clarinet project. Rendezvous will randomly call public functions and periodically check the defined invariants to detect state deviations. ```bash rv ./example counter invariant ``` -------------------------------- ### Example Commit Message Source: https://github.com/stacks-network/rendezvous/blob/master/docs/CONTRIBUTING.md Provides an example of a concise and informative Git commit message. Adhering to this format helps maintain a clean and understandable project history. ```git Fix off-by-one error in property-based test ``` -------------------------------- ### Uninstall Rendezvous Globally with npm Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Uninstalls a globally installed version of Rendezvous. This command removes the package from the global npm installation directory. ```bash npm uninstall -g @stacks/rendezvous ``` -------------------------------- ### Example: Run Property-Based Tests with Rendezvous Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This command executes property-based tests for a specified contract within a Clarinet project. It directs Rendezvous to load the project, target the 'contract' and run tests defined in its associated test file (e.g., contract.tests.clar). ```bash rv ./root contract test ``` -------------------------------- ### Remove Cloned Rendezvous Repository Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Removes the cloned Rendezvous project directory from your file system. This is the final step in uninstalling a development installation. ```bash rm -rf path/to/rendezvous ``` -------------------------------- ### Clarity Example: Reverse List Test Source: https://github.com/stacks-network/rendezvous/blob/master/README.md An example Clarity function that tests the property of reversing a list twice, asserting that the result is equal to the original list. This is used for property-based testing. ```clarity (define-public (test-reverse-list (seq (list 127 uint))) (begin (asserts! (is-eq seq (reverse-uint (reverse-uint seq))) (err u999)) (ok true))) ``` -------------------------------- ### JavaScript Code Commenting Example Source: https://github.com/stacks-network/rendezvous/blob/master/docs/CONTRIBUTING.md Illustrates effective and ineffective JavaScript code commenting practices. Good comments explain the 'why' providing context, while bad comments explain the 'how' or are redundant. ```javascript // Good: Explains why, offering crucial context. // Bad: Focuses on how or adds unnecessary verbosity. ``` -------------------------------- ### Unlink Globally Linked Rendezvous Package Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Unlinks a globally linked Rendezvous package. This is a necessary step before removing a development installation if the package was linked globally. ```bash npm unlink -g @stacks/rendezvous ``` -------------------------------- ### Rendezvous Minimal Counterexample Analysis Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md Details of a failed property test in Rendezvous, showing the final minimal counterexample found after the shrinking process. It includes the test contract, function, arguments, caller, and the specific runtime error encountered, aiding in debugging. ```text Error: Property failed after 23 tests. Seed : 869018352 Counterexample: - Test Contract : reverse - Test Function : test-reverse-uint (public) - Arguments : [[0,0,0,0,0]] - Caller : wallet_3 - Outputs : {"type":{"response":{"ok":"bool","error":"int128"}}} What happened? Rendezvous went on a rampage and found a weak spot: The test function "test-reverse-uint" returned: Call contract function error: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.reverse::test-reverse-uint((list u0 u0 u0 u0 u0)) -> Error calling contract function: Runtime error while interpreting ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.reverse: Runtime(UnwrapFailure, Some([FunctionIdentifier { identifier: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.reverse:test-reverse-uint" }, FunctionIdentifier { identifier: "_native_:special_asserts" }, FunctionIdentifier { identifier: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.reverse:reverse-uint" }, FunctionIdentifier { identifier: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.reverse:reverse-list1" }, FunctionIdentifier { identifier: "_native_:special_fold" }, FunctionIdentifier { identifier: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.reverse:reverse-redx-unsigned-list" }, FunctionIdentifier { identifier: "_native_:native_unwrap" }])) The minimal counterexample found is: [0,0,0,0,0] ``` -------------------------------- ### Uninstall Rendezvous Locally with npm Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_5.md Uninstalls Rendezvous from a specific project. This command removes the package from node_modules and updates the package.json file. ```bash npm uninstall @stacks/rendezvous ``` -------------------------------- ### Example: Run Invariant Tests with Rendezvous Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This command executes invariant tests for a specified contract within a Clarinet project. Rendezvous will randomly call public functions and check defined invariants to ensure the contract's state remains valid. Failures indicate potential bugs. ```bash rv ./root contract invariant ``` -------------------------------- ### Clarinet.toml Contract Definition Example Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This TOML snippet shows how a contract named 'contract' is defined within a Clarinet project's configuration file, specifying the path to its Clarinet code. ```toml [contracts.contract] path = "contracts/contract.clar" ``` -------------------------------- ### Introduce Bug in reverse-uint Private Utility (Clarity) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This snippet demonstrates how to introduce a bug into the `reverse-uint` private utility by incorrectly limiting the maximum supported list length. This limitation can lead to an unwrap failure runtime error if the input list exceeds the new, incorrect limit. ```clarity (define-read-only (reverse-uint (seq (list 127 uint))) (reverse-list1 seq) ) (define-private (reverse-list1 (seq (list 127 uint))) (fold reverse-redx-unsigned-list seq (list)) ) (define-private (reverse-redx-unsigned-list (item uint) (seq (list 127 uint))) (unwrap-panic (as-max-len? (concat (list item) seq) u4 ;; Introduces a bug by limiting max length incorrectly. ) ) ) ``` -------------------------------- ### Execute Custom JavaScript Dialers with --dial Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md Integrate custom JavaScript functions for pre- and post-execution logic during invariant testing using the --dial option. This allows for advanced validation and state manipulation. The provided example demonstrates a post-dialer for SIP-010 compliance. ```bash rv root contract invariant --dial=./custom-dialer.js ``` -------------------------------- ### Run Rendezvous Tests on Counter Contract Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md Executes property-based tests against the 'counter' contract using Rendezvous. By default, it runs 100 tests. To ensure sufficient coverage and detect potential bugs, especially in contracts with limited test cases like 'test-increment', increase the number of runs using the --runs option. ```bash rv ./example counter test rv ./example counter test --runs=1002 ``` -------------------------------- ### Clarity Property-Based Test for `slice-uint` Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This Clarity code implements a property-based test function, `test-slice-list-uint`, designed to evaluate the `slice-uint` contract. It includes logic to discard invalid test cases where `skip` or `n` are out of bounds. For valid inputs, it asserts three cases: when `skip` exceeds the list length, when `n` is larger than remaining elements, and when `n` is within bounds. ```clarity (define-public (test-slice-list-uint (seq (list 127 uint)) (skip int) (n int)) (if ;; Discard the test if the input is invalid by returning `(ok false)`. (or (not (and (<= 0 n) (<= n 127))) (not (and (<= 0 skip) (<= skip 127))) ) (ok false) (let ((result (slice-uint seq skip n))) (if ;; Case 1: If skip > length of seq, result should be an empty list. (> (to-uint skip) (len seq)) (asserts! (is-eq result (list )) ERR_ASSERTION_FAILED_1) (if ;; Case 2: If n > length of seq - skip, result length should be ;; length of seq - skip. (> (to-uint n) (- (len seq) (to-uint skip))) (asserts! (is-eq (len result) (- (len seq) (to-uint skip))) ERR_ASSERTION_FAILED_2 ) ;; Case 3: If n <= length of seq - skip, result length should be n. (asserts! (is-eq (len result) (to-uint n)) ERR_ASSERTION_FAILED_3) ) ) (ok true) ) ) ) ``` -------------------------------- ### Clarity Example: Counter Invariant Test Source: https://github.com/stacks-network/rendezvous/blob/master/README.md A Clarity invariant function designed to detect bugs in a counter contract. It checks if the counter is greater than zero only when the number of increment calls exceeds the number of decrement calls. ```clarity (define-read-only (invariant-counter-gt-zero) (let ((increment-num-calls (default-to u0 (get called (map-get? context "increment")))) (decrement-num-calls (default-to u0 (get called (map-get? context "decrement"))))) (if (> increment-num-calls decrement-num-calls) (> (var-get counter) u0) true))) ``` -------------------------------- ### Clarity `slice-uint` Contract with Bug Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This Clarity code defines the `slice-uint` read-only function and its private helper `slice-list1`. A bug is intentionally introduced in `slice-list1` where the `skip` parameter is hardcoded to 1 in a conditional check, leading to incorrect slicing behavior. The function takes a list of unsigned integers, a skip count, and a number of elements to slice, with boundary assertions. ```clarity (define-read-only (slice-uint (seq (list 127 uint)) (skip int) (n int)) (begin (assert- (and (<= 0 skip) (<= skip 127)) "Out of bounds: skip") (assert- (and (<= 0 n) (<= n 127)) "Out of bounds: n") (slice-list1 seq skip n) ) ) (define-private (slice-list1 (seq (list 127 uint)) (skip int) (n int)) (begin (assert- (and (<= 0 skip) (<= skip 127)) "Out of bounds: skip") (assert- (and (<= 0 n) (<= n 127)) "Out of bounds: n") (let ( (end (- (min-num-integer-integer (+ skip n) (to-int (len seq))) 1 ) ) ) (if (>= end 1) ;; Introduce a bug that forces `skip` to always be 1 in this comparison. (let ((i (range-1-integer-integer skip end))) (map for-step-integer-list1 i (repeat127-list1 seq)) ) (list) ) ) ) ) ``` -------------------------------- ### Run Rendezvous Invariant Tests on Cargo Contract Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md Executes invariant testing against the 'cargo' contract using Rendezvous. This command randomly calls public functions within the 'cargo' contract and periodically checks the defined invariants. If an invariant fails, it indicates a potential bug, such as the 'last-shipment-id' not being updated correctly. ```bash rv ./example cargo invariant ``` -------------------------------- ### Clarinet: Create New Shipment Function (Buggy) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This Clarinet code defines the 'create-new-shipment' function for the 'cargo' contract. The commented-out line '(var-set last-shipment-id new-shipment-id)' represents the fix for a bug where the 'last-shipment-id' was not updated. Commenting this line out re-introduces the bug for testing purposes. ```clarity (define-public (create-new-shipment (starting-location (string-ascii 25)) (receiver principal)) (let ( (new-shipment-id (+ (var-get last-shipment-id) u1)) ) ;; #[filter(starting-location, receiver)] (map-set shipments new-shipment-id { location: starting-location, status: "In Transit", shipper: tx-sender, receiver: receiver }) ;; The following line fixes the bug in the original implementation. ;; Comment out this line to re-introduce the bug. ;; (var-set last-shipment-id new-shipment-id) (ok "Shipment created successfully") ) ) ``` -------------------------------- ### Implement Faulty Counter Increment Logic in Clarity Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This Clarity code snippet introduces a bug into the 'increment' function of a counter contract. The bug causes the counter to reset to 0 if its value exceeds 1000. This demonstrates how to create and test faulty contract logic. ```clarity (define-public (increment) (let ( (current-counter (var-get counter)) ) (if (> current-counter u1000) ;; Introduce a bug for large values. (ok (var-set counter u0)) ;; Reset counter to zero if it exceeds 1000. (ok (var-set counter (+ current-counter u1))) ) ) ) ``` -------------------------------- ### Clarity Discard Function for Test Validity Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This Clarity code defines a discard function 'can-test-slice-list-int' to validate inputs for the 'test-slice-list-int' property test. The discard function checks if the 'n' and 'skip' parameters are within valid ranges relative to the sequence length. If the inputs are not valid, the test will be discarded. ```clarity ;; Some tests, like 'test-slice-list-int', are valid only for specific inputs. ;; Rendezvous generates a wide range of inputs, which may include values that ;; are unsuitable for those tests. ;; To skip the test when inputs are invalid, the first way is to define a ;; 'discard' function: ;; - Must be read-only. ;; - Name should match the property test function's, prefixed with "can-". ;; - Parameters should mirror those of the property test. ;; - Returns true only if inputs are valid, allowing the test to run. (define-read-only (can-test-slice-list-int (seq (list 127 int)) (skip int) (n int) ) (and (and (<= 0 n) (<= n 127)) (and (<= 0 skip) (<= skip 127)) ) ) (define-public (test-slice-list-int (seq (list 127 int)) (skip int) (n int)) (let ((result (slice seq skip n))) (if ;; Case 1: If skip > length of seq, result should be an empty list. (> (to-uint skip) (len seq)) (asserts! (is-eq result (list )) ERR_ASSERTION_FAILED_1) (if ;; Case 2: If n > length of seq - skip, result length should be ;; length of seq - skip. (> (to-uint n) (- (len seq) (to-uint skip))) (asserts! (is-eq (len result) (- (len seq) (to-uint skip))) ERR_ASSERTION_FAILED_2 ) ;; Case 3: If n <= length of seq - skip, result length should be n. (asserts! (is-eq (len result) (to-uint n)) ERR_ASSERTION_FAILED_3) ) ) (ok true) ) ) ``` -------------------------------- ### Run Rendezvous Property Tests on Cargo Contract Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md Executes property-based tests against the 'cargo' contract using Rendezvous. This command randomly selects and runs tests defined in the 'cargo' contract's test suite. If the 'test-get-last-shipment-id' function is the only test present, Rendezvous will quickly identify the bug related to the 'last-shipment-id' not incrementing. ```bash rv ./example cargo test ``` -------------------------------- ### Test Counter Increment Property in Clarity Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This Clarity code defines a property-based test for the 'increment' function of a counter contract. It asserts that after a successful call to 'increment', the counter's value should increase by exactly one. This test is designed to catch unexpected behavior, like the counter resetting. ```clarity (define-public (test-increment) (let ( (counter-before (get-counter)) ) (unwrap-panic (increment)) (asserts! (is-eq (get-counter) (+ counter-before u1)) (err u404)) (ok true) ) ) ``` -------------------------------- ### Clarinet: Invariant for Shipment ID Check Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md Defines a read-only invariant function in Clarinet to check if 'last-shipment-id' is greater than 0 after a shipment has been created. This invariant uses the 'context' utility from Rendezvous to count calls to 'create-new-shipment'. It ensures that if any shipments exist, the ID counter is positive, helping to detect bugs where the ID is not updated. ```clarity (define-read-only (invariant-last-shipment-id-gt-0-after-create-shipment) (let ( (create-shipment-num-calls (default-to u0 (get called (map-get? context "create-new-shipment"))) ) ) (if (is-eq create-shipment-num-calls u0) true (> (var-get last-shipment-id) u0) ) ) ) ``` -------------------------------- ### Define Counter Invariant for Positive Value Check in Clarity Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md This Clarity code defines an invariant for a counter contract that checks if the counter value is greater than zero when the 'increment' function has been called more often than 'decrement'. It utilizes Rendezvous's 'context' utility to access function call counts. ```clarity (define-read-only (invariant-counter-gt-zero) (let ( (increment-num-calls (default-to u0 (get called (map-get? context "increment")) ) ) (decrement-num-calls (default-to u0 (get called (map-get? context "decrement")) ) ) ) (if (<= increment-num-calls decrement-num-calls) true (> (var-get counter) u0) ) ) ) ``` -------------------------------- ### Clarinet: Property Test for Shipment ID Increment Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_7.md A property-based test function in Clarinet designed to verify the correct incrementing of 'last-shipment-id' in the 'cargo' contract. It records the ID before creating a new shipment, calls 'create-new-shipment', and then asserts that the 'last-shipment-id' has increased by exactly 1. This test helps identify bugs where the shipment ID counter fails to update. ```clarity (define-public (test-get-last-shipment-id (starting-location (string-ascii 25)) (receiver principal) ) (let ((shipment-id-before (get-last-shipment-id))) (unwrap! (create-new-shipment starting-location receiver) ERR_CONTRACT_CALL_FAILED ) ;; Verify the last shipment ID is incremented by 1. (asserts! (is-eq (get-last-shipment-id) (+ u1 shipment-id-before)) ERR_ASSERTION_FAILED ) (ok true) ) ) ``` -------------------------------- ### Run Rendezvous Command Line Tool Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This command initiates the Rendezvous testing process. It requires the path to the Clarinet project, the name of the contract to test, and the type of tests to run (e.g., 'test' for property-based or 'invariant' for invariant tests). Optional flags like --seed, --runs, --bail, and --dial can further configure the test execution. ```bash rv [--seed] [--runs] [--bail] [--dial] ``` -------------------------------- ### Run Tests with npm Source: https://github.com/stacks-network/rendezvous/blob/master/docs/CONTRIBUTING.md Shows the command to execute tests using npm. This is crucial for ensuring code changes do not introduce regressions and meet project standards. ```bash npm test ``` -------------------------------- ### Clarity Fuzzer Usage Command Source: https://github.com/stacks-network/rendezvous/blob/master/README.md Demonstrates the command-line usage of the Rendezvous (rv) fuzzer. It requires the path to the Clarinet project, the contract name, and the type of test to run (test or invariant). ```bash npx rv ``` -------------------------------- ### Clarinet TOML Configuration for SBTC Token Testing Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This TOML configuration specifies contract paths and Clarity versions for testing a specific token, 'sbtc-token'. Rendezvous uses this file to initialize Simnet when testing 'sbtc-token', falling back to the standard Clarinet.toml if this file is not found. This allows for isolated testing of specific components. ```toml [contracts.sbtc-registry] path = 'contracts/sbtc-registry-double.clar' clarity_version = 3 epoch = 3.0 ``` -------------------------------- ### Clarity Contract with Property-Based Test Using Trait References Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This Clarity test file demonstrates a property-based test that utilizes trait reference parameters. Rendezvous facilitates this by discovering available trait implementations in the project and randomly selecting one for each test execution, thereby increasing behavioral diversity and uncovering potential edge cases. ```clarity ;; Example from send-tokens.tests.clar ;; ... property-based test definition ... (property-test (test-trait-ref) ; Assuming this is how a trait ref is used in a test context (define-public (test-trait-ref) ...) ) ``` -------------------------------- ### Create Git Branch Source: https://github.com/stacks-network/rendezvous/blob/master/docs/CONTRIBUTING.md Demonstrates how to create a new Git branch for development work. This is a standard Git command used to isolate changes before merging them. ```bash git checkout -b my-fix ``` -------------------------------- ### Clarity Contract with Rendezvous Context Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This snippet demonstrates how a Clarity contract is modified by Rendezvous for testing. It includes the original contract functions, the new 'context' map for tracking execution, and the 'update-context' function to manage the context. This merged contract is deployed in a Simnet session. ```clarity (define-public (check-it (flag bool)) (if flag (ok 1) (err u100)) ) (define-map context (string-ascii 100) { called: uint ;; other data } ) (define-public (update-context (function-name (string-ascii 100)) (called uint)) (ok (map-set context function-name {called: called})) ) (define-public (test-1) (ok true) ) (define-read-only (invariant-1) true ) ``` -------------------------------- ### Property-Based Test: Verify list reversal in Clarity Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_4.md This Clarity code demonstrates a property-based test. It verifies that reversing a list twice returns the original list. Rendezvous automatically generates random list inputs for the `seq` parameter. The test passes if `(ok true)` is returned and fails otherwise. ```clarity (define-public (test-reverse-uint (seq (list 127 uint))) (begin (asserts! (is-eq seq (reverse-uint (reverse-uint seq))) ERR_ASSERTION_FAILED ) (ok true) ) ) ``` -------------------------------- ### Clarity Contract with Trait Reference Parameter Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This Clarity contract defines a public function that accepts a trait reference parameter. Rendezvous automatically handles these by scanning for implementations within the project, adding them to a selection pool, and randomly choosing one during test execution to ensure state transitions and validate invariants. ```clarity ;; Example from send-tokens.clar ;; ... function definition accepting a trait reference ... ``` -------------------------------- ### Rendezvous Context Map and Update Function (Clarity) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This code illustrates the core components of the Rendezvous context: a Clarity map named 'context' for storing execution data and a public function 'update-context' to modify this map. The map tracks successful function calls, and the function provides a mechanism to update this tracking information. ```clarity (define-map context (string-ascii 100) { called: uint ;; Additional fields can be added here }) (define-public (update-context (function-name (string-ascii 100)) (called uint)) (ok (map-set context function-name {called: called})) ) ``` -------------------------------- ### Replay Specific Test Sequence with --seed Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md Reproduce a previous test execution by using the --seed option with a specific seed value. This ensures the same random values are used, making test runs deterministic and aiding in debugging. Seeds are provided in failure reports. ```bash rv root contract test --seed=12345 ``` ```bash rv root contract test --seed=426141810 ``` -------------------------------- ### Clarity Contract Implementing a Required Trait for Rendezvous Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md This Clarity contract serves as a trait implementation required by Rendezvous for testing functions that accept trait reference parameters. Its presence in the project allows Rendezvous to discover and select it as an argument during test execution, enabling meaningful state transitions. ```clarity ;; Example from rendezvous-token.clar ;; ... contract implementing the required trait ... ``` -------------------------------- ### In-Place Discarding: Skip Test with Invalid Input (Clarity) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md A test function that internally checks input validity. If inputs are invalid, it returns '(ok false)', effectively discarding the test run without executing the main test logic. ```clarity (define-public (test-add (n uint)) (let ((counter-before (get-counter))) (ok (if (<= n u1) ;; If n <= 1, discard the test. false (begin (try! (add n)) (asserts! (is-eq (get-counter) (+ counter-before n)) (err u403)) true ) ) ) ) ) ``` -------------------------------- ### Stop Testing After First Failure with --bail Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md Immediately halt test execution upon detecting the first failure using the --bail option. This is useful for quickly examining the cause of the initial error without completing the entire test run and shrinking process. ```bash rv root contract test --bail ``` -------------------------------- ### Test Double: Loosen Authorization for Testing (Clarity) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md A contract intended as a test double, specifically for the 'sbtc-registry'. It modifies the 'is-protocol-caller' function to allow the 'deployer' principal to act as a protocol contract, enabling testing of restricted functions. ```clarity ;; contracts/sbtc-registry-double.clar ... (define-constant deployer tx-sender) ;; Allows the deployer to act as a protocol contract for testing (define-read-only (is-protocol-caller (contract-flag (buff 1)) (contract principal)) (begin (asserts! (is-eq tx-sender deployer) (err u1234567)) ;; Enforces deployer check (ok true) ) ) ... ``` -------------------------------- ### Customize Number of Test Runs with --runs Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md Modify the total number of test iterations executed by Rendezvous using the --runs option. This allows for more extensive testing if needed. The default is 100. ```bash rv root contract test --runs=500 ``` -------------------------------- ### Discard Function: Validate Input for Test (Clarity) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md A read-only function prefixed with 'can-' that validates inputs for a corresponding property test. It must mirror the test's parameters and return true only if the inputs are valid, allowing the test to proceed. ```clarity (define-read-only (can-test-add (n uint)) (> n u1) ;; Only allow tests where n > 1 ) (define-public (test-add (n uint)) (let ((counter-before (get-counter))) (try! (add n)) (asserts! (is-eq (get-counter) (+ counter-before n)) (err u403)) (ok true) ) ) ``` -------------------------------- ### SIP-010 Transfer Event Validation (JavaScript Dialer) Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_6.md A JavaScript post-dialer function designed to verify SIP-010 compliance for token transfers. It checks if the 'transfer' function emits a 'print_event' containing the memo, ensuring adherence to the SIP-010 standard. This function receives context about the function call and its arguments. ```javascript async function postTransferSip010PrintEvent(context) { const { selectedFunction, functionCall, clarityValueArguments } = context; // Ensure this check runs only for the "transfer" function. if (selectedFunction.name !== "transfer") return; const functionCallEvents = functionCall.events; const memoParameterIndex = 3; // The memo parameter is the fourth argument. const memoGeneratedArgumentCV = clarityValueArguments[memoParameterIndex]; // If the memo argument is `none`, there's nothing to validate. if (memoGeneratedArgumentCV.type === 9) return; // Ensure the memo argument is an option (`some`). if (memoGeneratedArgumentCV.type !== 10) { throw new Error("The memo argument must be an option type!"); } // Convert the `some` value to hex for comparison. const hexMemoArgumentValue = cvToHex(memoGeneratedArgumentCV.value); // Find the print event in the function call events. const sip010PrintEvent = functionCallEvents.find( (ev) => ev.event === "print_event" ); if (!sip010PrintEvent) { throw new Error( "No print event found. The transfer function must emit the SIP-010 print event containing the memo!" ); } const sip010PrintEventValue = sip010PrintEvent.data.raw_value; // Validate that the emitted print event matches the memo argument. if (sip010PrintEventValue !== hexMemoArgumentValue) { throw new Error( `Print event memo value does not match the memo argument: ${hexMemoArgumentValue} !== ${sip010PrintEventValue}` ); } } ``` -------------------------------- ### Invariant Test: Ensure counter remains positive in Clarity Source: https://github.com/stacks-network/rendezvous/blob/master/docs/chapter_4.md This Clarity code defines an invariant test for a counter. It checks if the counter is greater than zero when the number of increments is greater than the number of decrements. This invariant is checked by Rendezvous between random function calls to ensure state consistency. ```clarity (define-read-only (invariant-counter-gt-zero) (let ( (increment-num-calls (default-to u0 (get called (map-get? context "increment"))) ) (decrement-num-calls (default-to u0 (get called (map-get? context "decrement"))) ) ) (if (<= increment-num-calls decrement-num-calls) true (> (var-get counter) u0) ) ) ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.