-
Notifications
You must be signed in to change notification settings - Fork 25
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
Conversation
92f7781
to
7459dbe
Compare
7459dbe
to
608c93d
Compare
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 { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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"
There was a problem hiding this 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.
* 🚧 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]>
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.