Skip to content

Commit

Permalink
Update scarb new/init hello world Cairo code (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Mar 4, 2024
1 parent b2c0de9 commit 781df2a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
16 changes: 7 additions & 9 deletions examples/hello_world/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion extensions/scarb-cairo-run/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#});
}

Expand Down
16 changes: 7 additions & 9 deletions scarb/src/ops/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 781df2a

Please sign in to comment.