Skip to content

Commit 47fd273

Browse files
committed
disable apply pending balance when the account is frozen
1 parent de38c63 commit 47fd273

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

clients/rust-legacy/tests/confidential_transfer.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,6 +3279,94 @@ async fn test_confidential_transfer_pending_decryption_after_transfer() {
32793279
}
32803280
}
32813281

3282+
#[tokio::test]
3283+
async fn confidential_transfer_apply_pending_balance_frozen_account() {
3284+
let authority = Keypair::new();
3285+
let auto_approve_new_accounts = true;
3286+
let auditor_elgamal_keypair = ElGamalKeypair::new_rand();
3287+
let auditor_elgamal_pubkey = (*auditor_elgamal_keypair.pubkey()).into();
3288+
3289+
let mut context = TestContext::new().await;
3290+
context
3291+
.init_token_with_freezing_mint(vec![
3292+
ExtensionInitializationParams::ConfidentialTransferMint {
3293+
authority: Some(authority.pubkey()),
3294+
auto_approve_new_accounts,
3295+
auditor_elgamal_pubkey: Some(auditor_elgamal_pubkey),
3296+
},
3297+
])
3298+
.await
3299+
.unwrap();
3300+
3301+
let TokenContext {
3302+
token,
3303+
alice,
3304+
mint_authority,
3305+
freeze_authority,
3306+
decimals,
3307+
..
3308+
} = context.token_context.unwrap();
3309+
3310+
let freeze_authority = freeze_authority.unwrap();
3311+
let alice_meta = ConfidentialTokenAccountMeta::new(&token, &alice, Some(2), false, false).await;
3312+
3313+
// Mint tokens to Alice
3314+
token
3315+
.mint_to(
3316+
&alice_meta.token_account,
3317+
&mint_authority.pubkey(),
3318+
1000,
3319+
&[&mint_authority],
3320+
)
3321+
.await
3322+
.unwrap();
3323+
3324+
// Deposit tokens to create a pending balance
3325+
token
3326+
.confidential_transfer_deposit(
3327+
&alice_meta.token_account,
3328+
&alice.pubkey(),
3329+
1000,
3330+
decimals,
3331+
&[&alice],
3332+
)
3333+
.await
3334+
.unwrap();
3335+
3336+
// Freeze Alice's account
3337+
token
3338+
.freeze(
3339+
&alice_meta.token_account,
3340+
&freeze_authority.pubkey(),
3341+
&[&freeze_authority],
3342+
)
3343+
.await
3344+
.unwrap();
3345+
3346+
// Attempt to Apply Pending Balance
3347+
let err = token
3348+
.confidential_transfer_apply_pending_balance(
3349+
&alice_meta.token_account,
3350+
&alice.pubkey(),
3351+
None,
3352+
alice_meta.elgamal_keypair.secret(),
3353+
&alice_meta.aes_key,
3354+
&[&alice],
3355+
)
3356+
.await
3357+
.unwrap_err();
3358+
3359+
assert_eq!(
3360+
err,
3361+
TokenClientError::Client(Box::new(TransportError::TransactionError(
3362+
TransactionError::InstructionError(
3363+
0,
3364+
InstructionError::Custom(TokenError::AccountFrozen as u32)
3365+
)
3366+
)))
3367+
);
3368+
}
3369+
32823370
#[cfg(test)]
32833371
mod unit_tests {
32843372

program/src/extension/confidential_transfer/processor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,10 @@ fn process_apply_pending_balance(
12181218
account_info_iter.as_slice(),
12191219
)?;
12201220

1221+
if token_account.base.is_frozen() {
1222+
return Err(TokenError::AccountFrozen.into());
1223+
}
1224+
12211225
let confidential_transfer_account =
12221226
token_account.get_extension_mut::<ConfidentialTransferAccount>()?;
12231227

0 commit comments

Comments
 (0)