rave_engine 0.8.0

A secure and efficient JSON Schema validation and Rhai script execution engine
Documentation
//! Rule-1 backstop for optional inputs (the rhai-engine half).
//!
//! The optional-inputs change lets an executor omit any input the runtime
//! signature does not mark `required`. Anything the agreement actually *uses* is
//! still enforced by the integrity zome's Rhai re-execution (Rule 1): reading
//! `.data` off an input that isn't present throws, so a RAVE that dropped an
//! unconditionally-read input can never reproduce its committed output and is
//! rejected. That is why an input read unconditionally (e.g. a `Fixed` constant
//! the coordinator always injects, or a fund source) cannot be silently dropped
//! even when it is absent from the signature's `required`.
//!
//! This locks the engine behavior the backstop depends on. If a Rhai upgrade ever
//! made `().data` yield `()` instead of throwing, the backstop would weaken
//! silently — this test trips first.

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();

    // Absent → the re-run fails, so Rule 1 rejects the RAVE.
    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"
    );

    // Present → reads cleanly.
    let present = json!({ "inputs": { "cool_down_period": { "data": "2" } } });
    assert!(engine.execute(&present, script, None).is_ok());
}