#![cfg_attr(target_arch = "wasm32", no_std)]
#![cfg_attr(target_arch = "wasm32", no_main)]
extern crate zink;
#[zink::external]
pub fn fib(n: u64) -> u64 {
internal_rec(n)
}
#[inline(never)]
fn internal_rec(n: u64) -> u64 {
if n < 2 {
n
} else {
fib(n - 1) + fib(n - 2)
}
}
#[cfg(not(target_arch = "wasm32"))]
fn main() {}
#[ignore]
#[test]
fn test() -> anyhow::Result<()> {
use zint::{Bytes32, Contract};
let mut contract = Contract::search("fibonacci")?.compile()?;
let selector = "fib(uint64)".as_bytes();
let info = contract.execute([selector, &0u64.to_bytes32()])?;
assert_eq!(0.to_bytes32().to_vec(), info.ret);
let info = contract.execute([selector, &1u64.to_bytes32()])?;
assert_eq!(1.to_bytes32().to_vec(), info.ret);
let info = contract.execute([selector, &2u64.to_bytes32()])?;
assert_eq!(1.to_bytes32().to_vec(), info.ret);
let info = contract.execute([selector, &3u64.to_bytes32()])?;
assert_eq!(2.to_bytes32().to_vec(), info.ret);
let info = contract.execute([selector, &4u64.to_bytes32()])?;
assert_eq!(3.to_bytes32().to_vec(), info.ret);
let info = contract.execute([selector, &5u64.to_bytes32()])?;
assert_eq!(5.to_bytes32().to_vec(), info.ret);
Ok(())
}