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

Feat/fuzz pkey to acc #116

Merged
merged 6 commits into from
Feb 15, 2024
Merged

Feat/fuzz pkey to acc #116

merged 6 commits into from
Feb 15, 2024

Conversation

lukacan
Copy link
Collaborator

@lukacan lukacan commented Feb 5, 2024

If Pubkey is at instruction input, it is converted to AccountID, next the variable name is stored and the FuzzAccounts struct is expanded if an account with the same name does not exist.

However, if a Pubkey is contained within a struct, which itself is an input argument, this approach will not work.

Test_program was updated to test the functionality.
Added [workspace] into the test_program so the program can be easily expanded.

@lukacan
Copy link
Collaborator Author

lukacan commented Feb 14, 2024

@Ikrk rebased #115 , ready to review

let name_ident = format_ident!("{name}");
// TODO What about custom Enums and Structs on Instr Input ?
let ty = parse_str(ty).unwrap();
let ty: syn::Type = match &ty {
Copy link
Contributor

@Ikrk Ikrk Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so complicated? You can compare the ty variable directly as it is a String before it is shadowed by the let ty = parse_str(ty).unwrap(); line. So you can do only if ty == "Pubkey" directly.

Also I think the accounts_from_instr_input HashMap is not necessary. If it is one of the accounts, that will be required by another instruction, than it will be automatically generated anyway. And if it is not an account used by any instruction, than there is no need to add it.

Update: maybe it won't be so easy if the type is fully qualified with its path, but anyway, I think you can simply check if it is "Pubkey" or if it ends by "::Pubkey" or something similar...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments. Removed the unnecessary HashMap.
Regarding the Pubkey parse, simplified with "ends_with". Long option "anchor_lang::pubkey::Pubkey" is stored inside ty as "anchor_lang :: pubkey :: Pubkey" so for that case I check for ":: Pubkey". I think it won't hurt to check also for "::Pubkey", and for the short path I check for "Pubkey"

Copy link
Contributor

@Ikrk Ikrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your comment "// TODO What about custom Enums and Structs on Instr Input ?" - I would leave it to the developer.

@lukacan lukacan requested a review from Ikrk February 14, 2024 22:54
@Ikrk Ikrk merged commit 79f1b96 into develop Feb 15, 2024
7 checks passed
@Ikrk Ikrk deleted the feat/fuzz-pkey-to-accID branch February 15, 2024 10:35
lukacan added a commit that referenced this pull request May 20, 2024
* 🚧 WIP: instruction input argument of type Pubkey convert to AccointId, and add to FuzzAccounts struct

* ✅ update test_program so it can be simply expanded, update expected code

* 🔥 remove unnecessary code

* 🐛 update ?

* 🐛 simplified

* 🐛 Fixed Pubkey replacement by AccountId

---------

Co-authored-by: lukacan <[email protected]>
Co-authored-by: Ikrk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants