open-standards/jcp/jcp-rs/crates/jcp-action-receipt/tests/end_to_end_example.rs
Transaction Science 7f41c9a807 jcp-action-receipt: end_to_end authorises at an estimate, not a reading
The end_to_end example decides its action before the work runs and
debited Energy::measured(250_000), so the authority receipt it seals and
binds into the AR-1 receipt claimed a 0.25 J hardware reading of work
that had not happened. Its own docs promise HwShunt "only when every
record the meter returned is a hardware reading".

The decision now debits `authorised_cost()`, the action's 0.25 J
estimate graded Estimator with no measured figure, and the docs say the
work's reading is step 3's. The work receipt and the AR-1 receipt are
unchanged: they already carry the meter's own grade.

tests/end_to_end_example.rs compiles the example in as a module and
checks the authorised cost is Estimator with no measured figure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-10 17:47:12 -04:00

21 lines
968 B
Rust

//! The `end_to_end` example authorises its action before the work runs, so
//! the cost that decision debits and the authority receipt seals is an
//! estimate — never a hardware reading of work that had not happened. (The
//! work's own energy is metered, at the meter's grade, in step 3.) Checked on
//! the cost the example uses (the example file is compiled in here as a
//! module).
#[allow(dead_code)]
#[path = "../examples/end_to_end.rs"]
mod end_to_end;
use jcp_schema::Provenance;
#[test]
fn the_authorisation_is_debited_an_estimate() {
let cost = end_to_end::authorised_cost();
eprintln!("authorised cost: {} µJ [{}] measured {:?}", cost.uj(), cost.provenance.jcr1_label(), cost.measured_uj);
assert_eq!(cost.provenance, Provenance::Estimator, "a pre-run cost graded {:?}", cost.provenance);
assert_eq!(cost.measured_uj, None, "a measured figure for work that had not run");
assert!(cost.check_provenance().is_ok(), "{cost:?}");
}