Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/warn user on composite accounts and continue fuzz test generation #133

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ This section summarizes some known limitations in the current development stage.

- Only fuzzing of one program without CPIs to other custom programs is supported.
- Remaining accounts in check methods are not supported.
- Composite accounts are not supported (however it is possible to generate a fuzz test and finish the composite accounts deserialization manually).

## Fuzz test examples
- [Fuzz test example 0](examples/fuzz_example0)
Expand Down
27 changes: 19 additions & 8 deletions crates/client/src/fuzzer/snapshot_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,14 @@ fn create_snapshot_struct(
.to_string()
.replace(' ', "")
.starts_with("AccountInfo<");
} else {
return Err(
"Composite field types in context structs not supported".into()
}
else {
println!("\x1b[1;93mWarning\x1b[0m: The context `{}` has a field named `{}` of composite type `{}`. \
The automatic deserialization of composite types is currently not supported. You will have \
to implement it manually in the generated `accounts_snapshots.rs` file. The field deserialization \
was replaced by a `todo!()` macro. Also, you might want to adapt the corresponding FuzzInstruction \
variants in `fuzz_instructions.rs` file.",
orig_struct.ident, field_name.to_token_stream(), field_type.to_token_stream()
);
}

Expand Down Expand Up @@ -298,7 +303,7 @@ fn deserialize_ctx_struct_anchor(
snapshot_name: &Ident,
parsed_fields: &[AccountField],
) -> Result<TokenStream, Box<dyn Error>> {
let names_deser_pairs: Result<Vec<(TokenStream, TokenStream)>, _> = parsed_fields
let names_deser_pairs: Vec<(TokenStream, TokenStream)> = parsed_fields
.iter()
.map(|parsed_f| match parsed_f {
AccountField::Field(f) => {
Expand All @@ -316,18 +321,24 @@ fn deserialize_ctx_struct_anchor(
}
None => acc_info_tokens(&field_name, is_optional),
};
Ok((
(
quote! {#field_name},
quote! {
#deser_tokens
},
))
)
}
AccountField::CompositeField(f) => {
let field_name = f.ident.clone();
(
quote! { #field_name },
quote! { let #field_name = todo!(); },
)
}
AccountField::CompositeField(_) => Err("CompositeFields not supported!"),
})
.collect();

let (names, fields_deser): (Vec<_>, Vec<_>) = names_deser_pairs?.iter().cloned().unzip();
let (names, fields_deser): (Vec<_>, Vec<_>) = names_deser_pairs.iter().cloned().unzip();

let generated_deser_impl: syn::Item = parse_quote! {
impl<'info> #snapshot_name<'info> {
Expand Down
Loading