-
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
Additional anchor types #115
Conversation
c2ddac3
to
e3e352a
Compare
The accounts snapshots code generation was changed and the tests do not pass anymore. I will correct it next week. |
d8027a8
to
d370cda
Compare
When used on fuzz_example3, the freshly generated account_snapshots.rs contains an error for "escrow_pda_authority". The account is expected to be:
However, the code is generated as: where escrow_pda_authority has type Option<AccountInfo<'_>> |
d370cda
to
8225bb9
Compare
7a6e500
to
6795b02
Compare
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.
There is another issue. Currently, the escrow_pda_authority account inside WithdrawUnlockedSnapshot is expected to be of type AccountInfo. However, the bank's client returns None if the account is not found. The get_or_create_account function for the AccountsStorage<PdaStore> implementation derives the address. However, the account corresponding to the derived address is not initialized with the client. Since escrow_pda_authority is also not explicitly initialized within the program, the bank's client always returns None for this account.
- One possible solution:
Call the set_account function of the bank's client inside get_or_create_account for AccountsStorage<PdaStore>. However, while testing this, I identified at least two scenarios we want to avoid:
- We always want to set the owner of the PDA account as SYSTEM_PROGRAM_ID. If set to a specific program ID, we will not be able to initialize a new PDA account within the program because the owner will not be system_program -> not able to assign and allocate.
- Before calling set_account, we need to check if the PDA account is not already initialized. This is because set_account "Create or overwrite an account", so already initialized PDA accounts could be overwritten with fresh accounts -> this is because AccountID for the PDAStore can be different however seeds (and therefore) Address will be the same.
I made some additional testing today and so far I found another issues:
EDIT: I was further testing account types based on anchor_lang::accounts for Anchor 0.28.0, and my suggestions/observations:
|
Finally I have made following modifications:
|
Good job ! |
Added support for all Anchor types. Now, any context structure supported by Anchor 0.29.0 should be correctly parsed and the appropriate snapshot structs generated correctly.
Before this change, the parsing was done "manually". Now however we are using the parser directly from Anchor that has been exposed in Anchor 0.29.0 when using the idl-build feature flag. The types
Interface
andInterfaceAccount
were not tested.Also, this PR changes the way how the snapshot accounts are constructed. Now only the explicitly optional accounts and the accounts that have the
init
orclose
constraints are wrapped into the Option type. That make the work with accounts within thecheck
methods easier because it is not necessary to always verify if there is Some account.Finally, this PR modularized the implementation within the snapshot_generator.rs file to make it more readable.