Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix types.rs file generation #265

Merged
merged 2 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/client/tests/test_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ async fn verify_instructions(template: &Template) {
let generated_instructions = template.get_instructions();

for (name, generated_content) in generated_instructions {
let expected_path =
construct_path(&format!("fuzz_template/instructions/{}.rs", name));
let expected_path = construct_path(&format!("fuzz_template/instructions/{}.rs", name));
let expected_content = fs::read_to_string(&expected_path)?;
let formatted_content = Commander::format_program_code_nightly(&generated_content).await?;

Expand Down Expand Up @@ -82,8 +81,7 @@ async fn verify_transactions(template: &Template) {
let generated_transactions = template.get_transactions();

for (name, generated_content) in generated_transactions {
let expected_path =
construct_path(&format!("fuzz_template/transactions/{}.rs", name));
let expected_path = construct_path(&format!("fuzz_template/transactions/{}.rs", name));
let expected_content = fs::read_to_string(&expected_path)?;
let formatted_content = Commander::format_program_code_nightly(&generated_content).await?;

Expand Down
18 changes: 16 additions & 2 deletions crates/template/src/template_getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,30 @@ impl Template {
}
pub fn get_custom_types(&self) -> String {
let custom_types = self.custom_types.clone();
let module_definition: syn::File = parse_quote! {
let common_header = quote::quote! {
use borsh::{BorshDeserialize, BorshSerialize};
use trident_fuzz::fuzzing::*;

/// File containing all custom types which can be used in transactions and instructions
/// or invariant checks.
///
/// You can create your own types here and use them in transactions and instructions.
};

let module_definition: syn::File = match custom_types.len() {
0 => parse_quote! {
#common_header

#[derive(Arbitrary, Debug, BorshDeserialize, BorshSerialize, Clone)]
pub struct ExampleType {
example_data: u8,
}
},
_ => parse_quote! {
#common_header

#(#custom_types)*
#(#custom_types)*
},
};
module_definition.into_token_stream().to_string()
}
Expand Down
Loading