Skip to content

Conversation

grod220
Copy link
Member

@grod220 grod220 commented Jun 23, 2025

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:

  • MintBuilder
  • TokenAccountBuilder
  • ExtensionInitializer

Benefits: tests are more declarative, bugs with ATAs are fixed, and duplication is reduced.

Comment on lines +17 to +55
#[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>,
}
Copy link
Member Author

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

Comment on lines -48 to -49
pub const FREEZE_AUTHORITY: Pubkey =
Pubkey::from_str_const("11111115q4EpJaTXAZWpCg3J2zppWGSZ46KXozzo9");
Copy link
Member Author

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);
Copy link
Member Author

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> {
Copy link
Member Author

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

Copy link
Contributor

@joncinque joncinque left a 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!

Copy link

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

It would be interesting if all this was just generated, say, by some codegen library we might all know of...

@grod220 grod220 force-pushed the account-mint-builders branch from ca5b3af to 901e91c Compare June 24, 2025 07:43
@grod220 grod220 merged commit 9d75473 into main Jun 24, 2025
11 checks passed
@grod220 grod220 deleted the account-mint-builders branch June 24, 2025 07:59
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.

3 participants