-
Notifications
You must be signed in to change notification settings - Fork 7
Add MintBuilder & TokenAccountBuilder #143
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
Conversation
#[derive(Default, Debug, Clone)] | ||
pub struct KeyedAccount { | ||
pub key: Pubkey, | ||
pub account: Account, | ||
} | ||
|
||
impl KeyedAccount { | ||
pub fn pair(&self) -> (Pubkey, Account) { | ||
(self.key, self.account.clone()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum TokenProgram { | ||
SplToken, | ||
SplToken2022, | ||
} | ||
|
||
impl TokenProgram { | ||
pub fn id(&self) -> Pubkey { | ||
match self { | ||
TokenProgram::SplToken => spl_token::id(), | ||
TokenProgram::SplToken2022 => spl_token_2022::id(), | ||
} | ||
} | ||
|
||
pub fn keyed_account(&self) -> (Pubkey, Account) { | ||
match self { | ||
TokenProgram::SplToken => mollusk_svm_programs_token::token::keyed_account(), | ||
TokenProgram::SplToken2022 => mollusk_svm_programs_token::token2022::keyed_account(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct TransferAuthority { | ||
pub keyed_account: KeyedAccount, | ||
pub signers: Vec<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.
Moved to common.rs
and out of the suite-specific files
pub const FREEZE_AUTHORITY: Pubkey = | ||
Pubkey::from_str_const("11111115q4EpJaTXAZWpCg3J2zppWGSZ46KXozzo9"); |
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.
I found the freeze authority as a global to be strange as it really only should pertain to a few CreateMint assertions. So moved this locally to those tests.
|
||
// Only add extensions for SPL Token 2022 | ||
if unwrapped_token_program == TokenProgram::SplToken2022 { | ||
builder = builder.with_extension(ImmutableOwnerExtension); |
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.
Important as this was not formerly being added to the escrow ATA in tests
pub const FREEZE_AUTHORITY: Pubkey = | ||
Pubkey::from_str_const("11111115q4EpJaTXAZWpCg3J2zppWGSZ46KXozzo9"); | ||
|
||
fn token_2022_with_extension_data(supply: u64) -> Vec<u8> { |
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.
Here and down represents all of the individual mint and token account creators that are now replaced
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.
I mostly skimmed, but looks correct overall!
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.
ca5b3af
to
901e91c
Compare
This PR introduces a builder-pattern API for mints and token accounts in tests. Inspired by https://github.com/solana-program/token-wrap/pull/139/files#r2159332672 seeing that ATA accounts were not being properly set up. Main new structs added:
Benefits: tests are more declarative, bugs with ATAs are fixed, and duplication is reduced.