Skip to content

Commit 2cef53f

Browse files
committed
🔥 Remove AccountsSnapshots
1 parent 061cbc9 commit 2cef53f

File tree

74 files changed

+5210
-2924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5210
-2924
lines changed

Cargo.lock

Lines changed: 350 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/src/howto.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,7 @@ For more info about Honggfuzz installation check https://github.com/rust-fuzz/ho
2020
trident init
2121
```
2222

23-
- Derive ***AccountsSnapshots*** for each account context in the program:
24-
25-
```rust
26-
use trident_derive_accounts_snapshots::AccountsSnapshots;
27-
28-
#[derive(AccountsSnapshots, Accounts)]
29-
pub struct InitializeContext<'info> {
30-
// ...
31-
}
32-
33-
```
34-
35-
- Link Account Context Aliases in the ***fuzz_instructions.rs*** with desired Snapshots
36-
37-
```rust
38-
use hello_world::trident_fuzz_initialize_context_snapshot::InitializeContextAlias;
39-
type InitializeFnSnapshot<'info> = InitializeContextAlias<'info>;
40-
```
23+
## Write Fuzz Test
4124

4225
- Implement the ***todo!*** placeholders in ***fuzz_instructions.rs*** based on the provided descriptions.
4326

crates/client/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ description = "The trident_client crate helps you build and deploy an Anchor pro
1313
trident-derive-displayix = { path = "../fuzz/derive/display_ix", version = "0.0.3" }
1414
trident-derive-fuzz-test-executor = { path = "../fuzz/derive/fuzz_test_executor", version = "0.0.3" }
1515
trident-fuzz = { path = "../fuzz", version = "0.2.0" }
16-
trident-derive-accounts-snapshots = { path = "../fuzz/derive/accounts_snapshots", version = "0.0.2" }
1716
# ANCHOR
1817
# INFO: Anchor-spl is here as dependency only to activate the idl-build feature, so that
1918
# users do not have to do it manually in their program's Cargo.toml

crates/client/config.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"trident_fuzz": "0.2.0",
3-
"trident_derive_accounts_snapshots": "0.0.2",
42
"trident_client": "0.8.0"
53
}

crates/client/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ pub mod fuzzing {
88
/// anchor_lang
99
pub use anchor_lang;
1010
pub use anchor_lang::solana_program::hash::Hash;
11+
pub use anchor_lang::AccountDeserialize;
1112
pub use anchor_lang::InstructionData;
1213
pub use anchor_lang::Key;
1314
pub use anchor_lang::ToAccountInfo;
1415
pub use anchor_lang::ToAccountMetas;
1516

1617
/// solana_sdk
1718
pub use solana_sdk;
19+
pub use solana_sdk::account::AccountSharedData;
20+
pub use solana_sdk::account::ReadableAccount;
1821
pub use solana_sdk::account_info::AccountInfo;
1922
pub use solana_sdk::entrypoint::ProcessInstruction;
2023
pub use solana_sdk::instruction::AccountMeta;
2124
pub use solana_sdk::instruction::Instruction;
25+
pub use solana_sdk::native_token::LAMPORTS_PER_SOL;
2226
pub use solana_sdk::pubkey::Pubkey;
2327
pub use solana_sdk::signer::keypair::Keypair;
2428
pub use solana_sdk::signer::Signer;
@@ -60,6 +64,7 @@ pub mod fuzzing {
6064
pub use trident_fuzz::ix_ops::IxOps;
6165
pub use trident_fuzz::program_test_client_blocking::ProgramTestClientBlocking;
6266
pub use trident_fuzz::snapshot::Snapshot;
67+
pub use trident_fuzz::snapshot::SnapshotAccount;
6368
pub use trident_fuzz::transaction_executor::TransactionExecutor;
6469

6570
pub use std::cell::RefCell;

crates/client/src/source_code_generators/fuzz_instructions_generator.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub fn generate_source_code(idls: &[Idl]) -> String {
1111
let mut all_instruction_inputs: Vec<syn::ItemStruct> = Vec::new();
1212
let mut all_instructions_ixops_impls: Vec<syn::ItemImpl> = Vec::new();
1313
let mut all_fuzz_accounts: Vec<syn::FnArg> = Vec::new();
14-
let mut all_snapshot_types: Vec<syn::ItemType> = Vec::new();
1514

1615
// Mappings for instructions and accounts
1716
let mut instructions_mappings: HashMap<String, u8> = HashMap::new();
@@ -25,19 +24,13 @@ pub fn generate_source_code(idls: &[Idl]) -> String {
2524
all_instructions.extend(get_instruction_variants(idl, &instructions_mappings));
2625
all_instruction_inputs.extend(get_instruction_inputs(idl, &instructions_mappings));
2726
all_instructions_ixops_impls.extend(get_instruction_ixops(idl, &instructions_mappings));
28-
all_snapshot_types.extend(get_snapshot_types(idl, &instructions_mappings));
2927
all_fuzz_accounts.extend(get_fuzz_accounts(idl, &accounts_mappings));
3028
}
3129

3230
// Define the Rust module with all generated code
3331
let module_definition = quote! {
3432
use trident_client::fuzzing::*;
3533

36-
/// Link the relevant Account Context Alias from the program.
37-
/// Aliases are generated by the `AccountsSnapshots` macro.
38-
#(#all_snapshot_types)*
39-
40-
4134
/// FuzzInstruction contains all available Instructions.
4235
/// Below, the instruction arguments (accounts and data) are defined.
4336
#[derive(Arbitrary, DisplayIx, FuzzTestExecutor)]
@@ -124,31 +117,6 @@ fn get_instruction_variants(
124117
})
125118
}
126119

127-
// Generate snapshot types for each instruction
128-
fn get_snapshot_types(idl: &Idl, instruction_mappings: &HashMap<String, u8>) -> Vec<syn::ItemType> {
129-
let program_name = idl.metadata.name.to_case(Case::UpperCamel);
130-
131-
idl.instructions
132-
.iter()
133-
.fold(Vec::new(), |mut snapshot_types, instruction| {
134-
let mut instruction_name = instruction.name.to_case(Case::UpperCamel);
135-
let count = instruction_mappings.get(&instruction_name).unwrap_or(&1);
136-
137-
// Append the program name if the instruction name is not unique
138-
if *count > 1 {
139-
instruction_name.push_str(&program_name);
140-
}
141-
142-
let ix_snapshot: syn::Ident = format_ident!("{}Snapshot", &instruction_name);
143-
let ix_alias: syn::Ident = format_ident!("{}Alias", &instruction_name);
144-
145-
let snapshot_type: syn::ItemType =
146-
parse_quote! (type #ix_snapshot<'info> = #ix_alias<'info>;);
147-
snapshot_types.push(snapshot_type);
148-
snapshot_types
149-
})
150-
}
151-
152120
// Generate input structures for each instruction
153121
fn get_instruction_inputs(
154122
idl: &Idl,
@@ -255,7 +223,6 @@ fn get_instruction_ixops(
255223

256224
let instruction_ident_name_modified: syn::Ident =
257225
format_ident!("{}", &instruction_name);
258-
let ix_snapshot: syn::Ident = format_ident!("{}Snapshot", &instruction_name);
259226

260227
// Map arguments to their types
261228
let parameters = instruction
@@ -299,7 +266,6 @@ fn get_instruction_ixops(
299266
impl<'info> IxOps<'info> for #instruction_ident_name_modified {
300267
type IxData = #module_name::instruction::#instruction_ident_name;
301268
type IxAccounts = FuzzAccounts;
302-
type IxSnapshot = #ix_snapshot<'info>;
303269

304270
/// Definition of the program ID that the Instruction is associated with.
305271
fn get_program_id(&self) -> solana_sdk::pubkey::Pubkey {

crates/client/src/test_generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl TestGenerator {
7272

7373
update_gitignore(&self.root, CARGO_TARGET_DIR_DEFAULT_HFUZZ)?;
7474
// update_gitignore(&self.root, CARGO_TARGET_DIR_DEFAULT_AFL)?;
75-
initialize_package_metadata(&self.program_packages, &self.versions_config).await?;
75+
// initialize_package_metadata(&self.program_packages, &self.versions_config).await?;
7676
}
7777

7878
#[throws]
@@ -84,7 +84,7 @@ impl TestGenerator {
8484
self.generate_source_codes().await?;
8585
self.add_new_fuzz_test().await?;
8686

87-
update_package_metadata(&self.program_packages, &self.versions_config).await?;
87+
// update_package_metadata(&self.program_packages, &self.versions_config).await?;
8888
}
8989

9090
#[throws]

0 commit comments

Comments
 (0)