From 855952e01d46e3696c6915389763a33314e63287 Mon Sep 17 00:00:00 2001 From: lukacan Date: Thu, 9 Jan 2025 20:25:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20necessity=20to=20have?= =?UTF-8?q?=20anchor=20as=20dep=20in=20trident=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 10 +- crates/client/src/test_generator.rs | 2 +- crates/client/src/utils.rs | 170 ------------------ .../arbitrary-limit-inputs-5/Trident.toml | 2 +- .../trident-tests/Cargo.toml | 4 +- .../trident-tests/fuzz_0/fuzz_instructions.rs | 6 +- .../trident-tests/Cargo.toml | 1 - .../trident-tests/Cargo.toml | 1 - .../cpi-metaplex-7/trident-tests/Cargo.toml | 1 - .../cpi/simple-cpi-6/trident-tests/Cargo.toml | 1 - examples/hello_world/trident-tests/Cargo.toml | 1 - .../maze0/trident-tests/Cargo.toml | 2 - 12 files changed, 11 insertions(+), 190 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c22cd2ee..31c9a127 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -688,9 +688,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.24" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9560b07a799281c7e0958b9296854d6fafd4c5f31444a7e5bb1ad6dde5ccf1bd" +checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" dependencies = [ "clap_builder", "clap_derive", @@ -698,9 +698,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.24" +version = "4.5.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "874e0dd3eb68bf99058751ac9712f622e61e6f393a94f7128fa26e3f02f5c7cd" +checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" dependencies = [ "anstream", "anstyle", @@ -3965,7 +3965,7 @@ dependencies = [ [[package]] name = "trident-svm" version = "0.1.0" -source = "git+https://github.com/Ackee-Blockchain/trident-svm#efc43ed89d9505abb34c663704f9abd748abb40e" +source = "git+https://github.com/Ackee-Blockchain/trident-svm#2da36a408b386b1ff5fd5c1e9d50302e56a1dce1" dependencies = [ "bincode", "serde", diff --git a/crates/client/src/test_generator.rs b/crates/client/src/test_generator.rs index 9385869e..e1e765bc 100644 --- a/crates/client/src/test_generator.rs +++ b/crates/client/src/test_generator.rs @@ -188,7 +188,7 @@ impl TestGenerator { create_file(&self.root, &trident_toml_path, trident_toml_content).await?; add_bin_target(&fuzz_tests_manifest_path, &new_fuzz_test, &new_bin_target).await?; - initialize_fuzz_tests_manifest( + update_fuzz_tests_manifest( &self.versions_config, &self.program_packages, &fuzz_dir_path, diff --git a/crates/client/src/utils.rs b/crates/client/src/utils.rs index 28a6f4e3..123eb6f0 100644 --- a/crates/client/src/utils.rs +++ b/crates/client/src/utils.rs @@ -148,129 +148,6 @@ pub fn ensure_table<'a>(content: &'a mut Value, table_name: &str) -> Result<&'a .as_table_mut() .ok_or(Error::ParsingCargoTomlDependenciesFailed) } -// #[throws] -// pub async fn initialize_package_metadata( -// packages: &[Package], -// versions_config: &TridentVersionsConfig, -// ) { -// for package in packages { -// let manifest_path = package.manifest_path.as_std_path(); -// let cargo_toml_content = fs::read_to_string(&manifest_path).await?; -// let mut cargo_toml: Value = toml::from_str(&cargo_toml_content)?; - -// // Ensure the 'trident-fuzzing' feature exists with the required dependency. -// let features_table = ensure_table(&mut cargo_toml, "features")?; - -// features_table.insert( -// "trident-fuzzing".to_string(), -// Value::Array(vec![Value::String("dep:trident-fuzz".to_string())]), -// ); - -// // Ensure the required dependencies are present in the 'dependencies' section. -// let dependencies_table = ensure_table(&mut cargo_toml, "dependencies")?; - -// // Add 'trident-derive-accounts-snapshots' dependency in table format. -// dependencies_table.insert( -// "trident-derive-accounts-snapshots".to_string(), -// Value::Table({ -// let mut snapshots_table = toml::Table::new(); -// snapshots_table.insert( -// "version".to_string(), -// Value::String(versions_config.trident_derive_accounts_snapshots.clone()), -// ); -// snapshots_table -// }), -// ); - -// // Add 'trident-fuzz' dependency with specified attributes if not present. -// dependencies_table.insert( -// "trident-fuzz".to_string(), -// Value::Table({ -// let mut trident_fuzz_table = toml::Table::new(); -// trident_fuzz_table.insert( -// "version".to_string(), -// Value::String(versions_config.trident_fuzz.clone()), -// ); -// trident_fuzz_table.insert("optional".to_string(), Value::Boolean(true)); -// trident_fuzz_table -// }), -// ); - -// // Write the updated Cargo.toml back to the file. -// fs::write(&manifest_path, toml::to_string(&cargo_toml).unwrap()).await?; -// } -// } - -// #[throws] -// pub async fn update_package_metadata( -// packages: &[Package], -// versions_config: &TridentVersionsConfig, -// ) { -// for package in packages { -// let manifest_path = package.manifest_path.as_std_path(); -// let cargo_toml_content = fs::read_to_string(&manifest_path).await?; -// let mut cargo_toml: Value = toml::from_str(&cargo_toml_content)?; - -// // Ensure the 'trident-fuzzing' feature exists with the required dependency. -// let features_table = ensure_table(&mut cargo_toml, "features")?; -// if features_table.contains_key("trident-fuzzing") { -// println!( -// "{SKIP} 'trident-fuzzing' feature already exists in package: {}", -// package.name -// ); -// } else { -// features_table.insert( -// "trident-fuzzing".to_string(), -// Value::Array(vec![Value::String("dep:trident-fuzz".to_string())]), -// ); -// } - -// // Ensure the required dependencies are present in the 'dependencies' section. -// let dependencies_table = ensure_table(&mut cargo_toml, "dependencies")?; - -// // Add 'trident-derive-accounts-snapshots' dependency in table format. -// if dependencies_table.contains_key("trident-derive-accounts-snapshots") { -// println!("{SKIP} 'trident-derive-accounts-snapshots' dependency already exists in package: {}", package.name); -// } else { -// dependencies_table.insert( -// "trident-derive-accounts-snapshots".to_string(), -// Value::Table({ -// let mut snapshots_table = toml::Table::new(); -// snapshots_table.insert( -// "version".to_string(), -// Value::String(versions_config.trident_derive_accounts_snapshots.clone()), -// ); -// snapshots_table -// }), -// ); -// } - -// // Add 'trident-fuzz' dependency with specified attributes if not present. -// if dependencies_table.contains_key("trident-fuzz") { -// println!( -// "{SKIP} 'trident-fuzz' dependency already exists in package: {}", -// package.name -// ); -// } else { -// dependencies_table.insert( -// "trident-fuzz".to_string(), -// Value::Table({ -// let mut trident_fuzz_table = toml::Table::new(); -// trident_fuzz_table.insert( -// "version".to_string(), -// Value::String(versions_config.trident_fuzz.clone()), -// ); -// trident_fuzz_table.insert("optional".to_string(), Value::Boolean(true)); -// trident_fuzz_table -// }), -// ); -// } - -// // Write the updated Cargo.toml back to the file. -// fs::write(&manifest_path, toml::to_string(&cargo_toml).unwrap()).await?; -// } -// } - // #[throws] // pub async fn add_workspace_member(root: &Path, member: &str) { // // Construct the path to the Cargo.toml file @@ -341,53 +218,6 @@ pub async fn add_bin_target(cargo_path: &PathBuf, name: &str, path: &str) { fs::write(cargo_path, updated_toml).await?; } -#[throws] -pub async fn initialize_fuzz_tests_manifest( - versions_config: &TridentVersionsConfig, - packages: &[Package], - cargo_dir: &PathBuf, -) { - let cargo_path = cargo_dir.join("Cargo.toml"); - - let cargo_toml_content = fs::read_to_string(&cargo_path).await?; - let mut cargo_toml: Value = toml::from_str(&cargo_toml_content)?; - - // Ensure the required dependencies are present in the 'dependencies' section. - let dependencies_table = ensure_table(&mut cargo_toml, "dependencies")?; - - // Add 'trident-fuzz' dependency in table format. - dependencies_table.entry("trident-fuzz").or_insert_with(|| { - let mut trident_client = toml::Table::new(); - trident_client.insert( - "version".to_string(), - Value::String(versions_config.trident_fuzz.clone()), - ); - Value::Table(trident_client) - }); - - for package in packages { - let manifest_path = package.manifest_path.parent().unwrap().as_std_path(); - let relative_path = pathdiff::diff_paths(manifest_path, cargo_dir).unwrap(); - - let relative_path_str = relative_path.to_str().unwrap_or_default(); - - let package_name = package.name.clone(); - dependencies_table.insert( - package_name, - Value::Table({ - let mut package_entry = toml::Table::new(); - package_entry.insert( - "path".to_string(), - Value::String(relative_path_str.to_owned()), - ); - package_entry - }), - ); - } - - fs::write(cargo_path, toml::to_string(&cargo_toml).unwrap()).await?; -} - #[throws] pub async fn update_fuzz_tests_manifest( versions_config: &TridentVersionsConfig, diff --git a/examples/common_issues/arbitrary-limit-inputs-5/Trident.toml b/examples/common_issues/arbitrary-limit-inputs-5/Trident.toml index b040c243..3369f70a 100644 --- a/examples/common_issues/arbitrary-limit-inputs-5/Trident.toml +++ b/examples/common_issues/arbitrary-limit-inputs-5/Trident.toml @@ -4,7 +4,7 @@ fuzzing_with_stats = true [honggfuzz] -iterations = 10000 +iterations = 100 timeout = 20 exit_upon_crash = false # threads = 1 diff --git a/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/Cargo.toml b/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/Cargo.toml index 938cd2a8..b6d8ee1f 100644 --- a/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/Cargo.toml +++ b/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/Cargo.toml @@ -14,9 +14,7 @@ edition = "2021" arbitrary = "1.3.0" borsh = "1.5.3" solana-sdk = "~2.0" -anchor-lang = "0.30.1" -anchor-spl = "0.30.1" - +spl-token = "5" [dependencies.trident-fuzz] path = "../../../../crates/fuzz" diff --git a/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/fuzz_0/fuzz_instructions.rs b/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/fuzz_0/fuzz_instructions.rs index ab8f0ffc..ee97dcc9 100644 --- a/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/fuzz_0/fuzz_instructions.rs +++ b/examples/common_issues/arbitrary-limit-inputs-5/trident-tests/fuzz_0/fuzz_instructions.rs @@ -1,5 +1,5 @@ -use anchor_lang::AccountDeserialize; use borsh::{BorshDeserialize, BorshSerialize}; +use solana_sdk::program_pack::Pack; use trident_fuzz::fuzzing::*; /// FuzzInstruction contains all available Instructions. @@ -364,13 +364,13 @@ impl IxOps for WithdrawUnlocked { let recipient = pre_ix[0].pubkey(); let recipient_token_account_pre = - match anchor_spl::token::TokenAccount::try_deserialize(&mut pre_ix[1].data()) { + match spl_token::state::Account::unpack(pre_ix[1].data()) { Ok(recipient_token_account_pre) => recipient_token_account_pre, Err(_) => return Ok(()), }; let recipient_token_account_post = - match anchor_spl::token::TokenAccount::try_deserialize(&mut post_ix[1].data()) { + match spl_token::state::Account::unpack(post_ix[1].data()) { Ok(recipient_token_account_post) => recipient_token_account_post, Err(_) => return Ok(()), }; diff --git a/examples/common_issues/incorrect-ix-sequence-1/trident-tests/Cargo.toml b/examples/common_issues/incorrect-ix-sequence-1/trident-tests/Cargo.toml index 31799cfa..22f38a49 100644 --- a/examples/common_issues/incorrect-ix-sequence-1/trident-tests/Cargo.toml +++ b/examples/common_issues/incorrect-ix-sequence-1/trident-tests/Cargo.toml @@ -14,7 +14,6 @@ edition = "2021" arbitrary = "1.3.0" borsh = "1.5.3" solana-sdk = "~2.0" -anchor-lang = "0.30.1" [dependencies.trident-fuzz] path = "../../../../crates/fuzz" diff --git a/examples/common_issues/unchecked-arithmetic-0/trident-tests/Cargo.toml b/examples/common_issues/unchecked-arithmetic-0/trident-tests/Cargo.toml index 04c9d7ca..96eccca7 100644 --- a/examples/common_issues/unchecked-arithmetic-0/trident-tests/Cargo.toml +++ b/examples/common_issues/unchecked-arithmetic-0/trident-tests/Cargo.toml @@ -14,7 +14,6 @@ edition = "2021" arbitrary = "1.3.0" borsh = "1.5.3" solana-sdk = "~2.0" -anchor-lang = "0.29.0" [dependencies.trident-fuzz] path = "../../../../crates/fuzz" diff --git a/examples/cpi/cpi-metaplex-7/trident-tests/Cargo.toml b/examples/cpi/cpi-metaplex-7/trident-tests/Cargo.toml index 8e0d0c99..c09e8cd6 100644 --- a/examples/cpi/cpi-metaplex-7/trident-tests/Cargo.toml +++ b/examples/cpi/cpi-metaplex-7/trident-tests/Cargo.toml @@ -14,7 +14,6 @@ edition = "2021" arbitrary = "1.3.0" borsh = "1.5.3" solana-sdk = "~2.0" -anchor-lang = "0.30.1" [dependencies.trident-fuzz] path = "../../../../crates/fuzz" diff --git a/examples/cpi/simple-cpi-6/trident-tests/Cargo.toml b/examples/cpi/simple-cpi-6/trident-tests/Cargo.toml index 7f5cc2bc..c880a84a 100644 --- a/examples/cpi/simple-cpi-6/trident-tests/Cargo.toml +++ b/examples/cpi/simple-cpi-6/trident-tests/Cargo.toml @@ -14,7 +14,6 @@ edition = "2021" arbitrary = "1.3.0" borsh = "1.5.3" solana-sdk = "~2.0" -anchor-lang = "0.30.1" [dependencies.trident-fuzz] path = "../../../../crates/fuzz" diff --git a/examples/hello_world/trident-tests/Cargo.toml b/examples/hello_world/trident-tests/Cargo.toml index 93230603..e385e444 100644 --- a/examples/hello_world/trident-tests/Cargo.toml +++ b/examples/hello_world/trident-tests/Cargo.toml @@ -14,7 +14,6 @@ edition = "2021" arbitrary = "1.3.0" borsh = "1.5.3" solana-sdk = "~2.0" -anchor-lang = "0.30.1" [dependencies.trident-fuzz] path = "../../../crates/fuzz" diff --git a/examples/trident-benchmark/maze0/trident-tests/Cargo.toml b/examples/trident-benchmark/maze0/trident-tests/Cargo.toml index 2b8831c5..eb5c9fe2 100644 --- a/examples/trident-benchmark/maze0/trident-tests/Cargo.toml +++ b/examples/trident-benchmark/maze0/trident-tests/Cargo.toml @@ -14,8 +14,6 @@ edition = "2021" arbitrary = "1.3.0" borsh = "1.5.3" solana-sdk = "~2.0" -anchor-lang = "0.29.0" - [dependencies.trident-fuzz] path = "../../../../crates/fuzz"