cairo by example


To make sure our tests work, we use assert.

fn main(x: felt252, y: felt252) {
    assert(x != y, 'error, x is equal to y');

fn test_main() {

The first argument of assert is the condition we want to check, and the second is a message we will see on the console if the condition is false.

Run cairo-test file_name

Try changing it so that the test fails.

Try it out!
  1. Install the toolchain:
    • For macOS and Linux, run our script:
    • curl -sL | bash -s 2.2.0
    • For Windows and others, please see the official guide
  2. Run the example:
    1. Copy the example into a assert.cairo file and run with:
    2. %!s(<nil>) assert.cairo

prev (hello world) next (variables)