@@ -161,12 +161,12 @@ impl Processor {
161
161
let mut source_account = Account :: unpack ( & source_account_info. data . borrow ( ) ) ?;
162
162
let mut dest_account = Account :: unpack ( & dest_account_info. data . borrow ( ) ) ?;
163
163
164
- if source_account. amount < amount {
165
- return Err ( TokenError :: InsufficientFunds . into ( ) ) ;
166
- }
167
164
if source_account. is_frozen ( ) || dest_account. is_frozen ( ) {
168
165
return Err ( TokenError :: AccountFrozen . into ( ) ) ;
169
166
}
167
+ if source_account. amount < amount {
168
+ return Err ( TokenError :: InsufficientFunds . into ( ) ) ;
169
+ }
170
170
if source_account. mint != dest_account. mint {
171
171
return Err ( TokenError :: MintMismatch . into ( ) ) ;
172
172
}
@@ -478,17 +478,17 @@ impl Processor {
478
478
let mut source_account = Account :: unpack ( & source_account_info. data . borrow ( ) ) ?;
479
479
let mut mint = Mint :: unpack ( & mint_info. data . borrow ( ) ) ?;
480
480
481
+ if source_account. is_frozen ( ) {
482
+ return Err ( TokenError :: AccountFrozen . into ( ) ) ;
483
+ }
481
484
if source_account. is_native ( ) {
482
485
return Err ( TokenError :: NativeNotSupported . into ( ) ) ;
483
486
}
484
- if mint_info. key != & source_account. mint {
485
- return Err ( TokenError :: MintMismatch . into ( ) ) ;
486
- }
487
487
if source_account. amount < amount {
488
488
return Err ( TokenError :: InsufficientFunds . into ( ) ) ;
489
489
}
490
- if source_account. is_frozen ( ) {
491
- return Err ( TokenError :: AccountFrozen . into ( ) ) ;
490
+ if mint_info . key != & source_account. mint {
491
+ return Err ( TokenError :: MintMismatch . into ( ) ) ;
492
492
}
493
493
494
494
if let Some ( expected_decimals) = expected_decimals {
@@ -588,15 +588,15 @@ impl Processor {
588
588
let authority_info = next_account_info ( account_info_iter) ?;
589
589
590
590
let mut source_account = Account :: unpack ( & source_account_info. data . borrow ( ) ) ?;
591
+ if freeze && source_account. is_frozen ( ) || !freeze && !source_account. is_frozen ( ) {
592
+ return Err ( TokenError :: InvalidState . into ( ) ) ;
593
+ }
591
594
if source_account. is_native ( ) {
592
595
return Err ( TokenError :: NativeNotSupported . into ( ) ) ;
593
596
}
594
597
if mint_info. key != & source_account. mint {
595
598
return Err ( TokenError :: MintMismatch . into ( ) ) ;
596
599
}
597
- if freeze && source_account. is_frozen ( ) || !freeze && !source_account. is_frozen ( ) {
598
- return Err ( TokenError :: InvalidState . into ( ) ) ;
599
- }
600
600
601
601
let mint = Mint :: unpack ( & mint_info. data . borrow_mut ( ) ) ?;
602
602
match mint. freeze_authority {
@@ -3402,9 +3402,6 @@ mod tests {
3402
3402
] ,
3403
3403
)
3404
3404
. unwrap ( ) ;
3405
- let mut account = Account :: unpack_unchecked ( & mismatch_account. data ) . unwrap ( ) ;
3406
- account. mint = mint2_key;
3407
- Account :: pack ( account, & mut mismatch_account. data ) . unwrap ( ) ;
3408
3405
3409
3406
// mint to account
3410
3407
do_process_instruction (
@@ -3413,6 +3410,16 @@ mod tests {
3413
3410
)
3414
3411
. unwrap ( ) ;
3415
3412
3413
+ // mint to mismatch account and change mint key
3414
+ do_process_instruction (
3415
+ mint_to ( & program_id, & mint_key, & mismatch_key, & owner_key, & [ ] , 1000 ) . unwrap ( ) ,
3416
+ vec ! [ & mut mint_account, & mut mismatch_account, & mut owner_account] ,
3417
+ )
3418
+ . unwrap ( ) ;
3419
+ let mut account = Account :: unpack_unchecked ( & mismatch_account. data ) . unwrap ( ) ;
3420
+ account. mint = mint2_key;
3421
+ Account :: pack ( account, & mut mismatch_account. data ) . unwrap ( ) ;
3422
+
3416
3423
// missing signer
3417
3424
let mut instruction =
3418
3425
burn ( & program_id, & account_key, & mint_key, & delegate_key, & [ ] , 42 ) . unwrap ( ) ;
@@ -3471,7 +3478,7 @@ mod tests {
3471
3478
. unwrap ( ) ;
3472
3479
3473
3480
let mint = Mint :: unpack_unchecked ( & mint_account. data ) . unwrap ( ) ;
3474
- assert_eq ! ( mint. supply, 1000 - 42 ) ;
3481
+ assert_eq ! ( mint. supply, 2000 - 42 ) ;
3475
3482
let account = Account :: unpack_unchecked ( & account_account. data ) . unwrap ( ) ;
3476
3483
assert_eq ! ( account. amount, 1000 - 42 ) ;
3477
3484
@@ -3541,7 +3548,7 @@ mod tests {
3541
3548
3542
3549
// match
3543
3550
let mint = Mint :: unpack_unchecked ( & mint_account. data ) . unwrap ( ) ;
3544
- assert_eq ! ( mint. supply, 1000 - 42 - 84 ) ;
3551
+ assert_eq ! ( mint. supply, 2000 - 42 - 84 ) ;
3545
3552
let account = Account :: unpack_unchecked ( & account_account. data ) . unwrap ( ) ;
3546
3553
assert_eq ! ( account. amount, 1000 - 42 - 84 ) ;
3547
3554
0 commit comments