I'm running on Mac OS V10.14.6 and running v0.0.21-alpha1 on nixOS. So, I've been trying to make a create_user_entry zome function and it takes User struct(with nested UserInfo struct). All my unit tests in rust are passing but then the diorama test is failing apparently because of a function that uses chrono crate. Here is the code,
use chrono::{offset::Local, Date, Datelike, TimeZone};
use hdk::holochain_json_api::{error::JsonError, json::JsonString};
// This is the User entry
#[derive(Serialize, Deserialize, Debug, DefaultJson, Clone)]
pub struct User {
pub agent: Address,
pub handle: String,
pub user_info: user_info::UserInfo,
}
//Within this struct is the birth_date key with BirthDate struct value which has the get_age() associated function that uses a chrono crate.
#[derive(Serialize, Deserialize, Debug, DefaultJson, Clone, PartialEq)]
pub struct UserInfo {
pub first_name: String,
pub last_name: String,
pub birth_date: BirthDate,
pub age: u32,
}
//This is the BirthDate struct with its associated function get_age
#[derive(Serialize, Deserialize, Debug, DefaultJson, Clone, PartialEq)]
pub struct BirthDate {
birth_year: i32,
birth_month: u32,
birth_day: u32,
}
impl BirthDate {
//This is causing the Holochain Instance Error: WASM invocation failed: Trap: Trap { kind: Unreachable error
pub fn get_age(birth_year: i32, birth_month: u32, birth_day: u32) -> u32 {
let birthday_dt: Date<Local> =
Local.ymd(birth_year.clone(), birth_month.clone(), birth_day.clone());
let local_dt: Date<Local> = Local::today();
let year_diff: i32 = local_dt.year() - birthday_dt.year();
if birthday_dt.month() < local_dt.month() {
return year_diff as u32;
} else if birthday_dt.month() == local_dt.month() {
if birthday_dt.day() >= local_dt.day() {
return year_diff as u32;
} else {
return year_diff as u32 - 1;
}
} else {
return year_diff as u32 - 1;
}
}
}
}
I expected the Diorama test to succeed but i got
info: [C] Starting instance "alice-3"...
info: [C] Starting instance "bob-3"...
info: [C] 2019-07-31 20:54:14 ThreadId(1):alice-3: debug/dna: 'called `Option::unwrap()` on a `None` value'
info: [C] 2019-07-31 20:54:14 ThreadId(1):alice-3: debug/dna: 'panic occurred in file 'src/libcore/option.rs' at line 345'
got unhandledRejection: { code: -32602,
message:
'Holochain Instance Error: WASM invocation failed: Trap: Trap { kind: Unreachable }' }
error: Test failed while running: "zome call timed out after 60 seconds: alice-3/main/create_user"
not ok 1 (unnamed assert)
---
operator: fail
at: run.catch (/Users/lc/Desktop/kiretter-test/test/node_modules/@holochain/diorama/lib/executors.js:18:19)...
Also tried replacing get_age() with get_age_test() which is defined this way. Diorama passed so chrono is probably the problem...
pub fn get_age_test(birth_year: i32, birth_month: u32, birth_day: u32) -> u32 {
// let birthday_dt: Date<Local> =
// Local.ymd(birth_year.clone(), birth_month.clone(), birth_day.clone());
let birthday_dummy: (i32, u32, u32) = (birth_year, birth_month, birth_day);
let local_dummy: (i32, u32, u32) = (2019, 07, 31);
let year_diff: i32 = local_dummy.0 - birthday_dummy.0;
if birthday_dummy.1 < local_dummy.1 {
return year_diff as u32;
} else if birthday_dummy.1 == local_dummy.1 {
if birthday_dummy.2 >= birthday_dummy.2 {
return year_diff as u32;
} else {
return year_diff as u32 - 1;
}
} else {
return year_diff as u32 - 1;
}
}
also, here's the get_age() function that's working in rust playground as well just for reference
also tried using json-rpc and get_age() worked.