Annotations provide additional metadata to a definition in Leo.
Annotations are a work in progress. Currently only the
@test annotation is supported.
@test annotation to define tests in a leo program.
To run tests, use the
leo test CLI command.
The console assert function was add specifically for testing purposes. You can use it to check that an expression evaluates to a true boolean value.
Inside the Leo
@test function body you have access to all
functions in the current scope.
test_add_one we initialize allocated values
one as an input to the
add_one function and save the result in
In a real program execution, we would expect
one to be provided in a Leo input
The last line of the test asserts that the type and value of
two is equal to result
Next, run the test with
The console output clearly states that our test passed, and our constraint system is satisfied.
Change the last line of
test_add_one to assert that
one is equal to the result
Run the test with
As expected, the test now fails. The console output tells us the exact line where the assertion failed.
Tests with invalid syntax will fail before their circuit is run.
Add a second
one as input to the function call to
As expected, the test fails telling us that we incorrectly provided 2 inputs to the
Since we failed before running the circuit, there is no output about the constraint system.
One or more arguments can be passed into an annotation using parenthesis
@test annotation can take one argument that will be used as the file name for input and output files.
For integration tests, one can invoke
.state files to load the correct input and state as follows:
For example, one could invoke it as any of the following examples:
Create a directory in the
/inputs directory named
Add a file named
production.in and a file named
Use the test annotation to load the production input environment into the program test.
Run the tests.