Skip to content

Commit

Permalink
chore(example): use u64 for fibonacci
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Feb 27, 2024
1 parent 3f55e64 commit 269a646
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate zink;

/// Calculates the nth fibonacci number.
#[zink::external]
pub fn fib(n: usize) -> usize {
pub fn fib(n: u64) -> u64 {
if n < 2 {
n
} else {
Expand All @@ -25,27 +25,27 @@ fn test() -> anyhow::Result<()> {
let selector = "fib(uint64)".as_bytes();

// x = 0
let info = contract.execute([selector, &0usize.to_bytes32()])?;
let info = contract.execute([selector, &0u64.to_bytes32()])?;
assert_eq!(0.to_bytes32().to_vec(), info.ret);

// x = 1
let info = contract.execute([selector, &1usize.to_bytes32()])?;
let info = contract.execute([selector, &1u64.to_bytes32()])?;
assert_eq!(1.to_bytes32().to_vec(), info.ret);

// x = 2
let info = contract.execute([selector, &2usize.to_bytes32()])?;
let info = contract.execute([selector, &2u64.to_bytes32()])?;
assert_eq!(1.to_bytes32().to_vec(), info.ret);

// x = 3
let info = contract.execute([selector, &3usize.to_bytes32()])?;
let info = contract.execute([selector, &3u64.to_bytes32()])?;
assert_eq!(2.to_bytes32().to_vec(), info.ret);

// x = 4
let info = contract.execute([selector, &4usize.to_bytes32()])?;
let info = contract.execute([selector, &4u64.to_bytes32()])?;
assert_eq!(3.to_bytes32().to_vec(), info.ret);

// x = 5
let info = contract.execute([selector, &5usize.to_bytes32()])?;
let info = contract.execute([selector, &5u64.to_bytes32()])?;
assert_eq!(5.to_bytes32().to_vec(), info.ret);

Ok(())
Expand Down

0 comments on commit 269a646

Please sign in to comment.