TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/provablehq/leo/llms.txt
Use this file to discover all available pages before exploring further.
leo test command discovers and runs test functions annotated with @test in your Leo programs.
Syntax
Arguments
Optional filter to run only tests whose qualified name matches this string.Examples:
test_add- Runs tests containing “test_add”my_program.aleo/test_transfer- Runs specific test in program
Options
Network Options
Network type:
mainnet, testnet, or canary. Defaults to testnet.Network endpoint URL for dependencies.
Build Options
Enable offline mode. Prevents network requests.
Don’t use the dependency cache.
Use network versions of dependencies.
Examples
Run All Tests
Run Specific Test
Run Tests Matching Pattern
Writing Tests
Basic Test
Annotate transition functions with@test:
Test functions must be transitions (entry points) to be discovered by
leo test.Test with Expected Failure
Use@should_fail to test error conditions:
Test with Custom Private Key
Specify a private key for the test:Multiple Tests
Test Output
Passing Tests
Failing Tests
No Tests Found
- No functions have the
@testannotation - The test filter doesn’t match any tests
- All test functions are not transitions
Test Execution Flow
-
Build Phase:
- Compiles program with
--build-testsflag - Includes test functions in build
- Compiles program with
-
Test Discovery:
- Scans AST for
@testannotations - Filters by test name if provided
- Validates tests are transitions
- Scans AST for
-
Test Execution:
- Initializes VM with in-memory ledger
- Executes each test independently
- Captures outputs and errors
-
Result Reporting:
- Displays pass/fail for each test
- Shows error messages for failures
- Reports total pass/fail count
Assertions
Leo provides built-in assertion functions:assert_eq
Asserts two values are equal:assert_neq
Asserts two values are not equal:assert
Asserts a boolean condition:Testing Best Practices
1. Test Coverage
Test all public transitions:2. Descriptive Names
Use clear, descriptive test names:3. Test Edge Cases
4. Independent Tests
Each test should be independent:5. Test with Realistic Data
Testing with Dependencies
Tests can call functions from dependencies:Continuous Integration
Integrateleo test in CI/CD pipelines:
Troubleshooting
Test Not Discovered
Ensure:- Function has
@testannotation - Function is a
transition(not afunction) - Test name matches filter (if provided)
Test Fails Unexpectedly
Check:- Function logic is correct
- Assertions use correct expected values
- No side effects from previous tests
Build Errors in Tests
If tests fail to compile:Performance
Test execution time depends on:- Number of tests
- Complexity of test functions
- Number of dependencies