huff_neo_test_runner/
types.rs1use crate::internal::HuffFunction;
2use crate::outcome::{Failure, Outcome};
3use alloy_primitives::Log;
4use clap::ValueEnum;
5use comfy_table::{Cell, Color};
6use foundry_evm::traces::SparsedTraceArena;
7use huff_neo_utils::artifact::SourceMapEntry;
8use serde::Serialize;
9use yansi::Paint;
10
11#[derive(Debug, Clone, Serialize)]
13pub struct TestResult {
14 pub name: String,
15 pub return_data: Option<String>,
16 pub gas: u64,
17 pub status: TestStatus,
18 pub revert_reason: Option<String>,
19 pub passed: bool,
21 pub outcome: Outcome,
23 pub failures: Vec<Failure>,
25 #[serde(skip)]
27 pub traces: Option<SparsedTraceArena>,
28 #[serde(skip)]
30 pub logs: Option<Vec<Log>>,
31 #[serde(skip)]
33 pub functions: Vec<HuffFunction>,
34 #[serde(skip)]
36 pub source_map: Option<Vec<SourceMapEntry>>,
37 #[serde(skip)]
39 pub address: Option<alloy_primitives::Address>,
40 #[serde(skip)]
42 pub source_code: Option<String>,
43 #[serde(skip)]
45 pub bytecode: Option<String>,
46 #[serde(skip)]
49 pub source_files: Vec<(String, String)>,
50}
51
52#[derive(Debug, Clone, PartialEq, Serialize)]
54pub enum TestStatus {
55 Success,
56 Revert,
57 Skipped,
58}
59
60#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
62pub enum ReportKind {
63 #[default]
65 List,
66 Table,
68 Json,
70}
71
72impl TestStatus {
73 fn from_passed(passed: bool) -> Self {
75 if passed { Self::Success } else { Self::Revert }
76 }
77
78 pub fn from_outcome(outcome: &Outcome, passed: bool) -> Self {
80 if matches!(outcome, Outcome::Skip { .. }) { Self::Skipped } else { Self::from_passed(passed) }
81 }
82}
83
84impl From<TestStatus> for String {
86 fn from(status: TestStatus) -> Self {
87 match status {
88 TestStatus::Success => Paint::green("PASS").to_string(),
89 TestStatus::Revert => Paint::red("FAIL").to_string(),
90 TestStatus::Skipped => Paint::yellow("SKIP").to_string(),
91 }
92 }
93}
94
95impl From<TestStatus> for Cell {
97 fn from(status: TestStatus) -> Self {
98 match status {
99 TestStatus::Success => Cell::new("PASS").fg(Color::Green),
100 TestStatus::Revert => Cell::new("FAIL").fg(Color::Red),
101 TestStatus::Skipped => Cell::new("SKIP").fg(Color::Yellow),
102 }
103 }
104}