Skip to main content

trellis_testing/
output_ledger_dump.rs

1use core::fmt::Write;
2
3use trellis_core::OutputPayload;
4
5use crate::OutputLedger;
6
7impl OutputLedger {
8    /// Returns deterministic debug output for output ledger snapshots.
9    pub fn to_debug_string(&self) -> String {
10        self.to_redacted_debug_string(|value| format!("{value:?}"))
11    }
12
13    /// Returns deterministic redacted debug output for output ledger snapshots.
14    pub fn to_redacted_debug_string(&self, redact: impl Fn(&OutputPayload) -> String) -> String {
15        let mut out = String::new();
16        writeln!(&mut out, "OutputLedger").expect("writing to String cannot fail");
17
18        writeln!(&mut out, "Outputs:").expect("writing to String cannot fail");
19        for (key, snapshot) in &self.outputs {
20            let state = snapshot
21                .state
22                .as_ref()
23                .map(&redact)
24                .unwrap_or_else(|| "None".to_owned());
25            writeln!(
26                &mut out,
27                "  key={key:?} scope={:?} tx={:?} revision={:?} cleared={} state={}",
28                snapshot.scope, snapshot.transaction_id, snapshot.revision, snapshot.cleared, state
29            )
30            .expect("writing to String cannot fail");
31        }
32
33        writeln!(&mut out, "Closed scopes: {:?}", self.closed_scopes)
34            .expect("writing to String cannot fail");
35        writeln!(&mut out, "Errors: {:?}", self.errors).expect("writing to String cannot fail");
36        out
37    }
38}