diff --git a/crates/cli/src/command/init.rs b/crates/cli/src/command/init.rs index 467f4e75..efe4b470 100644 --- a/crates/cli/src/command/init.rs +++ b/crates/cli/src/command/init.rs @@ -8,6 +8,7 @@ use crate::{_discover, show_howto}; pub const ANCHOR_TOML: &str = "Anchor.toml"; pub const TRIDENT_TOML: &str = "Trident.toml"; +pub const SKIP: &str = "\x1b[33mSkip\x1b[0m"; #[throws] pub async fn init(force: bool) { @@ -25,7 +26,7 @@ pub async fn init(force: bool) { } else { let root_path = Path::new(&root).join(TRIDENT_TOML); if root_path.exists() { - println!("It looks like Trident is already initialized as the Trident.toml was found in {} directory.",root); + println!("{SKIP} It looks like Trident is already initialized as the Trident.toml was found in {} directory.",root); } else { generator.initialize().await?; } diff --git a/crates/fuzz/derive/accounts_snapshots/src/lib.rs b/crates/fuzz/derive/accounts_snapshots/src/lib.rs index 8712dcb3..5dfc8192 100644 --- a/crates/fuzz/derive/accounts_snapshots/src/lib.rs +++ b/crates/fuzz/derive/accounts_snapshots/src/lib.rs @@ -716,13 +716,29 @@ fn generate(accs: &TridentAccountsStruct) -> proc_macro2::TokenStream { quote! { #field_name } }); - quote! { - #[cfg(feature = "trident-fuzzing")] - pub mod #module_name{ - #[cfg(target_os = "solana")] - compile_error!("Do not use fuzzing with Production Code"); - use super::*; - impl<'info>trident_fuzz::fuzz_deserialize::FuzzDeserialize<'info> for #snapshot_name<'info> { + // CHECK IF STRUCT HAS ANY FIELDS + let has_fields = !accs.0.fields.is_empty(); + + // USE PHANTOMDATA IF NO FIELDS PRESENT + let struct_definition = if has_fields { + quote! { + pub struct #snapshot_name<'info> { + #(#snapshot_fields)* + } + } + } else { + quote! { + pub struct #snapshot_name<'info> { + #[allow(dead_code)] + _phantom: std::marker::PhantomData<&'info ()>, + } + } + }; + + // IF IT HAS FIELDS JUST FOLLOW STANDARD BEHAVIOR + let deserialize_impl = if has_fields { + quote! { + impl<'info> trident_fuzz::fuzz_deserialize::FuzzDeserialize<'info> for #snapshot_name<'info> { fn deserialize_option( _program_id: &anchor_lang::prelude::Pubkey, accounts: &mut &'info [Option>], @@ -736,10 +752,32 @@ fn generate(accs: &TridentAccountsStruct) -> proc_macro2::TokenStream { }) } } - pub struct #snapshot_name<'info> { - #(#snapshot_fields)* + } + } else { + // IF IT HAS NO FIELDS RETURN THE PHANTOM DATA + quote! { + impl<'info> trident_fuzz::fuzz_deserialize::FuzzDeserialize<'info> for #snapshot_name<'info> { + fn deserialize_option( + _program_id: &anchor_lang::prelude::Pubkey, + _accounts: &mut &'info [Option>], + ) -> core::result::Result { + Ok(Self { _phantom: std::marker::PhantomData }) + } } } + }; + + quote! { + #[cfg(feature = "trident-fuzzing")] + pub mod #module_name { + #[cfg(target_os = "solana")] + compile_error!("Do not use fuzzing with Production Code"); + use super::*; + + #deserialize_impl + + #struct_definition + } } }