open-standards/jcp/jcp-rs/crates/jcp-efficiency/tests/session_example.rs
Transaction Science b0f174bb8c jcp-efficiency: the session example's illustrative figures are estimates
The `session` example seals five efficiency/1 receipts for an
illustrative fleet — no task runs — and built each energy figure with
Energy::measured(uj), commented "a HwShunt reading in this demo". Every
receipt claimed a hardware reading nothing took.

`task()` now seals Energy::estimator(uj), the module docs say the fleet is
illustrative and that a binding metering real work seals its meter's
grade, and the run prints that the energy is sealed as estimates. The
figures, and so every rate the example prints, are unchanged.

tests/session_example.rs compiles the example in as a module, builds its
records and seals them: each record must be Estimator with no measured
figure, and each verified receipt's provenance "Estimator".

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

31 lines
1.5 KiB
Rust

//! The `session` example's fleet is illustrative — no task runs — so every
//! energy figure it seals must be an estimate, never a hardware reading.
//! Checked on the record the example builds (the example file is compiled in
//! here as a module) and on the `efficiency/1` receipt sealed from it,
//! recovered through the signature check.
#[allow(dead_code)]
#[path = "../examples/session.rs"]
mod session;
use ed25519_dalek::SigningKey;
use jcp_efficiency::{verify_chain, EfficiencyLog};
use jcp_schema::Provenance;
#[test]
fn the_session_examples_figures_are_sealed_as_estimates() {
let sk = SigningKey::from_bytes(&[0xed; 32]);
let mut log = EfficiencyLog::new(sk, "did:jcp:efficiency-demo");
for (id, completed) in [("fix-auth-bug", true), ("refactor-parser", false)] {
let t = session::task(id, completed, 1_200, 3_500_000, 42_000_000_000, completed.then_some(5_000_000));
eprintln!("{id}: {} µJ [{}] measured {:?}", t.energy.uj(), t.energy.provenance.jcr1_label(), t.energy.measured_uj);
assert_eq!(t.energy.provenance, Provenance::Estimator, "{id}: an illustrative figure graded {:?}", t.energy.provenance);
assert_eq!(t.energy.measured_uj, None, "{id}: a measured figure nothing read");
log.append(&t);
}
let recs = verify_chain(log.receipts(), log.steward(), &log.steward_pubkey()).expect("chain verifies");
for r in &recs {
eprintln!("sealed {}: {} µJ [{}]", r.task, r.energy_uj, r.provenance);
assert_eq!(r.provenance, "Estimator", "{}: sealed as {}", r.task, r.provenance);
}
}