trident_fuzz/
fuzz_trident.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#[macro_export]
macro_rules! fuzz_trident {
    ($ix:ident: $ix_dty:ident , |$buf:ident: $dty:ident| $body:block) => {
        if cfg!(honggfuzz) {
            loop {
                fuzz_honggfuzz(|$buf| {
                    let mut $buf: FuzzData<$ix_dty, _> = {
                        use arbitrary::Unstructured;

                        let mut buf = Unstructured::new($buf);
                        if let Ok(fuzz_data) = build_ix_fuzz_data($dty {}, &mut buf) {
                            fuzz_data
                        } else {
                            return;
                        }
                    };
                    $body
                });
            }
        } else if cfg!(afl) {
            fuzz_afl(true, |$buf| {
                let mut $buf: FuzzData<$ix_dty, _> = {
                    use arbitrary::Unstructured;

                    let mut buf = Unstructured::new($buf);
                    if let Ok(fuzz_data) = build_ix_fuzz_data($dty {}, &mut buf) {
                        fuzz_data
                    } else {
                        return;
                    }
                };
                $body
            });
        } else {
        }
    };
}

/// Prints the details of a given account in a pretty-printed format.
///
/// This macro takes a single argument, which is an expression referring to the account
/// you want to print. The account data structure must implement or derive the [`Debug`]
/// trait for this macro to work, as it relies on `std::fmt::Debug` for formatting.
///
/// # Examples
///
/// ```rust,ignore
/// use trident_client::fuzzing::show_account;
///
/// #[derive(Debug)]
/// #[account]
/// struct Escrow {
///     recipeint: Pubkey,
///     id: u32,
///     balance: f64,
///     name: String,
/// }
///
/// fn check(
///     &self,
///     pre_ix: Self::IxSnapshot,
///     post_ix: Self::IxSnapshot,
///     ix_data: Self::IxData,
/// ) -> Result<(), FuzzingError> {
///     if let Some(escrow) = pre_ix.escrow{
///         show_account!(escrow);
///     }
/// }
/// ```
///
/// # Requirements
///
/// The `account` passed to `show_account!` must implement or derive the [`Debug`] trait.
/// Attempting to use this macro with a type that does not meet this requirement will
/// result in a compilation error.
#[macro_export]
macro_rules! show_account {
    ($account:expr) => {
        eprintln!("{:#?}", $account);
    };
}