Skip to content

Commit

Permalink
🔥 Remove necessity to have anchor as dep in trident tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacan committed Jan 9, 2025
1 parent 7d2c4a8 commit 855952e
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 190 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/client/src/test_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
170 changes: 0 additions & 170 deletions crates/client/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
fuzzing_with_stats = true

[honggfuzz]
iterations = 10000
iterations = 100
timeout = 20
exit_upon_crash = false
# threads = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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(()),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion examples/cpi/cpi-metaplex-7/trident-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion examples/cpi/simple-cpi-6/trident-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion examples/hello_world/trident-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions examples/trident-benchmark/maze0/trident-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 855952e

Please sign in to comment.