From 8cd1a0ea8bdd2ff357b129dd7d7981ed5dfbb851 Mon Sep 17 00:00:00 2001 From: lukacan Date: Thu, 14 Nov 2024 14:01:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Fix=20case=20conversion=20for=20pro?= =?UTF-8?q?gram=20packages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/anchor_idl.rs | 11 +++-------- .../test_fuzz_generator.rs | 11 +++++------ .../expected_source_codes/expected_test_fuzz.rs | 16 ++++++++-------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/crates/client/src/anchor_idl.rs b/crates/client/src/anchor_idl.rs index 9dd397cb5..3cfe44af1 100644 --- a/crates/client/src/anchor_idl.rs +++ b/crates/client/src/anchor_idl.rs @@ -1,6 +1,5 @@ use anchor_lang_idl_spec::Idl; use cargo_metadata::Package; -use convert_case::{Case, Casing}; use std::error::Error; use std::fs::{self, File}; @@ -13,13 +12,9 @@ pub fn load_idls( ) -> Result, Box> { let mut idls = Vec::new(); - let package_names: Vec = program_packages + let mut package_names = program_packages .iter() - .map(|package| { - let name = &package.name; - name.to_case(Case::Snake) - }) - .collect(); + .map(|package| package.name.replace("-", "_")); // Read the directory and iterate over each entry for entry in fs::read_dir(dir_path)? { @@ -34,7 +29,7 @@ pub fn load_idls( let package_name = idl_name_str.trim_end_matches(".json"); // Check if the package name is in the list of known packages - if package_names.iter().any(|name| name == package_name) { + if package_names.any(|package| package == package_name) { // Open the file in read-only mode let mut file = File::open(&path)?; diff --git a/crates/client/src/source_code_generators/test_fuzz_generator.rs b/crates/client/src/source_code_generators/test_fuzz_generator.rs index 1ca139d43..019326ce0 100644 --- a/crates/client/src/source_code_generators/test_fuzz_generator.rs +++ b/crates/client/src/source_code_generators/test_fuzz_generator.rs @@ -1,5 +1,4 @@ use anchor_lang_idl_spec::Idl; -use convert_case::{Case, Casing}; use quote::{format_ident, ToTokens}; use syn::parse_quote; @@ -63,7 +62,7 @@ fn get_program_names(idl_instructions: &[Idl]) -> Vec { .iter() .map(|idl| { let program_name = &idl.metadata.name; - let program_name_upper = idl.metadata.name.to_case(Case::UpperSnake); + let program_name_upper = &idl.metadata.name; let program_name_ident = format_ident!("PROGRAM_NAME_{}", program_name_upper); parse_quote!(const #program_name_ident: &str = #program_name;) @@ -75,8 +74,8 @@ fn get_program_imports(idl_instructions: &[Idl]) -> Vec { idl_instructions .iter() .flat_map(|idl| { - let program_name = idl.metadata.name.to_case(Case::Snake); - let program_name_upper = idl.metadata.name.to_case(Case::UpperSnake); + let program_name = &idl.metadata.name; + let program_name_upper = &idl.metadata.name; let program_name_ident = format_ident!("{}", program_name); let program_entry_ident = format_ident!("entry_{}", program_name); let program_id_name_ident = format_ident!("PROGRAM_ID_{}", program_name_upper); @@ -97,8 +96,8 @@ fn get_fuzzing_programs(idl_instructions: &[Idl]) -> (Vec, syn::ExprA let fuzzing_programs: Vec = idl_instructions .iter() .map(|idl| { - let program_name = idl.metadata.name.to_case(Case::Snake); - let program_name_upper = idl.metadata.name.to_case(Case::UpperSnake); + let program_name = &idl.metadata.name; + let program_name_upper = &idl.metadata.name; let fuzzing_program_name_ident = format_ident!("fuzzing_program_{}", program_name); let program_id_name_ident = format_ident!("PROGRAM_ID_{}", program_name_upper); let program_name_ident = format_ident!("PROGRAM_NAME_{}", program_name_upper); diff --git a/crates/client/tests/expected_source_codes/expected_test_fuzz.rs b/crates/client/tests/expected_source_codes/expected_test_fuzz.rs index 0fe59e7ef..016d51ad4 100644 --- a/crates/client/tests/expected_source_codes/expected_test_fuzz.rs +++ b/crates/client/tests/expected_source_codes/expected_test_fuzz.rs @@ -1,12 +1,12 @@ use trident_client::fuzzing::*; mod fuzz_instructions; use dummy_2::entry as entry_dummy_2; -use dummy_2::ID as PROGRAM_ID_DUMMY_2; +use dummy_2::ID as PROGRAM_ID_dummy_2; use dummy_example::entry as entry_dummy_example; -use dummy_example::ID as PROGRAM_ID_DUMMY_EXAMPLE; +use dummy_example::ID as PROGRAM_ID_dummy_example; use fuzz_instructions::FuzzInstruction; -const PROGRAM_NAME_DUMMY_2: &str = "dummy_2"; -const PROGRAM_NAME_DUMMY_EXAMPLE: &str = "dummy_example"; +const PROGRAM_NAME_dummy_2: &str = "dummy_2"; +const PROGRAM_NAME_dummy_example: &str = "dummy_example"; struct InstructionsSequence; /// Define instruction sequences for invocation. /// `pre` runs at the start, `middle` in the middle, and `post` at the end. @@ -27,13 +27,13 @@ fn fuzz_iteration + std::fmt::Display, U>( config: &Config, ) { let fuzzing_program_dummy_2 = FuzzingProgram::new( - PROGRAM_NAME_DUMMY_2, - &PROGRAM_ID_DUMMY_2, + PROGRAM_NAME_dummy_2, + &PROGRAM_ID_dummy_2, processor!(convert_entry!(entry_dummy_2)), ); let fuzzing_program_dummy_example = FuzzingProgram::new( - PROGRAM_NAME_DUMMY_EXAMPLE, - &PROGRAM_ID_DUMMY_EXAMPLE, + PROGRAM_NAME_dummy_example, + &PROGRAM_ID_dummy_example, processor!(convert_entry!(entry_dummy_example)), ); let mut client = ProgramTestClientBlocking::new(