diff --git a/CHANGELOG.md b/CHANGELOG.md index 836bf408d..75aea0500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ incremented upon a breaking change and the patch version will be incremented for ## [dev] - Unreleased **Changed** +- feat/ option to add account into Fuzz Test environment with base64 data ([197](https://github.com/Ackee-Blockchain/trident/pull/197)) - impr/ instead of parsing source code and creating our IDL, read anchor IDL ([196](https://github.com/Ackee-Blockchain/trident/pull/196)) ## [0.7.0] - 2024-08-14 diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 96ca8a9d0..31d0a7975 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -41,6 +41,7 @@ pub mod fuzzing { pub use trident_fuzz::*; pub use solana_program_test::processor; + pub use trident_fuzz::program_test_client_blocking::FuzzingAccountBase64; pub use trident_fuzz::program_test_client_blocking::FuzzingProgram; pub use trident_fuzz::program_test_client_blocking::ProgramEntry; 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 a33c2675a..99b0b8cd9 100644 --- a/crates/client/src/source_code_generators/test_fuzz_generator.rs +++ b/crates/client/src/source_code_generators/test_fuzz_generator.rs @@ -58,7 +58,7 @@ pub fn generate_source_code(idl_instructions: &[Idl]) -> String { #(#fuzzing_programs)* - let mut client = ProgramTestClientBlocking::new(&#programs_array).unwrap(); + let mut client = ProgramTestClientBlocking::new(&#programs_array,&[]).unwrap(); #run_with_runtime 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 7f7558196..3b60c9442 100644 --- a/crates/client/tests/expected_source_codes/expected_test_fuzz.rs +++ b/crates/client/tests/expected_source_codes/expected_test_fuzz.rs @@ -23,7 +23,7 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz processor!(convert_entry!(entry_dummy_example)), ); - let mut client = ProgramTestClientBlocking::new(&[fuzzing_program_dummy_example]).unwrap(); + let mut client = ProgramTestClientBlocking::new(&[fuzzing_program_dummy_example], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_DUMMY_EXAMPLE, &mut client); } diff --git a/crates/fuzz/src/program_test_client_blocking.rs b/crates/fuzz/src/program_test_client_blocking.rs index 55bc73741..7e9031ef4 100644 --- a/crates/fuzz/src/program_test_client_blocking.rs +++ b/crates/fuzz/src/program_test_client_blocking.rs @@ -50,8 +50,34 @@ impl FuzzingProgram { } } +pub struct FuzzingAccountBase64<'a> { + pub address: Pubkey, + pub lamports: u64, + pub owner: Pubkey, + pub data_base64: &'a str, +} + +impl<'a> FuzzingAccountBase64<'a> { + pub fn new( + address: Pubkey, + lamports: u64, + owner: Pubkey, + data_base64: &'a str, + ) -> FuzzingAccountBase64<'a> { + Self { + address, + lamports, + owner, + data_base64, + } + } +} + impl ProgramTestClientBlocking { - pub fn new(program_: &[FuzzingProgram]) -> Result { + pub fn new( + program_: &[FuzzingProgram], + account_: &[FuzzingAccountBase64], + ) -> Result { let mut program_test = ProgramTest::default(); for x in program_ { match x.entry { @@ -74,6 +100,10 @@ impl ProgramTestClientBlocking { } } } + for x in account_ { + program_test.add_account_with_base64_data(x.address, x.lamports, x.owner, x.data_base64) + } + let rt: tokio::runtime::Runtime = Builder::new_current_thread().enable_all().build()?; let ctx = rt.block_on(program_test.start_with_context()); diff --git a/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 99215f188..bf6792c56 100644 --- a/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/arbitrary-custom-types-4/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -31,7 +31,7 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz ); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_arbitrary_custom_types_4]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_arbitrary_custom_types_4], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_ARBITRARY_CUSTOM_TYPES_4, &mut client); } diff --git a/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index f62122775..f292da0f0 100644 --- a/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/arbitrary-limit-inputs-5/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -38,7 +38,7 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz ); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_arbitrary_limit_inputs_5]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_arbitrary_limit_inputs_5], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_ARBITRARY_LIMIT_INPUTS_5, &mut client); } diff --git a/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 4f8b2466a..0fa8fe420 100644 --- a/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/cpi-metaplex-7/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -37,7 +37,7 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz let metaplex = FuzzingProgram::new("metaplex-token-metadata", &mpl_token_metadata::ID, None); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_cpi_metaplex_7, metaplex]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_cpi_metaplex_7, metaplex], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_CPI_METAPLEX_7, &mut client); } diff --git a/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 4b3cbfa24..19601fd66 100644 --- a/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/hello_world/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -16,22 +16,19 @@ struct MyFuzzData; impl FuzzDataBuilder for MyFuzzData {} fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: FuzzData) { - let fuzzing_program_hello_world = FuzzingProgram::new( PROGRAM_NAME_HELLO_WORLD, &PROGRAM_ID_HELLO_WORLD, processor!(convert_entry!(entry_hello_world)), ); - let mut client = ProgramTestClientBlocking::new(&[fuzzing_program_hello_world]).unwrap(); + let mut client = ProgramTestClientBlocking::new(&[fuzzing_program_hello_world], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_HELLO_WORLD, &mut client); } fn main() { - loop { - fuzz_trident ! (fuzz_ix : FuzzInstruction , | fuzz_data : MyFuzzData | { fuzz_iteration (fuzz_data) ; }); } } diff --git a/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 1f38732cb..5d20349a6 100644 --- a/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/incorrect-integer-arithmetic-3/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -30,7 +30,8 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz ); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_incorrect_integer_arithmetic_3]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_incorrect_integer_arithmetic_3], &[]) + .unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_INCORRECT_INTEGER_ARITHMETIC_3, &mut client); } diff --git a/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 3785646c2..68577f2ec 100644 --- a/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/incorrect-ix-sequence-1/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -29,7 +29,7 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz ); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_incorrect_ix_sequence_1]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_incorrect_ix_sequence_1], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_INCORRECT_IX_SEQUENCE_1, &mut client); } diff --git a/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 9b22b0e2e..e811cdd89 100644 --- a/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/simple-cpi-6/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -33,7 +33,8 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz ); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_callee, fuzzing_program_caller]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_callee, fuzzing_program_caller], &[]) + .unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_CALLER, &mut client); } diff --git a/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 11acaad39..8dcab457c 100644 --- a/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/unauthorized-access-2/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -30,7 +30,7 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz ); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_unauthorized_access_2]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_unauthorized_access_2], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_UNAUTHORIZED_ACCESS_2, &mut client); } diff --git a/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs b/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs index 0e0c18aa1..d59c8a55f 100644 --- a/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs +++ b/examples/fuzz-tests/unchecked-arithmetic-0/trident-tests/fuzz_tests/fuzz_0/test_fuzz.rs @@ -37,7 +37,7 @@ fn fuzz_iteration + std::fmt::Display, U>(fuzz_data: Fuzz ); let mut client = - ProgramTestClientBlocking::new(&[fuzzing_program_unchecked_arithmetic_0]).unwrap(); + ProgramTestClientBlocking::new(&[fuzzing_program_unchecked_arithmetic_0], &[]).unwrap(); let _ = fuzz_data.run_with_runtime(PROGRAM_ID_UNCHECKED_ARITHMETIC_0, &mut client); }