use crate::rhai_engine::{RhaiEngine, RhaiEngineConfig};
use serde_json::json;
#[test]
fn reading_data_off_an_absent_input_fails() {
let engine =
RhaiEngine::with_config(RhaiEngineConfig::default().with_use_holochain_time(false))
.unwrap();
let script = rmp_serde::to_vec(&r#" let x = inputs.cool_down_period.data; #{} "#).unwrap();
let absent = json!({ "inputs": { "call_method": { "data": "withdraw" } } });
assert!(
engine.execute(&absent, script.clone(), None).is_err(),
"reading .data off an absent input must fail — this is what Rule 1 relies on"
);
let present = json!({ "inputs": { "cool_down_period": { "data": "2" } } });
assert!(engine.execute(&present, script, None).is_ok());
}