From 5fbac6d6f404bfe4aa132694c58f84d7be02b5cc Mon Sep 17 00:00:00 2001 From: maciektr Date: Mon, 4 Mar 2024 11:34:59 +0100 Subject: [PATCH] Update scarb new/init hello world Cairo code --- examples/hello_world/src/lib.cairo | 16 +++++++--------- extensions/scarb-cairo-run/tests/examples.rs | 2 +- scarb/src/ops/new.rs | 16 +++++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/examples/hello_world/src/lib.cairo b/examples/hello_world/src/lib.cairo index 6d3ce3c14..c55f19bdf 100644 --- a/examples/hello_world/src/lib.cairo +++ b/examples/hello_world/src/lib.cairo @@ -1,19 +1,17 @@ -fn main() -> felt252 { +fn main() -> u32 { fib(16) } -fn fib(mut n: felt252) -> felt252 { - let mut a: felt252 = 0; - let mut b: felt252 = 1; - loop { - if n == 0 { - break a; - } +fn fib(mut n: u32) -> u32 { + let mut a: u32 = 0; + let mut b: u32 = 1; + while n != 0 { n = n - 1; let temp = b; b = a + b; a = temp; - } + }; + a } #[cfg(test)] diff --git a/extensions/scarb-cairo-run/tests/examples.rs b/extensions/scarb-cairo-run/tests/examples.rs index c68c5667a..3fd69252d 100644 --- a/extensions/scarb-cairo-run/tests/examples.rs +++ b/extensions/scarb-cairo-run/tests/examples.rs @@ -97,7 +97,7 @@ fn can_limit_gas() { Finished release target(s) in [..] Running hello_world Run completed successfully, returning [987] - Remaining gas: 68340 + Remaining gas: 50760 "#}); } diff --git a/scarb/src/ops/new.rs b/scarb/src/ops/new.rs index e9e1602d2..e2003a264 100644 --- a/scarb/src/ops/new.rs +++ b/scarb/src/ops/new.rs @@ -156,22 +156,20 @@ fn mk( fsx::write( source_path, indoc! {r#" - fn main() -> felt252 { + fn main() -> u32 { fib(16) } - fn fib(mut n: felt252) -> felt252 { - let mut a: felt252 = 0; - let mut b: felt252 = 1; - loop { - if n == 0 { - break a; - } + fn fib(mut n: u32) -> u32 { + let mut a: u32 = 0; + let mut b: u32 = 1; + while n != 0 { n = n - 1; let temp = b; b = a + b; a = temp; - } + }; + a } #[cfg(test)]