From 4015650ecc6e1404ccaef424436e1ca4d994e6cc Mon Sep 17 00:00:00 2001 From: Aurelien Isak Date: Thu, 8 Sep 2022 10:36:58 +0200 Subject: [PATCH 1/5] ADD migrate.sh script and migrate all files --- exercises/builtins/bitwise.cairo | 243 +++++++++--------- exercises/hints/hints00.cairo | 36 +-- exercises/hints/hints01.cairo | 54 ++-- .../implicit_arguments01.cairo | 30 +-- .../implicit_arguments02.cairo | 60 ++--- .../implicit_arguments03.cairo | 38 +-- exercises/operations/operations00.cairo | 34 +-- exercises/operations/operations01.cairo | 36 +-- exercises/operations/operations02.cairo | 38 +-- exercises/operations/operations03.cairo | 34 +-- exercises/recursions/array01.cairo | 48 ++-- exercises/recursions/array02.cairo | 58 ++--- exercises/recursions/array03.cairo | 176 ++++++------- exercises/recursions/array04.cairo | 54 ++-- exercises/recursions/collatz_sequence.cairo | 74 +++--- exercises/recursions/recursion01.cairo | 42 +-- exercises/recursions/struct01.cairo | 80 +++--- exercises/registers/registers00.cairo | 58 ++--- exercises/registers/registers01.cairo | 60 ++--- exercises/registers/registers02.cairo | 184 ++++++------- exercises/registers/registers03.cairo | 122 ++++----- exercises/registers/registers04.cairo | 48 ++-- .../revoked_references01.cairo | 48 ++-- exercises/storage/storage01.cairo | 26 +- exercises/storage/storage02.cairo | 72 +++--- exercises/storage/storage03.cairo | 50 ++-- exercises/strings/strings00.cairo | 40 +-- exercises/strings/strings01.cairo | 50 ++-- exercises/syntax/syntax01.cairo | 16 +- exercises/syntax/syntax02.cairo | 16 +- exercises/syntax/syntax03.cairo | 24 +- exercises/syntax/syntax04.cairo | 30 +-- exercises/syntax/syntax05.cairo | 20 +- exercises/tricks/assert_bool.cairo | 150 +++++------ exercises/tricks/inline_if.cairo | 42 +-- exercises/tricks/no_conditionals.cairo | 102 ++++---- migrate.sh | 11 + 37 files changed, 1156 insertions(+), 1148 deletions(-) create mode 100755 migrate.sh diff --git a/exercises/builtins/bitwise.cairo b/exercises/builtins/bitwise.cairo index b5775371..18633d31 100644 --- a/exercises/builtins/bitwise.cairo +++ b/exercises/builtins/bitwise.cairo @@ -6,130 +6,129 @@ from starkware.cairo.common.bitwise import bitwise_and, bitwise_xor, bitwise_or from starkware.cairo.common.cairo_builtins import BitwiseBuiltin from starkware.cairo.common.pow import pow -# While operations like addition, multiplication and divisions are native for felts, -# bit operations are more difficult to implement for felt. -# The bitwise builtin allows computing logical operations such as XOR, AND and OR on 251-bit felts. +// While operations like addition, multiplication and divisions are native for felts, +// bit operations are more difficult to implement for felt. +// The bitwise builtin allows computing logical operations such as XOR, AND and OR on 251-bit felts. -# Resources: -# - https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/bitwise.cairo -# - https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/cairo_builtins.cairo#L17 +// Resources: +// - https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/bitwise.cairo +// - https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/cairo_builtins.cairo#L17 -# I AM NOT DONE +// I AM NOT DONE -# TODO: Use a bitwise operation to return the n-th bit of the value parameter +// TODO: Use a bitwise operation to return the n-th bit of the value parameter -func get_nth_bit{bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt}(value, n) -> (res): - # FILL ME - return (res) -end +func get_nth_bit{bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}(value, n) -> (res: felt) { + // FILL ME + return (res,); +} -# TODO: Use a bitwise operation to set the n-th bit of the value parameter to 1 +// TODO: Use a bitwise operation to set the n-th bit of the value parameter to 1 -func set_nth_bit{bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt}(value, n) -> (res): - # FILL ME - return (res) -end +func set_nth_bit{bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}(value, n) -> (res: felt) { + // FILL ME + return (res,); +} -# TODO: Use a bitwise operation to toggle the n-th bit of the value parameter +// TODO: Use a bitwise operation to toggle the n-th bit of the value parameter -func toggle_nth_bit{bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt}(value, n) -> (res): - # FILL ME - return (res) -end +func toggle_nth_bit{bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}(value, n) -> (res: felt) { + // FILL ME + return (res,); +} -# Let's write a unique function that combines all the functions above. -# This function should use the bitwise_ptr explicitly. -# In particular, do not use any of the functions above. +// Let's write a unique function that combines all the functions above. +// This function should use the bitwise_ptr explicitly. +// In particular, do not use any of the functions above. -# TODO: Write a function that takes as argument -# - a felt `op` in ['get', 'set', 'toggle'], -# - felts `value` and `n`, -# and returns the result of the operation applied to `n`-th bit of value. -# Make sure -# - the argument `n` is within the correct bitwise bounds, -# - the `op` argument is correct. +// TODO: Write a function that takes as argument +// - a felt `op` in ['get', 'set', 'toggle'], +// - felts `value` and `n`, +// and returns the result of the operation applied to `n`-th bit of value. +// Make sure +// - the argument `n` is within the correct bitwise bounds, +// - the `op` argument is correct. -func op_nth_bit{bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt}(op, value, n) -> (res): - alloc_locals +func op_nth_bit{bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}(op, value, n) -> (res: felt) { + alloc_locals; - # Assert op is correct + // Assert op is correct - with_attr error_message("Bad bitwise bounds"): - # Assert n is within bounds - end + with_attr error_message("Bad bitwise bounds") { + // Assert n is within bounds + } - # Compute the operation - # Don't forget to advance bitwise_ptr + // Compute the operation + // Don't forget to advance bitwise_ptr - return (res) -end + return (res,); +} -# Do not modify the tests. +// Do not modify the tests. @view -func test_get_nth_bit{syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt}(): - alloc_locals - local value = 0xA8 - let (local r0) = get_nth_bit(value, 0) - let (local r1) = get_nth_bit(value, 1) - let (local r2) = get_nth_bit(value, 2) - let (local r3) = get_nth_bit(value, 3) - let (local r4) = get_nth_bit(value, 4) - let (local r5) = get_nth_bit(value, 5) - let (local r6) = get_nth_bit(value, 6) - let (local r7) = get_nth_bit(value, 7) - assert r0 * 2 ** 0 + r1 * 2 ** 1 + r2 * 2 ** 2 + r3 * 2 ** 3 + r4 * 2 ** 4 + r5 * 2 ** 5 + r6 * 2 ** 6 + r7 * 2 ** 7 = value - return () -end +func test_get_nth_bit{syscall_ptr: felt*, bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}() { + alloc_locals; + local value = 0xA8; + let (local r0) = get_nth_bit(value, 0); + let (local r1) = get_nth_bit(value, 1); + let (local r2) = get_nth_bit(value, 2); + let (local r3) = get_nth_bit(value, 3); + let (local r4) = get_nth_bit(value, 4); + let (local r5) = get_nth_bit(value, 5); + let (local r6) = get_nth_bit(value, 6); + let (local r7) = get_nth_bit(value, 7); + assert r0 * 2 ** 0 + r1 * 2 ** 1 + r2 * 2 ** 2 + r3 * 2 ** 3 + r4 * 2 ** 4 + r5 * 2 ** 5 + r6 * 2 ** 6 + r7 * 2 ** 7 = value; + return (); +} @view -func test_set_nth_bit{syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt}(): - alloc_locals - local value = 0 - let (local r0) = set_nth_bit(value, 0) - assert 1 = r0 - let (local r1) = set_nth_bit(r0, 1) - assert 3 = r1 - let (local r2) = set_nth_bit(r1, 2) - assert 7 = r2 - let (local r3) = set_nth_bit(r2, 3) - assert 15 = r3 - let (local r4) = set_nth_bit(r3, 4) - assert 31 = r4 - let (local r5) = set_nth_bit(r4, 5) - assert 63 = r5 - let (local r6) = set_nth_bit(r5, 6) - assert 127 = r6 - let (local r7) = set_nth_bit(r6, 7) - assert 255 = r7 - return () -end +func test_set_nth_bit{syscall_ptr: felt*, bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}() { + alloc_locals; + local value = 0; + let (local r0) = set_nth_bit(value, 0); + assert 1 = r0; + let (local r1) = set_nth_bit(r0, 1); + assert 3 = r1; + let (local r2) = set_nth_bit(r1, 2); + assert 7 = r2; + let (local r3) = set_nth_bit(r2, 3); + assert 15 = r3; + let (local r4) = set_nth_bit(r3, 4); + assert 31 = r4; + let (local r5) = set_nth_bit(r4, 5); + assert 63 = r5; + let (local r6) = set_nth_bit(r5, 6); + assert 127 = r6; + let (local r7) = set_nth_bit(r6, 7); + assert 255 = r7; + return (); +} @view -func test_toggle_nth_bit{ - syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt -}(): - alloc_locals - - local value = nondet %{ int('100000011010111', 2) %} - let (res) = toggle_nth_bit(value, 14) - let (res) = toggle_nth_bit(res, 3) - let (res) = toggle_nth_bit(res, 5) - assert res = 2 ** 8 - 1 - return () -end +func test_toggle_nth_bit{syscall_ptr: felt*, bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}( + ) { + alloc_locals; + + local value = nondet %{ int('100000011010111', 2) %}; + let (res) = toggle_nth_bit(value, 14); + let (res) = toggle_nth_bit(res, 3); + let (res) = toggle_nth_bit(res, 5); + assert res = 2 ** 8 - 1; + return (); +} @view -func test_op_nth_bit{syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt}(): - alloc_locals - local v0 - local v1 - local v2 - local n0 - local n1 - local n2 - local r0 - local r1 - local r2 +func test_op_nth_bit{syscall_ptr: felt*, bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt}() { + alloc_locals; + local v0; + local v1; + local v2; + local n0; + local n1; + local n2; + local r0; + local r1; + local r2; %{ from random import randint size = 249 @@ -144,34 +143,34 @@ func test_op_nth_bit{syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*, range_c ids.r1 = ids.v1 | (1 << ids.n1) ids.r2 = ids.v2 ^ (1 << ids.n2) %} - let (val0) = op_nth_bit('get', v0, n0) - assert r0 = val0 - let (val1) = op_nth_bit('set', v1, n1) - assert r1 = val1 - let (val2) = op_nth_bit('toggle', v2, n2) - assert r2 = val2 + let (val0) = op_nth_bit('get', v0, n0); + assert r0 = val0; + let (val1) = op_nth_bit('set', v1, n1); + assert r1 = val1; + let (val2) = op_nth_bit('toggle', v2, n2); + assert r2 = val2; %{ expect_revert() %} - let (_) = op_nth_bit('rigged', v0, n1) - return () -end + let (_) = op_nth_bit('rigged', v0, n1); + return (); +} @view func test_bitwise_bounds_negative_ko{ - syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt -}(): - alloc_locals + syscall_ptr: felt*, bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt +}() { + alloc_locals; %{ expect_revert(error_message="Bad bitwise bounds") %} - let (res) = op_nth_bit('set', 1337, -42) - return () -end + let (res) = op_nth_bit('set', 1337, -42); + return (); +} @view func test_bitwise_bounds_too_high_ko{ - syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt -}(): - alloc_locals + syscall_ptr: felt*, bitwise_ptr: BitwiseBuiltin*, range_check_ptr: felt +}() { + alloc_locals; %{ expect_revert(error_message="Bad bitwise bounds") %} - let (res) = op_nth_bit('set', 1337, 251) - return () -end + let (res) = op_nth_bit('set', 1337, 251); + return (); +} diff --git a/exercises/hints/hints00.cairo b/exercises/hints/hints00.cairo index 24b17e13..f382fd09 100644 --- a/exercises/hints/hints00.cairo +++ b/exercises/hints/hints00.cairo @@ -1,26 +1,26 @@ %lang starknet -# Hints +// Hints -# Hints are the Cairo way to defer part of the program execution to an external program -# Memory can be accessed and assigned inside a hint by using variables identifiers. -# e.g., inside a hint variable `a` is accessed through `ids.a` +// Hints are the Cairo way to defer part of the program execution to an external program +// Memory can be accessed and assigned inside a hint by using variables identifiers. +// e.g., inside a hint variable `a` is accessed through `ids.a` -# I AM NOT DONE +// I AM NOT DONE -# TODO: Assign the value of `res` inside a hint. +// TODO: Assign the value of `res` inside a hint. -func basic_hint() -> (value : felt): - alloc_locals - local res - # TODO: Insert hint here - return (res) -end +func basic_hint() -> (value: felt) { + alloc_locals; + local res; + // TODO: Insert hint here + return (res,); +} -# Do not change the test +// Do not change the test @external -func test_basic_hint{syscall_ptr : felt*}(): - let (value) = basic_hint() - assert 41 = value - 1 - return () -end +func test_basic_hint{syscall_ptr: felt*}() { + let (value) = basic_hint(); + assert 41 = value - 1; + return (); +} diff --git a/exercises/hints/hints01.cairo b/exercises/hints/hints01.cairo index ea638ab5..d8102735 100644 --- a/exercises/hints/hints01.cairo +++ b/exercises/hints/hints01.cairo @@ -1,36 +1,36 @@ %lang starknet -# Cairo hints can be useful for delegating heavy computation. -# This pattern is at the very heart of Cairo: verification is much faster than computation. -# However, as hints are not part of the final Cairo bytecode, a malicious program may provide wrong results. -# You should always verify computations done inside hints. +// Cairo hints can be useful for delegating heavy computation. +// This pattern is at the very heart of Cairo: verification is much faster than computation. +// However, as hints are not part of the final Cairo bytecode, a malicious program may provide wrong results. +// You should always verify computations done inside hints. -# I AM NOT DONE +// I AM NOT DONE -# TODO: Compute the result of "x modulo n" inside a hint using python's `divmod` -# Don't forget to make sure the result is correct. +// TODO: Compute the result of "x modulo n" inside a hint using python's `divmod` +// Don't forget to make sure the result is correct. -func modulo(x : felt, n : felt) -> (mod : felt): - alloc_locals - local quotient - local remainder +func modulo(x: felt, n: felt) -> (mod: felt) { + alloc_locals; + local quotient; + local remainder; %{ # TODO: Compute the quotient and remainder inside the hint print(ids.quotient) print(ids.remainder) %} - # TODO: verify the result is correct + // TODO: verify the result is correct - return (0) -end + return (0,); +} -# Do not change the test +// Do not change the test @external -func test_modulo{syscall_ptr : felt*}(): - const NUM_TESTS = 19 +func test_modulo{syscall_ptr: felt*}() { + const NUM_TESTS = 19; %{ import random %} - tempvar count = NUM_TESTS + tempvar count = NUM_TESTS; loop: %{ @@ -39,14 +39,14 @@ func test_modulo{syscall_ptr : felt*}(): if x < n: x,n = n,x %} - tempvar x = nondet %{ x %} - tempvar n = nondet %{ n %} - tempvar res = nondet %{ x % n %} + tempvar x = nondet %{ x %}; + tempvar n = nondet %{ n %}; + tempvar res = nondet %{ x % n %}; - let (mod) = modulo(x, n) - assert res = mod - tempvar count = count - 1 - jmp loop if count != 0 + let (mod) = modulo(x, n); + assert res = mod; + tempvar count = count - 1; + jmp loop if count != 0; - return () -end + return (); +} diff --git a/exercises/implicit_arguments/implicit_arguments01.cairo b/exercises/implicit_arguments/implicit_arguments01.cairo index ca971793..e021414d 100644 --- a/exercises/implicit_arguments/implicit_arguments01.cairo +++ b/exercises/implicit_arguments/implicit_arguments01.cairo @@ -1,23 +1,23 @@ %lang starknet -# Functions can take implicit arguments. You might have already encountered this with -# syscall_ptr: felt* for example. +// Functions can take implicit arguments. You might have already encountered this with +// syscall_ptr: felt* for example. -# I AM NOT DONE +// I AM NOT DONE -# TODO: fix the "implicit_sum" signature to make the test pass +// TODO: fix the "implicit_sum" signature to make the test pass -func implicit_sum() -> (result : felt): - return (a + b) -end +func implicit_sum() -> (result: felt) { + return (a + b,); +} -# Do not change the test +// Do not change the test @external -func test_sum{syscall_ptr : felt*}(): - let a = 3 - let b = 5 - let (sum) = implicit_sum{a=a, b=b}() - assert sum = 8 +func test_sum{syscall_ptr: felt*}() { + let a = 3; + let b = 5; + let (sum) = implicit_sum{a=a, b=b}(); + assert sum = 8; - return () -end + return (); +} diff --git a/exercises/implicit_arguments/implicit_arguments02.cairo b/exercises/implicit_arguments/implicit_arguments02.cairo index 9c2062d6..4f0a7e33 100644 --- a/exercises/implicit_arguments/implicit_arguments02.cairo +++ b/exercises/implicit_arguments/implicit_arguments02.cairo @@ -1,39 +1,39 @@ %lang starknet -# Implicit arguments are passed down to any subsequent function calls that would require them. -# Make good usage of this feature to pass this exercise! +// Implicit arguments are passed down to any subsequent function calls that would require them. +// Make good usage of this feature to pass this exercise! -# I AM NOT DONE +// I AM NOT DONE -# TODO: fix the "child_function_1" and "child_function_2" signatures to make the test pass +// TODO: fix the "child_function_1" and "child_function_2" signatures to make the test pass -# Do not change the function signature -func parent_function{a, b}() -> (result : felt): - # Do not change the function body - alloc_locals - let (local intermediate_result_1) = child_function_1() - let (local intermediate_result_2) = child_function_2() - return (intermediate_result_1 + intermediate_result_2) -end +// Do not change the function signature +func parent_function{a, b}() -> (result: felt) { + // Do not change the function body + alloc_locals; + let (local intermediate_result_1) = child_function_1(); + let (local intermediate_result_2) = child_function_2(); + return (intermediate_result_1 + intermediate_result_2,); +} -func child_function_1() -> (result : felt): - # Do not change the function body - return (2 * a) -end +func child_function_1() -> (result: felt) { + // Do not change the function body + return (2 * a,); +} -func child_function_2() -> (result : felt): - # Do not change the function body - return (b + 3) -end +func child_function_2() -> (result: felt) { + // Do not change the function body + return (b + 3,); +} @external -func test_sum{syscall_ptr : felt*}(): - let a = 3 - let b = 5 - with a, b: - let (result) = parent_function() - assert result = 14 - end - - return () -end +func test_sum{syscall_ptr: felt*}() { + let a = 3; + let b = 5; + with a, b { + let (result) = parent_function(); + assert result = 14; + } + + return (); +} diff --git a/exercises/implicit_arguments/implicit_arguments03.cairo b/exercises/implicit_arguments/implicit_arguments03.cairo index 93629ad3..4de71227 100644 --- a/exercises/implicit_arguments/implicit_arguments03.cairo +++ b/exercises/implicit_arguments/implicit_arguments03.cairo @@ -1,27 +1,27 @@ %lang starknet -# What is really neat with implicit arguments is that they are returned implicitly by any function using them -# This is a very powerful feature of the language since it helps with readability, letting the developer omit -# implicit arguments in the subsequent function calls. +// What is really neat with implicit arguments is that they are returned implicitly by any function using them +// This is a very powerful feature of the language since it helps with readability, letting the developer omit +// implicit arguments in the subsequent function calls. -# I AM NOT DONE +// I AM NOT DONE -# TODO: implement the "black_box" function body to make the test pass +// TODO: implement the "black_box" function body to make the test pass -# Do not change the function signature! -func black_box{secret : felt}() -> (): - # Make the magic happen here :) - return () -end +// Do not change the function signature! +func black_box{secret: felt}() -> () { + // Make the magic happen here :) + return (); +} -# Do not change the test +// Do not change the test @external -func test_secret_change{syscall_ptr : felt*}(): - let secret = 'no so secret' - with secret: - black_box() - assert secret = 'very secret!' - end +func test_secret_change{syscall_ptr: felt*}() { + let secret = 'no so secret'; + with secret { + black_box(); + assert secret = 'very secret!'; + } - return () -end + return (); +} diff --git a/exercises/operations/operations00.cairo b/exercises/operations/operations00.cairo index 49c16996..1d02c231 100644 --- a/exercises/operations/operations00.cairo +++ b/exercises/operations/operations00.cairo @@ -1,23 +1,23 @@ %lang starknet -# Felts supports basic math operations. -# Only accepted operators (const excluded) are: +, -, * and / +// Felts supports basic math operations. +// Only accepted operators (const excluded) are: +, -, * and / -# I AM NOT DONE +// I AM NOT DONE -# TODO -# Return the solution of (x² + x - 2) / (x - 2) -func poly(x : felt) -> (res : felt): - # FILL ME - return (res=res) # Do not change -end +// TODO +// Return the solution of (x² + x - 2) / (x - 2) +func poly(x: felt) -> (res: felt) { + // FILL ME + return (res=res); // Do not change +} -# Do not change the test +// Do not change the test @external -func test_poly(): - let (res) = poly(x=1) - assert res = 0 - let (res) = poly(x=3) - assert res = 10 - return () -end +func test_poly() { + let (res) = poly(x=1); + assert res = 0; + let (res) = poly(x=3); + assert res = 10; + return (); +} diff --git a/exercises/operations/operations01.cairo b/exercises/operations/operations01.cairo index ff6131d8..87e911f0 100644 --- a/exercises/operations/operations01.cairo +++ b/exercises/operations/operations01.cairo @@ -1,27 +1,27 @@ %lang starknet -# Felts are integers defined in the range [0 ; P[, all compuations are done modulo P. -# They can be unsigned integers using `let` or signed integers using `const`. -# Exercice resources: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements +// Felts are integers defined in the range [0 ; P[, all compuations are done modulo P. +// They can be unsigned integers using `let` or signed integers using `const`. +// Exercice resources: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements -# I AM NOT DONE +// I AM NOT DONE -# TODO -# Compute a number X which verify X + 1 < X using unsigned int +// TODO +// Compute a number X which verify X + 1 < X using unsigned int @external -func test_unsigned_integer(): - # FILL ME - let z = x + 1 +func test_unsigned_integer() { + // FILL ME + let z = x + 1; %{ assert ids.z < ids.x, f'assert failed: {ids.z} >= {ids.x}' %} - return () -end + return (); +} -# TODO -# Compute a number Y which verify Y + 1 < Y using signed int +// TODO +// Compute a number Y which verify Y + 1 < Y using signed int @external -func test_signed_integer(): - # FILL ME - const z = y + 1 +func test_signed_integer() { + // FILL ME + const z = y + 1; %{ assert ids.z < ids.y, f'assert failed: {ids.z} >= {ids.y}' %} - return () -end + return (); +} diff --git a/exercises/operations/operations02.cairo b/exercises/operations/operations02.cairo index a91060f0..117c08ad 100644 --- a/exercises/operations/operations02.cairo +++ b/exercises/operations/operations02.cairo @@ -2,26 +2,26 @@ from starkware.cairo.common.math import assert_lt_felt, assert_not_zero -# Felts use prime number property to ensure (x / y) * y = x is always true. -# Since floats are not supported, this can lead to get surprising results. -# Exercice resources: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements +// Felts use prime number property to ensure (x / y) * y = x is always true. +// Since floats are not supported, this can lead to get surprising results. +// Exercice resources: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements -# I AM NOT DONE +// I AM NOT DONE -# TODO -# Find a number X which satisfy A / X > A with X in range ]0 ; 100] -func solve(a : felt) -> (x : felt): - # TO FILL - return (x=x) -end +// TODO +// Find a number X which satisfy A / X > A with X in range ]0 ; 100] +func solve(a: felt) -> (x: felt) { + // TO FILL + return (x=x); +} -# Do not change the test +// Do not change the test @external -func test_solve{range_check_ptr}(): - let a = 347092984475551631116800 - let (x) = solve(a=a) - assert_not_zero(x) - assert_lt_felt(x, 101) - assert_lt_felt(a, a / x) - return () -end +func test_solve{range_check_ptr}() { + let a = 347092984475551631116800; + let (x) = solve(a=a); + assert_not_zero(x); + assert_lt_felt(x, 101); + assert_lt_felt(a, a / x); + return (); +} diff --git a/exercises/operations/operations03.cairo b/exercises/operations/operations03.cairo index e19481ec..ef51e0eb 100644 --- a/exercises/operations/operations03.cairo +++ b/exercises/operations/operations03.cairo @@ -2,24 +2,24 @@ from starkware.cairo.common.math import assert_lt_felt -# Felts use prime number property to ensure (x / y) * y = x is always true. -# Even if `let` provide an unsigned integer, it is still possible to manage negative numbers thanks to field element properties. -# Exercice resources: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements +// Felts use prime number property to ensure (x / y) * y = x is always true. +// Even if `let` provide an unsigned integer, it is still possible to manage negative numbers thanks to field element properties. +// Exercice resources: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements -# I AM NOT DONE +// I AM NOT DONE -# TODO -# Set the value of x (in the hint) to verify the test -func solve() -> (x : felt): - tempvar x - %{ ids.x = -1 %} # Change only this line to make the test pass - return (x=x) -end +// TODO +// Set the value of x (in the hint) to verify the test +func solve() -> (x: felt) { + tempvar x; + %{ ids.x = -1 %} // Change only this line to make the test pass + return (x=x); +} -# Do not change the test +// Do not change the test @external -func test_solve{range_check_ptr}(): - let (x) = solve() - assert x = -17 - return () -end +func test_solve{range_check_ptr}() { + let (x) = solve(); + assert x = -17; + return (); +} diff --git a/exercises/recursions/array01.cairo b/exercises/recursions/array01.cairo index 44cb04fa..b89dc0e0 100644 --- a/exercises/recursions/array01.cairo +++ b/exercises/recursions/array01.cairo @@ -1,33 +1,33 @@ %lang starknet -# Arrays can be passed as function arguments in the form of a pointer and a length. +// Arrays can be passed as function arguments in the form of a pointer and a length. -# I AM NOT DONE +// I AM NOT DONE -# TODO: write the "contains" function body that returns 1 if the haystack contains the needle and 0 otherwise. +// TODO: write the "contains" function body that returns 1 if the haystack contains the needle and 0 otherwise. from starkware.cairo.common.alloc import alloc -func contains(needle : felt, haystack : felt*, haystack_len : felt) -> (result : felt): - return (0) -end +func contains(needle: felt, haystack: felt*, haystack_len: felt) -> (result: felt) { + return (0,); +} -# Do not change the test +// Do not change the test @external -func test_contains{syscall_ptr : felt*}(): - let (haystack1 : felt*) = alloc() - assert [haystack1] = 1 - assert [haystack1 + 1] = 2 - assert [haystack1 + 2] = 3 - assert [haystack1 + 3] = 4 - - let (contains3) = contains(3, haystack1, 4) - assert contains3 = 1 - - let (haystack2 : felt*) = alloc() - assert [haystack2] = 1 - assert [haystack2 + 1] = 2 - let (contains5) = contains(5, haystack2, 2) - assert contains5 = 0 - return () -end +func test_contains{syscall_ptr: felt*}() { + let (haystack1: felt*) = alloc(); + assert [haystack1] = 1; + assert [haystack1 + 1] = 2; + assert [haystack1 + 2] = 3; + assert [haystack1 + 3] = 4; + + let (contains3) = contains(3, haystack1, 4); + assert contains3 = 1; + + let (haystack2: felt*) = alloc(); + assert [haystack2] = 1; + assert [haystack2 + 1] = 2; + let (contains5) = contains(5, haystack2, 2); + assert contains5 = 0; + return (); +} diff --git a/exercises/recursions/array02.cairo b/exercises/recursions/array02.cairo index de33f4a7..d4ccee24 100644 --- a/exercises/recursions/array02.cairo +++ b/exercises/recursions/array02.cairo @@ -1,44 +1,44 @@ %lang starknet -# Getting pointer as function arguments let us modify the values at the memory address of the pointer -# ...or not! Cairo memory is immutable. Therefore you cannot just update a memory cell. +// Getting pointer as function arguments let us modify the values at the memory address of the pointer +// ...or not! Cairo memory is immutable. Therefore you cannot just update a memory cell. -# I AM NOT DONE +// I AM NOT DONE -# TODO: Update the square function – you can change the body and the signature – -# to make it achieve the desired result: returning an array -# with the squared values of the input array. +// TODO: Update the square function – you can change the body and the signature – +// to make it achieve the desired result: returning an array +// with the squared values of the input array. from starkware.cairo.common.alloc import alloc -func square(array : felt*, array_len : felt): - if array_len == 0: - return () - end +func square(array: felt*, array_len: felt) { + if (array_len == 0) { + return (); + } - let squared_item = array[0] * array[0] - assert [array] = squared_item + let squared_item = array[0] * array[0]; + assert [array] = squared_item; - return square(array + 1, array_len - 1) -end + return square(array + 1, array_len - 1); +} -# You can update the test if the function signature changes. +// You can update the test if the function signature changes. @external -func test_square{syscall_ptr : felt*}(): - alloc_locals - let (local array : felt*) = alloc() +func test_square{syscall_ptr: felt*}() { + alloc_locals; + let (local array: felt*) = alloc(); - assert [array] = 1 - assert [array + 1] = 2 - assert [array + 2] = 3 - assert [array + 3] = 4 + assert [array] = 1; + assert [array + 1] = 2; + assert [array + 2] = 3; + assert [array + 3] = 4; - square(array, 4) + square(array, 4); - assert [array] = 1 - assert [array + 1] = 4 - assert [array + 2] = 9 - assert [array + 3] = 16 + assert [array] = 1; + assert [array + 1] = 4; + assert [array + 2] = 9; + assert [array + 3] = 16; - return () -end + return (); +} diff --git a/exercises/recursions/array03.cairo b/exercises/recursions/array03.cairo index 6cdd009c..539cad0e 100644 --- a/exercises/recursions/array03.cairo +++ b/exercises/recursions/array03.cairo @@ -1,110 +1,110 @@ %lang starknet -# There are multiple ways to scan through an array. -# Using recursion, one could go forwards or backwards. +// There are multiple ways to scan through an array. +// Using recursion, one could go forwards or backwards. -# I AM NOT DONE +// I AM NOT DONE from starkware.cairo.common.math_cmp import is_le from starkware.cairo.common.alloc import alloc -# TODO -# Scan through the array elements from first to last -# Return 1 if elements of the array are in increasing order. -# Return 0 otherwise +// TODO +// Scan through the array elements from first to last +// Return 1 if elements of the array are in increasing order. +// Return 0 otherwise -func is_increasing{range_check_ptr : felt}(array : felt*, array_len : felt) -> (res : felt): - if array_len == 0: - return (1) - end +func is_increasing{range_check_ptr: felt}(array: felt*, array_len: felt) -> (res: felt) { + if (array_len == 0) { + return (1,); + } - if array_len == 1: - return (1) - end + if (array_len == 1) { + return (1,); + } - let curr_value = 0 - let next_value = 0 + let curr_value = 0; + let next_value = 0; - # Do not modify these lines - let (is_sorted) = is_le(curr_value, next_value) - if is_sorted == 1: - return is_increasing(array + 1, array_len - 1) - end + // Do not modify these lines + let is_sorted = is_le(curr_value, next_value); + if (is_sorted == 1) { + return is_increasing(array + 1, array_len - 1); + } - return (0) -end + return (0,); +} -# TODO -# Scan through the array elements from last to first -# Return 1 if elements of the array are in decreasing order. -# Return 0 otherwise +// TODO +// Scan through the array elements from last to first +// Return 1 if elements of the array are in decreasing order. +// Return 0 otherwise -func is_decreasing{range_check_ptr : felt}(array : felt*, array_len : felt) -> (res : felt): - # FILL ME +func is_decreasing{range_check_ptr: felt}(array: felt*, array_len: felt) -> (res: felt) { + // FILL ME - # Do not modify this line - let (is_sorted) = is_le(curr_value, next_value) + // Do not modify this line + let is_sorted = is_le(curr_value, next_value); - if is_sorted == 1: - return is_decreasing(array, array_len) - end + if (is_sorted == 1) { + return is_decreasing(array, array_len); + } - return (0) -end + return (0,); +} -# TODO -# Use recursion to reverse array in rev_array -# Assume rev_array is already allocated +// TODO +// Use recursion to reverse array in rev_array +// Assume rev_array is already allocated -func reverse(array : felt*, rev_array : felt*, array_len : felt): - # FILL ME - return () -end +func reverse(array: felt*, rev_array: felt*, array_len: felt) { + // FILL ME + return (); +} -# Do not modify the test +// Do not modify the test @external -func test_is_sorted{syscall_ptr : felt*, range_check_ptr : felt}(): - alloc_locals - - local inc_array : felt* = new (1, 2, 3, 4) - local bad_array : felt* = new (1, 2, 69, -11, 0) - local dec_array : felt* = new (10, 9, 8, 7, 6, 5) - let (inc0) = is_increasing(inc_array, 4) - let (inc1) = is_increasing(bad_array, 5) - let (inc2) = is_increasing(dec_array, 6) - assert (inc0, inc1, inc2) = (1, 0, 0) - - let (dec0) = is_decreasing(inc_array, 4) - let (dec1) = is_decreasing(bad_array, 5) - let (dec2) = is_decreasing(dec_array, 6) - assert (dec0, dec1, dec2) = (0, 0, 1) - - return () -end - -# Do not modify the test +func test_is_sorted{syscall_ptr: felt*, range_check_ptr: felt}() { + alloc_locals; + + local inc_array: felt* = new (1, 2, 3, 4); + local bad_array: felt* = new (1, 2, 69, -11, 0); + local dec_array: felt* = new (10, 9, 8, 7, 6, 5); + let (inc0) = is_increasing(inc_array, 4); + let (inc1) = is_increasing(bad_array, 5); + let (inc2) = is_increasing(dec_array, 6); + assert (inc0, inc1, inc2) = (1, 0, 0); + + let (dec0) = is_decreasing(inc_array, 4); + let (dec1) = is_decreasing(bad_array, 5); + let (dec2) = is_decreasing(dec_array, 6); + assert (dec0, dec1, dec2) = (0, 0, 1); + + return (); +} + +// Do not modify the test @external -func test_reversed{syscall_ptr : felt*}(): - alloc_locals - - local in_array : felt* = new (1, 2, 3, 4, 19, 42) - let (reversed_array : felt*) = alloc() - reverse(in_array, reversed_array, 6) - assert 42 = [reversed_array + 0] - assert 19 = [reversed_array + 1] - assert 4 = [reversed_array + 2] - assert 3 = [reversed_array + 3] - assert 2 = [reversed_array + 4] - assert 1 = [reversed_array + 5] - - local in_array : felt* = new (31337, 1664, 911, 0, -42) - let (reversed_array : felt*) = alloc() - reverse(in_array, reversed_array, 5) - assert -42 = [reversed_array + 0] - assert 0 = [reversed_array + 1] - assert 911 = [reversed_array + 2] - assert 1664 = [reversed_array + 3] - assert 31337 = [reversed_array + 4] - - return () -end +func test_reversed{syscall_ptr: felt*}() { + alloc_locals; + + local in_array: felt* = new (1, 2, 3, 4, 19, 42); + let (reversed_array: felt*) = alloc(); + reverse(in_array, reversed_array, 6); + assert 42 = [reversed_array + 0]; + assert 19 = [reversed_array + 1]; + assert 4 = [reversed_array + 2]; + assert 3 = [reversed_array + 3]; + assert 2 = [reversed_array + 4]; + assert 1 = [reversed_array + 5]; + + local in_array: felt* = new (31337, 1664, 911, 0, -42); + let (reversed_array: felt*) = alloc(); + reverse(in_array, reversed_array, 5); + assert -42 = [reversed_array + 0]; + assert 0 = [reversed_array + 1]; + assert 911 = [reversed_array + 2]; + assert 1664 = [reversed_array + 3]; + assert 31337 = [reversed_array + 4]; + + return (); +} diff --git a/exercises/recursions/array04.cairo b/exercises/recursions/array04.cairo index 80fdc31b..66ff5ef5 100644 --- a/exercises/recursions/array04.cairo +++ b/exercises/recursions/array04.cairo @@ -1,42 +1,42 @@ %lang starknet -# Arrays can also contain structs +// Arrays can also contain structs -# I AM NOT DONE +// I AM NOT DONE -struct Point: - member x : felt - member y : felt - member z : felt -end +struct Point { + x: felt, + y: felt, + z: felt, +} -func contains_origin{range_check_ptr : felt}(len_points : felt, points : Point*) -> (bool : felt): - # FILL ME -end +func contains_origin{range_check_ptr: felt}(len_points: felt, points: Point*) -> (bool: felt) { + // FILL ME +} -# TESTS # +// TESTS # from starkware.cairo.common.alloc import alloc @external -func test_contrains_origin{range_check_ptr : felt}(): - alloc_locals +func test_contrains_origin{range_check_ptr: felt}() { + alloc_locals; - let (local false_array : Point*) = alloc() - assert false_array[0] = Point(1, 2, 3) - assert false_array[1] = Point(2, 2, 2) - assert false_array[2] = Point(42, 27, 11) + let (local false_array: Point*) = alloc(); + assert false_array[0] = Point(1, 2, 3); + assert false_array[1] = Point(2, 2, 2); + assert false_array[2] = Point(42, 27, 11); - let (res) = contains_origin(3, false_array) - assert res = 0 + let (res) = contains_origin(3, false_array); + assert res = 0; - let (local true_array : Point*) = alloc() - assert true_array[0] = Point(1, 2, 3) - assert true_array[1] = Point(0, 0, 0) - assert true_array[2] = Point(42, 27, 11) + let (local true_array: Point*) = alloc(); + assert true_array[0] = Point(1, 2, 3); + assert true_array[1] = Point(0, 0, 0); + assert true_array[2] = Point(42, 27, 11); - let (res) = contains_origin(3, true_array) - assert res = 1 + let (res) = contains_origin(3, true_array); + assert res = 1; - return () -end + return (); +} diff --git a/exercises/recursions/collatz_sequence.cairo b/exercises/recursions/collatz_sequence.cairo index 642633e2..e1b4b9be 100644 --- a/exercises/recursions/collatz_sequence.cairo +++ b/exercises/recursions/collatz_sequence.cairo @@ -4,45 +4,45 @@ from starkware.cairo.common.bitwise import bitwise_and from starkware.cairo.common.cairo_builtins import BitwiseBuiltin -# Collatz sequence are defined as follow : -# If the number is even, divide it by two. -# If the number is odd, triple it and add one. -# If the number is one, stop the computation -# https://en.wikipedia.org/wiki/Collatz_conjecture +// Collatz sequence are defined as follow : +// If the number is even, divide it by two. +// If the number is odd, triple it and add one. +// If the number is one, stop the computation +// https://en.wikipedia.org/wiki/Collatz_conjecture -# I AM NOT DONE +// I AM NOT DONE -# TODO: write a recursive implementation of Collatz sequence that returns the nth collatz number from the seed -# HELP: number % 2 == 0 => bitwise_and(number, 1) == 0 +// TODO: write a recursive implementation of Collatz sequence that returns the nth collatz number from the seed +// HELP: number % 2 == 0 => bitwise_and(number, 1) == 0 -func collatz{bitwise_ptr : BitwiseBuiltin*}(seed : felt, step : felt) -> (result : felt): - return (result=number) -end +func collatz{bitwise_ptr: BitwiseBuiltin*}(seed: felt, step: felt) -> (result: felt) { + return (result=number); +} -# Do not change the test +// Do not change the test @external -func test_collatz{syscall_ptr : felt*, bitwise_ptr : BitwiseBuiltin*}(): - let (n) = collatz(seed=42, step=0) - assert n = 42 - let (n) = collatz(seed=42, step=1) - assert n = 21 - let (n) = collatz(seed=42, step=2) - assert n = 64 - let (n) = collatz(seed=42, step=3) - assert n = 32 - let (n) = collatz(seed=42, step=4) - assert n = 16 - let (n) = collatz(seed=42, step=5) - assert n = 8 - let (n) = collatz(seed=42, step=6) - assert n = 4 - let (n) = collatz(seed=42, step=7) - assert n = 2 - let (n) = collatz(seed=42, step=8) - assert n = 1 - let (n) = collatz(seed=42, step=9) - assert n = 1 - let (n) = collatz(seed=42, step=42) - assert n = 1 - return () -end +func test_collatz{syscall_ptr: felt*, bitwise_ptr: BitwiseBuiltin*}() { + let (n) = collatz(seed=42, step=0); + assert n = 42; + let (n) = collatz(seed=42, step=1); + assert n = 21; + let (n) = collatz(seed=42, step=2); + assert n = 64; + let (n) = collatz(seed=42, step=3); + assert n = 32; + let (n) = collatz(seed=42, step=4); + assert n = 16; + let (n) = collatz(seed=42, step=5); + assert n = 8; + let (n) = collatz(seed=42, step=6); + assert n = 4; + let (n) = collatz(seed=42, step=7); + assert n = 2; + let (n) = collatz(seed=42, step=8); + assert n = 1; + let (n) = collatz(seed=42, step=9); + assert n = 1; + let (n) = collatz(seed=42, step=42); + assert n = 1; + return (); +} diff --git a/exercises/recursions/recursion01.cairo b/exercises/recursions/recursion01.cairo index 811b7a9f..361c6bc5 100644 --- a/exercises/recursions/recursion01.cairo +++ b/exercises/recursions/recursion01.cairo @@ -1,28 +1,28 @@ %lang starknet -# Fibonacci numbers are defined by the following recurrence: -# F(0) = 0 -# F(1) = 1 -# F(n) = F(n-1) + F(n-2) +// Fibonacci numbers are defined by the following recurrence: +// F(0) = 0 +// F(1) = 1 +// F(n) = F(n-1) + F(n-2) -# I AM NOT DONE +// I AM NOT DONE -# TODO: write a recursive implementation of fibonacci numbers that returns the nth fibonacci number +// TODO: write a recursive implementation of fibonacci numbers that returns the nth fibonacci number -func fibonacci(n : felt) -> (result : felt): - return (0) -end +func fibonacci(n: felt) -> (result: felt) { + return (0,); +} -# Do not change the test +// Do not change the test @external -func test_fibonacci{syscall_ptr : felt*}(): - let (n) = fibonacci(0) - assert n = 0 - let (n) = fibonacci(1) - assert n = 1 - let (n) = fibonacci(7) - assert n = 13 - let (n) = fibonacci(10) - assert n = 55 - return () -end +func test_fibonacci{syscall_ptr: felt*}() { + let (n) = fibonacci(0); + assert n = 0; + let (n) = fibonacci(1); + assert n = 1; + let (n) = fibonacci(7); + assert n = 13; + let (n) = fibonacci(10); + assert n = 55; + return (); +} diff --git a/exercises/recursions/struct01.cairo b/exercises/recursions/struct01.cairo index c295c9af..854592a1 100644 --- a/exercises/recursions/struct01.cairo +++ b/exercises/recursions/struct01.cairo @@ -1,46 +1,46 @@ %lang starknet -# Structs are nothing more than a continuous list of felts in memory. So are arrays. -# -# In other words, a felt* can point to an element of an array, but also -# to an element of a struct. It is therefore possible to access the next element of a -# struct by incrementing the pointer, just like with arrays. -# -# It is also worth noting that a struct pointer implicitely casts to a felt pointer -# (eg. Foo* is automatically casted to felt*) - -# I AM NOT DONE - -struct Vector2D: - member x : felt - member y : felt -end - -struct Vector3D: - member x : felt - member y : felt - member z : felt -end - -# Returns the squared magnitude of a vector. -# Examples: -# - the squared magnitude of a 2D vector (x,y) is x * x + y * y. -# - the squared magnitude of a 3D vector (x,y,z) is x * x + y * y + z * z. -func squared_magnitude(struct_value : felt*, struct_size : felt) -> (res : felt): - # FILL ME -end - -# TESTS # +// Structs are nothing more than a continuous list of felts in memory. So are arrays. +// +// In other words, a felt* can point to an element of an array, but also +// to an element of a struct. It is therefore possible to access the next element of a +// struct by incrementing the pointer, just like with arrays. +// +// It is also worth noting that a struct pointer implicitely casts to a felt pointer +// (eg. Foo* is automatically casted to felt*) + +// I AM NOT DONE + +struct Vector2D { + x: felt, + y: felt, +} + +struct Vector3D { + x: felt, + y: felt, + z: felt, +} + +// Returns the squared magnitude of a vector. +// Examples: +// - the squared magnitude of a 2D vector (x,y) is x * x + y * y. +// - the squared magnitude of a 3D vector (x,y,z) is x * x + y * y + z * z. +func squared_magnitude(struct_value: felt*, struct_size: felt) -> (res: felt) { + // FILL ME +} + +// TESTS # @external -func test_squared_magnitude{range_check_ptr : felt}(): - tempvar vector2D : Vector2D* = new Vector2D(x=4, y=7) - let (res) = squared_magnitude(vector2D, Vector2D.SIZE) - assert res = 4 * 4 + 7 * 7 +func test_squared_magnitude{range_check_ptr: felt}() { + tempvar vector2D: Vector2D* = new Vector2D(x=4, y=7); + let (res) = squared_magnitude(vector2D, Vector2D.SIZE); + assert res = 4 * 4 + 7 * 7; - tempvar vector3D : Vector3D* = new Vector3D(x=8, y=2, z=1) - let (res) = squared_magnitude(vector3D, Vector3D.SIZE) - assert res = 8 * 8 + 2 * 2 + 1 * 1 + tempvar vector3D: Vector3D* = new Vector3D(x=8, y=2, z=1); + let (res) = squared_magnitude(vector3D, Vector3D.SIZE); + assert res = 8 * 8 + 2 * 2 + 1 * 1; - return () -end + return (); +} diff --git a/exercises/registers/registers00.cairo b/exercises/registers/registers00.cairo index ac078bce..96d3401d 100644 --- a/exercises/registers/registers00.cairo +++ b/exercises/registers/registers00.cairo @@ -1,43 +1,43 @@ %lang starknet -# I AM NOT DONE +// I AM NOT DONE -# Ressources -# https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#registers -# https://www.cairo-lang.org/docs/how_cairo_works/functions.html#function-arguments-and-return-values +// Ressources +// https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#registers +// https://www.cairo-lang.org/docs/how_cairo_works/functions.html#function-arguments-and-return-values -# TODO -# Rewrite this function body in a high level syntax +// TODO +// Rewrite this function body in a high level syntax @external -func ret_42() -> (r : felt): - # [ap] = 42; ap++ - # ret -end +func ret_42() -> (r: felt) { + // [ap] = 42; ap++ + // ret +} -# TODO -# Rewrite this function body in a low level syntax, using registers +// TODO +// Rewrite this function body in a low level syntax, using registers @external -func ret_0_and_1() -> (zero : felt, one : felt): - # return (0, 1) -end +func ret_0_and_1() -> (zero: felt, one: felt) { + // return (0, 1) +} -######### -# TESTS # -######### +//######## +// TESTS # +//######## @external -func test_ret_42(): - let (r) = ret_42() - assert r = 42 +func test_ret_42() { + let (r) = ret_42(); + assert r = 42; - return () -end + return (); +} @external -func test_0_and_1(): - let (zero, one) = ret_0_and_1() - assert zero = 0 - assert one = 1 +func test_0_and_1() { + let (zero, one) = ret_0_and_1(); + assert zero = 0; + assert one = 1; - return () -end + return (); +} diff --git a/exercises/registers/registers01.cairo b/exercises/registers/registers01.cairo index 222c1ed4..6af4113a 100644 --- a/exercises/registers/registers01.cairo +++ b/exercises/registers/registers01.cairo @@ -1,45 +1,45 @@ %lang starknet -# I AM NOT DONE +// I AM NOT DONE -# Resource -# https://www.cairo-lang.org/docs/how_cairo_works/functions.html#function-arguments-and-return-values +// Resource +// https://www.cairo-lang.org/docs/how_cairo_works/functions.html#function-arguments-and-return-values -# TODO -# Rewrite this function with a high level syntax +// TODO +// Rewrite this function with a high level syntax @external -func assert_is_42(n : felt): - # [ap - 3] = 42 - # ret -end +func assert_is_42(n: felt) { + // [ap - 3] = 42 + // ret +} -# TODO -# Rewrite this function with a low level syntax, using registers +// TODO +// Rewrite this function with a low level syntax, using registers @external -func sum(a : felt, b : felt) -> (s : felt): - # return (a + b) -end +func sum(a: felt, b: felt) -> (s: felt) { + // return (a + b) +} -######### -# TESTS # -######### +//######## +// TESTS # +//######## @external -func test_assert_is_42_ok(): - assert_is_42(42) - return () -end +func test_assert_is_42_ok() { + assert_is_42(42); + return (); +} @external -func test_assert_is_42_ko(): +func test_assert_is_42_ko() { %{ expect_revert() %} - assert_is_42(21) - return () -end + assert_is_42(21); + return (); +} @external -func test_sum(): - let (s) = sum(2, 3) - assert s = 5 - return () -end +func test_sum() { + let (s) = sum(2, 3); + assert s = 5; + return (); +} diff --git a/exercises/registers/registers02.cairo b/exercises/registers/registers02.cairo index ee74d6e0..631da3dd 100644 --- a/exercises/registers/registers02.cairo +++ b/exercises/registers/registers02.cairo @@ -1,131 +1,131 @@ %lang starknet -# I AM NOT DONE - -# Cairo memory is immutable. -# Once a memory cell has been assigned, its value CANNOT be changed. -# The program will crash if someone tries to assign a new, different, value to an already initialized memory cell. -# However, trying to assign a memory cell twice, or more, **with the same value** won't cause any harm. -# This property can be used to assert the value of a cell. - -# TODO -# Rewrite this function in a high level syntax, using tempvar and assert -func crash(): - # [ap] = 42; ap++ - # [ap - 1] = 42 - # [ap - 1] = 21 - - ret -end - -# TODO -# Rewrite this funtion in a low level syntax -func assert_42(number : felt): - # assert number = 42 - - return () -end - -# TODO -# Write this function body so: -# if the memory cell pointed by `p_number` is not initialized, set it to 42 -# else, if the value is initialized and different from 42, crash -# else, do nothing and return -func assert_pointer_42(p_number : felt*): - return () -end - -# TODO -# Write this function body so: -# if the memory cell pointed by `p_number` is set to 42, do nothing and return -# else crash -func assert_pointer_42_no_set(p_number : felt*): - return () -end - -######### -# TESTS # -######### +// I AM NOT DONE + +// Cairo memory is immutable. +// Once a memory cell has been assigned, its value CANNOT be changed. +// The program will crash if someone tries to assign a new, different, value to an already initialized memory cell. +// However, trying to assign a memory cell twice, or more, **with the same value** won't cause any harm. +// This property can be used to assert the value of a cell. + +// TODO +// Rewrite this function in a high level syntax, using tempvar and assert +func crash() { + // [ap] = 42; ap++ + // [ap - 1] = 42 + // [ap - 1] = 21 + + ret; +} + +// TODO +// Rewrite this funtion in a low level syntax +func assert_42(number: felt) { + // assert number = 42 + + return (); +} + +// TODO +// Write this function body so: +// if the memory cell pointed by `p_number` is not initialized, set it to 42 +// else, if the value is initialized and different from 42, crash +// else, do nothing and return +func assert_pointer_42(p_number: felt*) { + return (); +} + +// TODO +// Write this function body so: +// if the memory cell pointed by `p_number` is set to 42, do nothing and return +// else crash +func assert_pointer_42_no_set(p_number: felt*) { + return (); +} + +//######## +// TESTS # +//######## from starkware.cairo.common.alloc import alloc @external -func test_crash(): +func test_crash() { %{ expect_revert() %} - crash() + crash(); - return () -end + return (); +} @external -func test_assert_42(): - assert_42(42) +func test_assert_42() { + assert_42(42); %{ expect_revert() %} - assert_42(21) + assert_42(21); - return () -end + return (); +} @external -func test_assert_pointer_42_initialized(): - let (mem_zone : felt*) = alloc() - assert mem_zone[0] = 42 - assert mem_zone[1] = 21 +func test_assert_pointer_42_initialized() { + let (mem_zone: felt*) = alloc(); + assert mem_zone[0] = 42; + assert mem_zone[1] = 21; - assert_pointer_42(mem_zone) + assert_pointer_42(mem_zone); %{ expect_revert() %} - assert_pointer_42(mem_zone + 1) + assert_pointer_42(mem_zone + 1); - return () -end + return (); +} @external -func test_assert_pointer_42_not_initialized_ok(): - let (mem_zone : felt*) = alloc() - assert mem_zone[0] = 42 - assert_pointer_42(mem_zone) +func test_assert_pointer_42_not_initialized_ok() { + let (mem_zone: felt*) = alloc(); + assert mem_zone[0] = 42; + assert_pointer_42(mem_zone); - assert_pointer_42(mem_zone + 1) - assert mem_zone[1] = 42 + assert_pointer_42(mem_zone + 1); + assert mem_zone[1] = 42; - return () -end + return (); +} @external -func test_assert_pointer_42_not_initialized_revert(): - let (mem_zone : felt*) = alloc() - assert mem_zone[0] = 42 - assert_pointer_42(mem_zone) +func test_assert_pointer_42_not_initialized_revert() { + let (mem_zone: felt*) = alloc(); + assert mem_zone[0] = 42; + assert_pointer_42(mem_zone); - assert_pointer_42(mem_zone + 1) + assert_pointer_42(mem_zone + 1); %{ expect_revert() %} - assert mem_zone[1] = 21 + assert mem_zone[1] = 21; - return () -end + return (); +} @external -func test_assert_pointer_42_no_set(): - let (mem_zone : felt*) = alloc() - assert mem_zone[0] = 42 - assert mem_zone[1] = 21 +func test_assert_pointer_42_no_set() { + let (mem_zone: felt*) = alloc(); + assert mem_zone[0] = 42; + assert mem_zone[1] = 21; - assert_pointer_42_no_set(mem_zone) + assert_pointer_42_no_set(mem_zone); %{ expect_revert() %} - assert_pointer_42_no_set(mem_zone + 1) + assert_pointer_42_no_set(mem_zone + 1); - return () -end + return (); +} @external -func test_assert_pointer_42_no_set_crash(): - let (mem_zone : felt*) = alloc() +func test_assert_pointer_42_no_set_crash() { + let (mem_zone: felt*) = alloc(); %{ expect_revert() %} - assert_pointer_42_no_set(mem_zone) + assert_pointer_42_no_set(mem_zone); - return () -end + return (); +} diff --git a/exercises/registers/registers03.cairo b/exercises/registers/registers03.cairo index 4f606c09..b2c2a3c4 100644 --- a/exercises/registers/registers03.cairo +++ b/exercises/registers/registers03.cairo @@ -1,81 +1,81 @@ %lang starknet from starkware.cairo.common.math_cmp import is_le -# I AM NOT DONE +// I AM NOT DONE -# TODO -# Rewrite those functions with a high level syntax +// TODO +// Rewrite those functions with a high level syntax @external -func sum_array(array_len : felt, array : felt*) -> (sum : felt): - # [ap] = [fp - 4]; ap++ - # [ap] = [fp - 3]; ap++ - # [ap] = 0; ap++ - # call rec_sum_array - # ret -end +func sum_array(array_len: felt, array: felt*) -> (sum: felt) { + // [ap] = [fp - 4]; ap++ + // [ap] = [fp - 3]; ap++ + // [ap] = 0; ap++ + // call rec_sum_array + // ret +} -func rec_sum_array(array_len : felt, array : felt*, sum : felt) -> (sum : felt): - # jmp continue if [fp - 5] != 0 +func rec_sum_array(array_len: felt, array: felt*, sum: felt) -> (sum: felt) { + // jmp continue if [fp - 5] != 0 - # stop: - # [ap] = [fp - 3]; ap++ - # jmp done + // stop: + // [ap] = [fp - 3]; ap++ + // jmp done - # continue: - # [ap] = [[fp - 4]]; ap++ - # [ap] = [fp - 5] - 1; ap++ - # [ap] = [fp - 4] + 1; ap++ - # [ap] = [ap - 3] + [fp - 3]; ap++ - # call rec_sum_array + // continue: + // [ap] = [[fp - 4]]; ap++ + // [ap] = [fp - 5] - 1; ap++ + // [ap] = [fp - 4] + 1; ap++ + // [ap] = [ap - 3] + [fp - 3]; ap++ + // call rec_sum_array - # done: - # ret -end + // done: + // ret +} -# TODO -# Rewrite this function with a low level syntax -# It's possible to do it with only registers, labels and conditional jump. No reference or localvar +// TODO +// Rewrite this function with a low level syntax +// It's possible to do it with only registers, labels and conditional jump. No reference or localvar @external -func max{range_check_ptr}(a : felt, b : felt) -> (max : felt): - # let (res) = is_le(a, b) - # if res == 1: - # return (b) - # else: - # return (a) - # end -end +func max{range_check_ptr}(a: felt, b: felt) -> (max: felt) { + // let (res) = is_le(a, b) + // if res == 1: + // return (b) + // else: + // return (a) + // end +} -######### -# TESTS # -######### +//######## +// TESTS # +//######## from starkware.cairo.common.alloc import alloc @external -func test_max{range_check_ptr}(): - let (m) = max(21, 42) - assert m = 42 - let (m) = max(42, 21) - assert m = 42 - return () -end +func test_max{range_check_ptr}() { + let (m) = max(21, 42); + assert m = 42; + let (m) = max(42, 21); + assert m = 42; + return (); +} @external -func test_sum(): - let (array) = alloc() - assert array[0] = 1 - assert array[1] = 2 - assert array[2] = 3 - assert array[3] = 4 - assert array[4] = 5 - assert array[5] = 6 - assert array[6] = 7 - assert array[7] = 8 - assert array[8] = 9 - assert array[9] = 10 +func test_sum() { + let (array) = alloc(); + assert array[0] = 1; + assert array[1] = 2; + assert array[2] = 3; + assert array[3] = 4; + assert array[4] = 5; + assert array[5] = 6; + assert array[6] = 7; + assert array[7] = 8; + assert array[8] = 9; + assert array[9] = 10; - let (s) = sum_array(10, array) - assert s = 55 + let (s) = sum_array(10, array); + assert s = 55; - return () -end + return (); +} diff --git a/exercises/registers/registers04.cairo b/exercises/registers/registers04.cairo index 16503f79..f5c8aa74 100644 --- a/exercises/registers/registers04.cairo +++ b/exercises/registers/registers04.cairo @@ -1,31 +1,31 @@ %lang starknet -# Felts supports basic math operations. -# High level syntax allows one-line multiple operations while low level syntax doesn't. -# Exercice source: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements +// Felts supports basic math operations. +// High level syntax allows one-line multiple operations while low level syntax doesn't. +// Exercice source: https://www.cairo-lang.org/docs/how_cairo_works/cairo_intro.html#field-elements -# I AM NOT DONE +// I AM NOT DONE -# TODO -# Write this function body in a high level syntax -func poly_high_level(x : felt) -> (res : felt): - # return x³ + 23x² + 45x + 67 according to x - return (res=res) # Do not change -end +// TODO +// Write this function body in a high level syntax +func poly_high_level(x: felt) -> (res: felt) { + // return x³ + 23x² + 45x + 67 according to x + return (res=res); // Do not change +} -# TODO -# Write this function body in a low level syntax (result must be stored in [ap - 1] before ret) -func poly_low_level(x : felt): - # return x³ + 23x² + 45x + 67 according to x - ret # Do not change -end +// TODO +// Write this function body in a low level syntax (result must be stored in [ap - 1] before ret) +func poly_low_level(x: felt) { + // return x³ + 23x² + 45x + 67 according to x + ret; // Do not change +} -# Do not change the test +// Do not change the test @external -func test_poly(): - poly_low_level(x=100) - assert [ap - 1] = 1234567 - let (high_level_res) = poly_high_level(x=100) - assert high_level_res = 1234567 - return () -end +func test_poly() { + poly_low_level(x=100); + assert [ap - 1] = 1234567; + let (high_level_res) = poly_high_level(x=100); + assert high_level_res = 1234567; + return (); +} diff --git a/exercises/revoked_references/revoked_references01.cairo b/exercises/revoked_references/revoked_references01.cairo index 2c0fe0f5..2c156a4e 100644 --- a/exercises/revoked_references/revoked_references01.cairo +++ b/exercises/revoked_references/revoked_references01.cairo @@ -1,38 +1,38 @@ %lang starknet -# References in Cairo are like aliases to specific memory cells pointed by ap +// References in Cairo are like aliases to specific memory cells pointed by ap -# I AM NOT DONE +// I AM NOT DONE -# TODO: complete the bar function to make the test pass -# You will encounter a "revoked reference" error -# https://www.cairo-lang.org/docs/how_cairo_works/consts.html#revoked-references +// TODO: complete the bar function to make the test pass +// You will encounter a "revoked reference" error +// https://www.cairo-lang.org/docs/how_cairo_works/consts.html#revoked-references from starkware.cairo.common.cairo_builtins import HashBuiltin from starkware.cairo.common.hash import hash2 -func foo(n): - if n == 0: - return () - end - foo(n=n - 1) - return () -end +func foo(n) { + if (n == 0) { + return (); + } + foo(n=n - 1); + return (); +} -func bar{hash_ptr : HashBuiltin*}(): - hash2(1, 2) # Do not change - foo(3) # Do not change +func bar{hash_ptr: HashBuiltin*}() { + hash2(1, 2); // Do not change + foo(3); // Do not change - # Insert something here to make the test pass + // Insert something here to make the test pass - hash2(3, 4) # Do not change - return () # Do not change -end + hash2(3, 4); // Do not change + return (); // Do not change +} -# Do not change the test +// Do not change the test @external -func test_bar{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - bar{hash_ptr=pedersen_ptr}() +func test_bar{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + bar{hash_ptr=pedersen_ptr}(); - return () -end + return (); +} diff --git a/exercises/storage/storage01.cairo b/exercises/storage/storage01.cairo index a9feec0a..f90db280 100644 --- a/exercises/storage/storage01.cairo +++ b/exercises/storage/storage01.cairo @@ -1,25 +1,25 @@ %lang starknet -# Starknet provide persistent and mutable storage +// Starknet provide persistent and mutable storage -# I AM NOT DONE +// I AM NOT DONE -# TODO -# Create a storage named `bool` storing a single felt +// TODO +// Create a storage named `bool` storing a single felt -# TESTS # +// TESTS # from starkware.cairo.common.cairo_builtins import HashBuiltin @external -func test_store_bool{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - let (x) = bool.read() - assert x = 0 +func test_store_bool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + let (x) = bool.read(); + assert x = 0; - bool.write(1) + bool.write(1); - let (x) = bool.read() - assert x = 1 + let (x) = bool.read(); + assert x = 1; - return () -end + return (); +} diff --git a/exercises/storage/storage02.cairo b/exercises/storage/storage02.cairo index 548a5cda..1dfff8b8 100644 --- a/exercises/storage/storage02.cairo +++ b/exercises/storage/storage02.cairo @@ -1,59 +1,59 @@ %lang starknet -# Starknet storage can be though about as a hashmap +// Starknet storage can be though about as a hashmap -# I AM NOT DONE +// I AM NOT DONE -struct Id: - member age : felt - member height : felt - member married : felt -end +struct Id { + age: felt, + height: felt, + married: felt, +} -# TODO -# Create a storage named wallet, mapping a felt to another -# Create a storage named height_map, mapping two felts to another -# Create a storage named id, mapping a felt to an Id +// TODO +// Create a storage named wallet, mapping a felt to another +// Create a storage named height_map, mapping two felts to another +// Create a storage named id, mapping a felt to an Id -# TESTS # +// TESTS # from starkware.cairo.common.cairo_builtins import HashBuiltin @external -func test_wallet{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - let (x) = wallet.read(0) - assert x = 0 +func test_wallet{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + let (x) = wallet.read(0); + assert x = 0; - wallet.write(0, 100) + wallet.write(0, 100); - let (x) = wallet.read(0) - assert x = 100 + let (x) = wallet.read(0); + assert x = 100; - return () -end + return (); +} @external -func test_height_map{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - let (z) = height_map.read(0, 0) - assert z = 0 +func test_height_map{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + let (z) = height_map.read(0, 0); + assert z = 0; - height_map.write(0, 0, 5) + height_map.write(0, 0, 5); - let (z) = height_map.read(0, 0) - assert z = 5 + let (z) = height_map.read(0, 0); + assert z = 5; - return () -end + return (); +} @external -func test_id{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - let (mr_smith) = id.read(0) - assert mr_smith = Id(0, 0, 0) +func test_id{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + let (mr_smith) = id.read(0); + assert mr_smith = Id(0, 0, 0); - id.write(0, Id(37, 185, 0)) + id.write(0, Id(37, 185, 0)); - let (mr_smith) = id.read(0) - assert mr_smith = Id(37, 185, 0) + let (mr_smith) = id.read(0); + assert mr_smith = Id(37, 185, 0); - return () -end + return (); +} diff --git a/exercises/storage/storage03.cairo b/exercises/storage/storage03.cairo index 60cc3440..5aa2ef09 100644 --- a/exercises/storage/storage03.cairo +++ b/exercises/storage/storage03.cairo @@ -1,45 +1,43 @@ %lang starknet -# You can update stored values using externals, or just consult them (for free) using views +// You can update stored values using externals, or just consult them (for free) using views -# I AM NOT DONE +// I AM NOT DONE @storage_var -func bool() -> (bool : felt): -end +func bool() -> (bool: felt) { +} @external -func toggle{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - # TODO - # Implement toggle external -end +func toggle{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + // TODO + // Implement toggle external +} @view -func view_bool{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> ( - bool : felt -): - # TODO - # Implement view_bool -end +func view_bool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (bool: felt) { + // TODO + // Implement view_bool +} -# TESTS # +// TESTS # from starkware.cairo.common.cairo_builtins import HashBuiltin @external -func test_toggle_and_view{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - let (x) = view_bool() - assert x = 0 +func test_toggle_and_view{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + let (x) = view_bool(); + assert x = 0; - toggle() + toggle(); - let (x) = view_bool() - assert x = 1 + let (x) = view_bool(); + assert x = 1; - toggle() + toggle(); - let (x) = view_bool() - assert x = 0 + let (x) = view_bool(); + assert x = 0; - return () -end + return (); +} diff --git a/exercises/strings/strings00.cairo b/exercises/strings/strings00.cairo index df09a2a7..5463cb88 100644 --- a/exercises/strings/strings00.cairo +++ b/exercises/strings/strings00.cairo @@ -1,27 +1,27 @@ %lang starknet -# Cairo supports short strings which are encoded as ASCII under the hood -# The felt is the decimal representation of the string in hexadecimal ASCII -# e.g. let hello_string = 'Hello' -# let hello_felt = 310939249775 -# let hello_hex = 0x48656c6c6f -# https://www.cairo-lang.org/docs/how_cairo_works/consts.html#short-string-literals +// Cairo supports short strings which are encoded as ASCII under the hood +// The felt is the decimal representation of the string in hexadecimal ASCII +// e.g. let hello_string = 'Hello' +// let hello_felt = 310939249775 +// let hello_hex = 0x48656c6c6f +// https://www.cairo-lang.org/docs/how_cairo_works/consts.html#short-string-literals -# I AM NOT DONE +// I AM NOT DONE -# TODO: Fix the say_hello function by returning the appropriate short strings +// TODO: Fix the say_hello function by returning the appropriate short strings -func say_hello() -> (hello_string : felt, hello_felt : felt, hello_hex : felt): - # FILL ME - return (hello_string, hello_felt, hello_hex) -end +func say_hello() -> (hello_string: felt, hello_felt: felt, hello_hex: felt) { + // FILL ME + return (hello_string, hello_felt, hello_hex); +} -# Do not change the test +// Do not change the test @external -func test_say_hello{syscall_ptr : felt*}(): - let (user_string, user_felt, user_hex) = say_hello() - assert user_string = 'Hello Starklings' - assert user_felt = 12011164701440182822452181791570417168947 - assert user_hex = 0x627569646c20627569646c20627569646c - return () -end +func test_say_hello{syscall_ptr: felt*}() { + let (user_string, user_felt, user_hex) = say_hello(); + assert user_string = 'Hello Starklings'; + assert user_felt = 12011164701440182822452181791570417168947; + assert user_hex = 0x627569646c20627569646c20627569646c; + return (); +} diff --git a/exercises/strings/strings01.cairo b/exercises/strings/strings01.cairo index 176663c7..f1217f4f 100644 --- a/exercises/strings/strings01.cairo +++ b/exercises/strings/strings01.cairo @@ -1,36 +1,36 @@ %lang starknet -# Short strings really are felts in disguise, and support the same basic operations +// Short strings really are felts in disguise, and support the same basic operations -# I AM NOT DONE +// I AM NOT DONE -# TODO: Find the key to decode the string that passes the test +// TODO: Find the key to decode the string that passes the test -func decode_cipher1() -> (plaintext : felt): - let ciphertext = 'Another One Bites The Dust' - let key = 0 - let plaintext = ciphertext + key - return (plaintext) -end +func decode_cipher1() -> (plaintext: felt) { + let ciphertext = 'Another One Bites The Dust'; + let key = 0; + let plaintext = ciphertext + key; + return (plaintext,); +} -# TODO: Find the correct ciphertext that passes the test +// TODO: Find the correct ciphertext that passes the test -func decode_cipher2() -> (plaintext : felt): - let ciphertext = 0 - let plaintext = 1337 * ciphertext + 0xc0de - return (plaintext) -end +func decode_cipher2() -> (plaintext: felt) { + let ciphertext = 0; + let plaintext = 1337 * ciphertext + 0xc0de; + return (plaintext,); +} -# Do not change the test +// Do not change the test @external -func test_decode_string{syscall_ptr : felt*}(): - # The correct key should produce the corresponding plaintext - let (decoded_string) = decode_cipher1() - assert decoded_string = 'Twinkle Twinkle Little Star' +func test_decode_string{syscall_ptr: felt*}() { + // The correct key should produce the corresponding plaintext + let (decoded_string) = decode_cipher1(); + assert decoded_string = 'Twinkle Twinkle Little Star'; - # The correct ciphertext should produce corresponding plaintext - let (decoded_string) = decode_cipher2() - assert decoded_string = 'Magic Starknet Money' + // The correct ciphertext should produce corresponding plaintext + let (decoded_string) = decode_cipher2(); + assert decoded_string = 'Magic Starknet Money'; - return () -end + return (); +} diff --git a/exercises/syntax/syntax01.cairo b/exercises/syntax/syntax01.cairo index f5b07a35..b77c9d3d 100644 --- a/exercises/syntax/syntax01.cairo +++ b/exercises/syntax/syntax01.cairo @@ -1,12 +1,12 @@ -# All Starknet files must start with a specific line indicating the file is a smart contract, -# not just a regular Cairo file +// All Starknet files must start with a specific line indicating the file is a smart contract, +// not just a regular Cairo file -# I AM NOT DONE +// I AM NOT DONE -# TODO: add the Starknet file specifier at the beginning of the file +// TODO: add the Starknet file specifier at the beginning of the file -# You can ignore what follows for now +// You can ignore what follows for now @external -func test_ok(): - return () -end +func test_ok() { + return (); +} diff --git a/exercises/syntax/syntax02.cairo b/exercises/syntax/syntax02.cairo index e210f761..23dde164 100644 --- a/exercises/syntax/syntax02.cairo +++ b/exercises/syntax/syntax02.cairo @@ -1,14 +1,14 @@ %lang starknet -# Starknet provides a module management system. -# It is very similar to the Python's one. +// Starknet provides a module management system. +// It is very similar to the Python's one. -# I AM NOT DONE +// I AM NOT DONE -# TODO: add the module imports needed to make the test pass! +// TODO: add the module imports needed to make the test pass! -# You can ignore what follows for now +// You can ignore what follows for now @external -func test_ok{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - return () -end +func test_ok{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + return (); +} diff --git a/exercises/syntax/syntax03.cairo b/exercises/syntax/syntax03.cairo index c07022ce..f0e77d6a 100644 --- a/exercises/syntax/syntax03.cairo +++ b/exercises/syntax/syntax03.cairo @@ -1,19 +1,19 @@ %lang starknet -# Functions can take arguments and return results +// Functions can take arguments and return results -# I AM NOT DONE +// I AM NOT DONE -# TODO: make the test pass! +// TODO: make the test pass! -func takes_two_arguments_and_returns_one() -> (): - return (a + b) # Do not change -end +func takes_two_arguments_and_returns_one() -> () { + return (a + b,); // Do not change +} -# You could be tempted to change the test to make it pass, but don't? +// You could be tempted to change the test to make it pass, but don't? @external -func test_sum{syscall_ptr : felt*}(): - let (sum) = takes_two_arguments_and_returns_one(1, 2) - assert sum = 3 - return () -end +func test_sum{syscall_ptr: felt*}() { + let (sum) = takes_two_arguments_and_returns_one(1, 2); + assert sum = 3; + return (); +} diff --git a/exercises/syntax/syntax04.cairo b/exercises/syntax/syntax04.cairo index 60e60bdd..efd0e80e 100644 --- a/exercises/syntax/syntax04.cairo +++ b/exercises/syntax/syntax04.cairo @@ -1,22 +1,22 @@ %lang starknet -# Function and other definitions can be scoped in namespaces, making the code more readable. +// Function and other definitions can be scoped in namespaces, making the code more readable. -# I AM NOT DONE +// I AM NOT DONE -# TODO: make the test pass! +// TODO: make the test pass! -# Do not change anything but the test -namespace my_namespace: - func returns_something() -> (result : felt): - return (42) - end -end +// Do not change anything but the test +namespace my_namespace { + func returns_something() -> (result: felt) { + return (42,); + } +} -# Change the following test to make it pass +// Change the following test to make it pass @external -func test_hello{syscall_ptr : felt*}(): - let (result) = returns_something() - assert result = 42 - return () -end +func test_hello{syscall_ptr: felt*}() { + let (result) = returns_something(); + assert result = 42; + return (); +} diff --git a/exercises/syntax/syntax05.cairo b/exercises/syntax/syntax05.cairo index bb65c7b7..d28fc625 100644 --- a/exercises/syntax/syntax05.cairo +++ b/exercises/syntax/syntax05.cairo @@ -1,16 +1,16 @@ %lang starknet -# As with many other languages, you can describe object structures with the struct keyword. +// As with many other languages, you can describe object structures with the struct keyword. -# I AM NOT DONE +// I AM NOT DONE -# TODO: declare the Currency struct to make the test pass +// TODO: declare the Currency struct to make the test pass -# Do not change the test +// Do not change the test @external -func test_currency_sum{syscall_ptr : felt*}(): - alloc_locals - local euro : Currency = Currency('Euro', 2) - assert euro.name = 'Euro' - return () -end +func test_currency_sum{syscall_ptr: felt*}() { + alloc_locals; + local euro: Currency = Currency('Euro', 2); + assert euro.name = 'Euro'; + return (); +} diff --git a/exercises/tricks/assert_bool.cairo b/exercises/tricks/assert_bool.cairo index 9da9053f..6905f86c 100644 --- a/exercises/tricks/assert_bool.cairo +++ b/exercises/tricks/assert_bool.cairo @@ -1,118 +1,118 @@ %lang starknet -# Boolean assertions, such as "x OR y" for boolean felts, can also be implemented without conditionals. +// Boolean assertions, such as "x OR y" for boolean felts, can also be implemented without conditionals. -# I AM NOT DONE +// I AM NOT DONE -# TODO Implement the following boolean asserts without "if" +// TODO Implement the following boolean asserts without "if" -func assert_or(x, y): - # FILL ME - return () -end +func assert_or(x, y) { + // FILL ME + return (); +} -func assert_and(x, y): - # FILL ME - return () -end +func assert_and(x, y) { + // FILL ME + return (); +} -func assert_nor(x, y): - # FILL ME - return () -end +func assert_nor(x, y) { + // FILL ME + return (); +} -func assert_xor(x, y): - # FILL ME - return () -end +func assert_xor(x, y) { + // FILL ME + return (); +} -# Do not modify the tests +// Do not modify the tests @external -func test_assert_or(): - assert_or(0, 1) - assert_or(1, 0) - assert_or(1, 1) - return () -end +func test_assert_or() { + assert_or(0, 1); + assert_or(1, 0); + assert_or(1, 1); + return (); +} @external -func test_assert_or_ko(): +func test_assert_or_ko() { %{ expect_revert() %} - assert_or(0, 0) - return () -end + assert_or(0, 0); + return (); +} @external -func test_assert_and(): - assert_and(1, 1) - return () -end +func test_assert_and() { + assert_and(1, 1); + return (); +} @external -func test_assert_and_ko1(): +func test_assert_and_ko1() { %{ expect_revert() %} - assert_and(0, 0) - return () -end + assert_and(0, 0); + return (); +} @external -func test_assert_and_ko2(): +func test_assert_and_ko2() { %{ expect_revert() %} - assert_and(0, 1) - return () -end + assert_and(0, 1); + return (); +} @external -func test_assert_and_ko3(): +func test_assert_and_ko3() { %{ expect_revert() %} - assert_and(1, 0) - return () -end + assert_and(1, 0); + return (); +} @external -func test_assert_nor(): - assert_nor(0, 0) - return () -end +func test_assert_nor() { + assert_nor(0, 0); + return (); +} @external -func test_assert_nor_ko1(): +func test_assert_nor_ko1() { %{ expect_revert() %} - assert_nor(0, 1) - return () -end + assert_nor(0, 1); + return (); +} @external -func test_assert_nor_ko2(): +func test_assert_nor_ko2() { %{ expect_revert() %} - assert_nor(1, 0) - return () -end + assert_nor(1, 0); + return (); +} @external -func test_assert_nor_ko3(): +func test_assert_nor_ko3() { %{ expect_revert() %} - assert_nor(1, 1) - return () -end + assert_nor(1, 1); + return (); +} @external -func test_assert_xor(): - assert_xor(0, 1) - assert_xor(1, 0) - return () -end +func test_assert_xor() { + assert_xor(0, 1); + assert_xor(1, 0); + return (); +} @external -func test_assert_xor_ko(): +func test_assert_xor_ko() { %{ expect_revert() %} - assert_xor(0, 0) - return () -end + assert_xor(0, 0); + return (); +} @external -func test_assert_xor_ko2(): +func test_assert_xor_ko2() { %{ expect_revert() %} - assert_xor(1, 1) - return () -end + assert_xor(1, 1); + return (); +} diff --git a/exercises/tricks/inline_if.cairo b/exercises/tricks/inline_if.cairo index 8394db71..66847b83 100644 --- a/exercises/tricks/inline_if.cairo +++ b/exercises/tricks/inline_if.cairo @@ -3,30 +3,30 @@ from starkware.cairo.common.math_cmp import is_not_zero from starkware.cairo.common.bool import TRUE, FALSE -# Sometimes, conditionals can be avoided by using a polynomial that maps valid inputs to 0 -# Use this trick to rewrite functions without "if" +// Sometimes, conditionals can be avoided by using a polynomial that maps valid inputs to 0 +// Use this trick to rewrite functions without "if" -# I AM NOT DONE +// I AM NOT DONE -# TODO: Implement a ternary operator `if cond then return val_true else return val_false` -# Make sure the condition is a boolean +// TODO: Implement a ternary operator `if cond then return val_true else return val_false` +// Make sure the condition is a boolean -func if_then_else(cond : felt, val_true : felt, val_false) -> (res : felt): - # FILL ME - return (res) -end +func if_then_else(cond: felt, val_true: felt, val_false) -> (res: felt) { + // FILL ME + return (res,); +} @external -func test_ternary_conditional_operator(): - let (res) = if_then_else(FALSE, 911, 420) - assert 420 = res - let (res) = if_then_else(TRUE, 911, 'over 9000') - assert 911 = res - let (res) = if_then_else(FALSE, 69420, 1559) - assert 1559 = res - let (res) = if_then_else(TRUE, 'nice', 69) - assert 'nice' = res +func test_ternary_conditional_operator() { + let (res) = if_then_else(FALSE, 911, 420); + assert 420 = res; + let (res) = if_then_else(TRUE, 911, 'over 9000'); + assert 911 = res; + let (res) = if_then_else(FALSE, 69420, 1559); + assert 1559 = res; + let (res) = if_then_else(TRUE, 'nice', 69); + assert 'nice' = res; %{ expect_revert() %} - let (res) = if_then_else(69, 'nope', 911) - return () -end + let (res) = if_then_else(69, 'nope', 911); + return (); +} diff --git a/exercises/tricks/no_conditionals.cairo b/exercises/tricks/no_conditionals.cairo index ade7f821..13464186 100644 --- a/exercises/tricks/no_conditionals.cairo +++ b/exercises/tricks/no_conditionals.cairo @@ -2,67 +2,67 @@ from starkware.cairo.common.math_cmp import is_not_zero -# Sometimes, conditionals can be avoided by using an expression that -# - maps valid inputs to 1, -# - and/or maps invalid inputs to 0. -# For instance (row - 2) * (row - 4) is 0 only when row is 2 or 4. +// Sometimes, conditionals can be avoided by using an expression that +// - maps valid inputs to 1, +// - and/or maps invalid inputs to 0. +// For instance (row - 2) * (row - 4) is 0 only when row is 2 or 4. -# Use this trick to rewrite functions without "if" conditions -# Note: This helps to avoid dealing with revoked references. +// Use this trick to rewrite functions without "if" conditions +// Note: This helps to avoid dealing with revoked references. -# I AM NOT DONE +// I AM NOT DONE -func is_binary_if(x : felt) -> (res : felt): - if x == 0: - return (1) - end - if x == 1: - return (1) - end - return (0) -end +func is_binary_if(x: felt) -> (res: felt) { + if (x == 0) { + return (1,); + } + if (x == 1) { + return (1,); + } + return (0,); +} -# TODO: Return the right value to mimick the behavior of is_binary_if +// TODO: Return the right value to mimick the behavior of is_binary_if -func is_binary_no_if(x : felt) -> (res : felt): - # FILL ME - return (res) -end +func is_binary_no_if(x: felt) -> (res: felt) { + // FILL ME + return (res,); +} -# TODO: Fix the function so that -# - it returns the string 'cool' if x is 1337, 69420, 42 -# - it returns 'meh' on any other input +// TODO: Fix the function so that +// - it returns the string 'cool' if x is 1337, 69420, 42 +// - it returns 'meh' on any other input -func is_cool(x : felt) -> (res : felt): - # FILL ME - return (res) -end +func is_cool(x: felt) -> (res: felt) { + // FILL ME + return (res,); +} -# Do not change the test +// Do not change the test @external -func test_is_binary{syscall_ptr : felt*}(): - let (eval_if) = is_binary_if(0) - let (eval_no_if) = is_binary_no_if(0) - assert (eval_if, eval_no_if) = (1, 1) +func test_is_binary{syscall_ptr: felt*}() { + let (eval_if) = is_binary_if(0); + let (eval_no_if) = is_binary_no_if(0); + assert (eval_if, eval_no_if) = (1, 1); - let (eval_if) = is_binary_if(1) - let (eval_no_if) = is_binary_no_if(1) - assert (eval_if, eval_no_if) = (1, 1) + let (eval_if) = is_binary_if(1); + let (eval_no_if) = is_binary_no_if(1); + assert (eval_if, eval_no_if) = (1, 1); - let (eval_if) = is_binary_if(13) - let (eval_no_if) = is_binary_no_if(37) - assert (eval_if, eval_no_if) = (0, 0) - return () -end + let (eval_if) = is_binary_if(13); + let (eval_no_if) = is_binary_no_if(37); + assert (eval_if, eval_no_if) = (0, 0); + return (); +} @external -func test_is_cool{syscall_ptr : felt*}(): - let (is_1337_cool) = is_cool(1337) - let (is_69420_cool) = is_cool(69420) - let (is_42_cool) = is_cool(42) - let (is_0_cool) = is_cool(0) - let (is_911_cool) = is_cool(911) - let results = ('cool', 'cool', 'cool', 'meh', 'meh') - assert (is_1337_cool, is_69420_cool, is_42_cool, is_0_cool, is_911_cool) = results - return () -end +func test_is_cool{syscall_ptr: felt*}() { + let (is_1337_cool) = is_cool(1337); + let (is_69420_cool) = is_cool(69420); + let (is_42_cool) = is_cool(42); + let (is_0_cool) = is_cool(0); + let (is_911_cool) = is_cool(911); + let results = ('cool', 'cool', 'cool', 'meh', 'meh'); + assert (is_1337_cool, is_69420_cool, is_42_cool, is_0_cool, is_911_cool) = results; + return (); +} diff --git a/migrate.sh b/migrate.sh new file mode 100755 index 00000000..4cdcc2de --- /dev/null +++ b/migrate.sh @@ -0,0 +1,11 @@ + +#!/bin/bash + +# +# migrate and format all cairo files in project/dir +# oneline: `for i in $(find . -name "*.cairo" -type f); do cairo-migrate $i -i; done` +# +for i in $(find . -name "*.cairo" -type f); do + echo "editing $i" + cairo-migrate -i $i +done From 0a9fda58b55521ce6bfd356567ded00aadf6475c Mon Sep 17 00:00:00 2001 From: "nicolas.ngomai" Date: Tue, 4 Oct 2022 10:58:11 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=94=A7=20fix:=20migrate=20test=20file?= =?UTF-8?q?s=20to=20new=20cairo=20syntax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../with_next_exercises/syntax01.cairo | 14 +++++++------- .../with_next_exercises/syntax02.cairo | 16 ++++++++-------- .../without_next_exercises/syntax01.cairo | 14 +++++++------- .../without_next_exercises/syntax02.cairo | 14 +++++++------- tests/test.cairo | 16 ++++++++-------- tests/test_failure.cairo | 16 ++++++++-------- tests/test_missing.cairo | 6 +++--- 7 files changed, 48 insertions(+), 48 deletions(-) diff --git a/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax01.cairo b/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax01.cairo index 03ccddf0..c326967f 100644 --- a/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax01.cairo +++ b/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax01.cairo @@ -1,10 +1,10 @@ -# All Starknet files must start with a specific line indicating the file is a smart contract, -# not just a regular Cairo file +// All Starknet files must start with a specific line indicating the file is a smart contract, +// not just a regular Cairo file -# TODO: add the Starknet file specifier at the beginning of the file +// TODO: add the Starknet file specifier at the beginning of the file -# You can ignore what follows for now +// You can ignore what follows for now @external -func test_ok(): - return () -end +func test_ok() { + return (); +} diff --git a/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax02.cairo b/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax02.cairo index e210f761..23dde164 100644 --- a/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax02.cairo +++ b/tests/exercises/test_end_of_exercise_messages/with_next_exercises/syntax02.cairo @@ -1,14 +1,14 @@ %lang starknet -# Starknet provides a module management system. -# It is very similar to the Python's one. +// Starknet provides a module management system. +// It is very similar to the Python's one. -# I AM NOT DONE +// I AM NOT DONE -# TODO: add the module imports needed to make the test pass! +// TODO: add the module imports needed to make the test pass! -# You can ignore what follows for now +// You can ignore what follows for now @external -func test_ok{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - return () -end +func test_ok{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + return (); +} diff --git a/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax01.cairo b/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax01.cairo index 03ccddf0..c326967f 100644 --- a/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax01.cairo +++ b/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax01.cairo @@ -1,10 +1,10 @@ -# All Starknet files must start with a specific line indicating the file is a smart contract, -# not just a regular Cairo file +// All Starknet files must start with a specific line indicating the file is a smart contract, +// not just a regular Cairo file -# TODO: add the Starknet file specifier at the beginning of the file +// TODO: add the Starknet file specifier at the beginning of the file -# You can ignore what follows for now +// You can ignore what follows for now @external -func test_ok(): - return () -end +func test_ok() { + return (); +} diff --git a/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax02.cairo b/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax02.cairo index 725b296c..e48d3657 100644 --- a/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax02.cairo +++ b/tests/exercises/test_end_of_exercise_messages/without_next_exercises/syntax02.cairo @@ -1,12 +1,12 @@ %lang starknet -# Starknet provides a module management system. -# It is very similar to the Python's one. +// Starknet provides a module management system. +// It is very similar to the Python's one. -# TODO: add the module imports needed to make the test pass! +// TODO: add the module imports needed to make the test pass! -# You can ignore what follows for now +// You can ignore what follows for now @external -func test_ok{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(): - return () -end +func test_ok{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { + return (); +} diff --git a/tests/test.cairo b/tests/test.cairo index da9efe81..a2017e52 100644 --- a/tests/test.cairo +++ b/tests/test.cairo @@ -1,12 +1,12 @@ %lang starknet -func sum_func{syscall_ptr : felt*, range_check_ptr}(a : felt, b : felt) -> (res : felt): - return (a + b) -end +func sum_func{syscall_ptr: felt*, range_check_ptr}(a: felt, b: felt) -> (res: felt) { + return (a + b,); +} @external -func test_sum{syscall_ptr : felt*, range_check_ptr}(): - let (r) = sum_func(4, 3) - assert r = 7 - return () -end +func test_sum{syscall_ptr: felt*, range_check_ptr}() { + let (r) = sum_func(4, 3); + assert r = 7; + return (); +} diff --git a/tests/test_failure.cairo b/tests/test_failure.cairo index 8f9b0fad..750df428 100644 --- a/tests/test_failure.cairo +++ b/tests/test_failure.cairo @@ -1,12 +1,12 @@ %lang starknet -func sum_func{syscall_ptr : felt*, range_check_ptr}(a : felt, b : felt) -> (res : felt): - return (a + b) -end +func sum_func{syscall_ptr: felt*, range_check_ptr}(a: felt, b: felt) -> (res: felt) { + return (a + b,); +} @external -func test_sum{syscall_ptr : felt*, range_check_ptr}(): - let (r) = sum_func(4, 3) - assert r = 6 - return () -end +func test_sum{syscall_ptr: felt*, range_check_ptr}() { + let (r) = sum_func(4, 3); + assert r = 6; + return (); +} diff --git a/tests/test_missing.cairo b/tests/test_missing.cairo index 75d5a54f..fb95ef61 100644 --- a/tests/test_missing.cairo +++ b/tests/test_missing.cairo @@ -1,4 +1,4 @@ @external -func test_ok(): - return () -end +func test_ok() { + return (); +} From 3f2c431bb2dd81660a4898f801aa2390312e5dce Mon Sep 17 00:00:00 2001 From: "nicolas.ngomai" Date: Tue, 4 Oct 2022 10:58:36 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=94=A7=20fix:=20fix=20seeker=20for=20?= =?UTF-8?q?new=20cairo=20syntax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/exercises/seeker.py | 2 +- src/exercises/seeker_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exercises/seeker.py b/src/exercises/seeker.py index e82cae86..defdae7c 100644 --- a/src/exercises/seeker.py +++ b/src/exercises/seeker.py @@ -3,7 +3,7 @@ def _is_exercise_not_done(exercise: Path) -> bool: - return "\n# I AM NOT DONE\n" in exercise.read_text() + return "\n// I AM NOT DONE\n" in exercise.read_text() class ExerciseSeeker: diff --git a/src/exercises/seeker_test.py b/src/exercises/seeker_test.py index 368c2986..cbc1252f 100644 --- a/src/exercises/seeker_test.py +++ b/src/exercises/seeker_test.py @@ -12,7 +12,7 @@ def finished_exercise_fixture(mocker): @pytest.fixture(name="unfinished_exercise") def unfinished_exercise_fixture(mocker): mock = mocker.patch("src.exercises.seeker.Path").return_value - mock.read_text.return_value = "Yolo\n# I AM NOT DONE\nNext" + mock.read_text.return_value = "Yolo\n// I AM NOT DONE\nNext" return mock From 887ff349231b3fc7dd9719ce59e3c81c5d3fc052 Mon Sep 17 00:00:00 2001 From: "nicolas.ngomai" Date: Tue, 4 Oct 2022 14:10:49 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=94=A7=20fix:=20fix=20pyproject=20fau?= =?UTF-8?q?lty=20characters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 07569d49..312bc542 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ black = "^22.3.0" cairo-lang = {url = "https://files.pythonhosted.org/packages/c0/f6/c850604895a2ce5ff3ef77cdb470b6b0ef50889645748a748e18a1c2269e/cairo-lang-0.8.1.post1.zip#sha256=b3c1a23078ba4e0c8ec45d2cd2ba4873ad70b6723dfba70f70c978c9723ff6eb"} colorama = "^0.4.4" openzeppelin-cairo-contracts = "^0.1.0" -pyinstaller = "ˆ5.0.1" +pyinstaller = "^5.0.1" pylint = "^2.13.8" pytest = "^7.1.2" pytest-mock = "^3.7.0" @@ -25,7 +25,7 @@ pickleDB = "^0.9.2" [tool.poetry.dev-dependencies] GitPython = "^3.1.27" packaging = "^21.3" -poethepoet = "ˆ0.13.1" +poethepoet = "^0.13.1" tomli = "<2.0.0" responses = "^0.21.0" From a84d78a3dcd0c5cfff3ec7d64eb3d7c9e0afb718 Mon Sep 17 00:00:00 2001 From: "nicolas.ngomai" Date: Tue, 4 Oct 2022 14:38:49 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=A7=20fix:=20fix=20cairo=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/solutions/factory_test.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/solutions/factory_test.py b/src/solutions/factory_test.py index ee327d75..6de9321e 100644 --- a/src/solutions/factory_test.py +++ b/src/solutions/factory_test.py @@ -19,17 +19,17 @@ def test_solution_getter(an_exercise): assert ( solution == """%lang starknet -# All Starknet files must start with a specific line indicating the file is a smart contract, -# not just a regular Cairo file +// All Starknet files must start with a specific line indicating the file is a smart contract, +// not just a regular Cairo file -# I AM NOT DONE +// I AM NOT DONE -# TODO: add the Starknet file specifier at the beginning of the file +// TODO: add the Starknet file specifier at the beginning of the file -# You can ignore what follows for now +// You can ignore what follows for now @external -func test_ok(): - return () -end +func test_ok() { + return (); +} """ )