//! 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); } }